修改后台权限
This commit is contained in:
9
node_modules/@open-draft/logger/LICENSE
generated
vendored
Normal file
9
node_modules/@open-draft/logger/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2023—present Artem Zakharchenko
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
225
node_modules/@open-draft/logger/README.md
generated
vendored
Normal file
225
node_modules/@open-draft/logger/README.md
generated
vendored
Normal file
@@ -0,0 +1,225 @@
|
||||
# Logger
|
||||
|
||||
Environment-agnostic, ESM-friendly logger for simple needs.
|
||||
|
||||
## Why does this exist?
|
||||
|
||||
I've been using `debug` for quite some time but wanted to migrate my projects to better ESM support. Alas, `debug` doesn't ship as ESM so I went and wrote this little logger just for my needs. You will likely see it printing useful data in Mock Service Worker and beyond.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install @open-draft/logger
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
This package has the same API for both browser and Node.js and can run in those environments out of the box.
|
||||
|
||||
```js
|
||||
// app.js
|
||||
import { Logger } from '@open-draft/logger'
|
||||
|
||||
const logger = new Logger('parser')
|
||||
|
||||
logger.info('starting parsing...')
|
||||
logger.warning('found legacy document format')
|
||||
logger.success('parsed 120 documents!')
|
||||
```
|
||||
|
||||
Logging is disabled by default. To enable logging, provide the `DEBUG` environment variable:
|
||||
|
||||
```sh
|
||||
DEBUG=1 node ./app.js
|
||||
```
|
||||
|
||||
> You can also use `true` instead of `1`. You can also use a specific logger's name to enable [logger filtering](#logger-filtering).
|
||||
|
||||
## API
|
||||
|
||||
- Class: `Logger`
|
||||
- [`new Logger(name)`](#new-loggername)
|
||||
- [`logger.debug(message, ...positionals)`](#loggerdebugmessage-positionals)
|
||||
- [`logger.info(message, ...positionals)`](#loggerinfomessage-positionals)
|
||||
- [`logger.success(message, ...positionals)`](#loggersuccessmessage-positionals)
|
||||
- [`logger.warning(message, ...positionals)`](#loggerwarningmessage-positionals)
|
||||
- [`logger.error(message, ...positionals)`](#loggererrormessage-positionals)
|
||||
- [`logger.extend(name)`](#loggerextendprefix)
|
||||
- [`logger.only(callback)`](#loggeronlycallback)
|
||||
|
||||
### `new Logger(name)`
|
||||
|
||||
- `name` `string` the name of the logger.
|
||||
|
||||
Creates a new instance of the logger. Each message printed by the logger will be prefixed with the given `name`. You can have multiple loggers with different names for different areas of your system.
|
||||
|
||||
```js
|
||||
const logger = new Logger('parser')
|
||||
```
|
||||
|
||||
> You can nest loggers via [`logger.extend()`](#loggerextendprefix).
|
||||
|
||||
### `logger.debug(message, ...positionals)`
|
||||
|
||||
- `message` `string`
|
||||
- `positionals` `unknown[]`
|
||||
|
||||
Prints a debug message.
|
||||
|
||||
```js
|
||||
logger.debug('no duplicates found, skipping...')
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 [parser] no duplicates found, skipping...
|
||||
```
|
||||
|
||||
### `logger.info(message, ...positionals)`
|
||||
|
||||
- `message` `string`
|
||||
- `positionals` `unknown[]`
|
||||
|
||||
Prints an info message.
|
||||
|
||||
```js
|
||||
logger.info('new parse request')
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 [parser] new parse request
|
||||
```
|
||||
|
||||
### `logger.success(message, ...positionals)`
|
||||
|
||||
- `message` `string`
|
||||
- `positionals` `unknown[]`
|
||||
|
||||
Prints a success message.
|
||||
|
||||
```js
|
||||
logger.success('prased 123 documents!')
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 ✔ [parser] prased 123 documents!
|
||||
```
|
||||
|
||||
### `logger.warning(message, ...positionals)`
|
||||
|
||||
- `message` `string`
|
||||
- `positionals` `unknown[]`
|
||||
|
||||
Prints a warning. In Node.js, prints it to `process.stderr`.
|
||||
|
||||
```js
|
||||
logger.warning('found legacy document format')
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 ⚠ [parser] found legacy document format
|
||||
```
|
||||
|
||||
### `logger.error(message, ...positionals)`
|
||||
|
||||
- `message` `string`
|
||||
- `positionals` `unknown[]`
|
||||
|
||||
Prints an error. In Node.js, prints it to `process.stderr`.
|
||||
|
||||
```js
|
||||
logger.error('failed to parse document')
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 ✖ [parser] failed to parse document
|
||||
```
|
||||
|
||||
### `logger.extend(prefix)`
|
||||
|
||||
- `prefix` `string` Additional prefix to append to the logger's name.
|
||||
|
||||
Creates a new logger out of the current one.
|
||||
|
||||
```js
|
||||
const logger = new Logger('parser')
|
||||
|
||||
function parseRequest(request) {
|
||||
const requestLogger = logger.extend(`${request.method} ${request.url}`)
|
||||
requestLogger.info('start parsing...')
|
||||
}
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 [parser] [GET https://example.com] start parsing...
|
||||
```
|
||||
|
||||
### `logger.only(callback)`
|
||||
|
||||
Executes a given callback only when the logging is activated. Useful for computing additional information for logs.
|
||||
|
||||
```js
|
||||
logger.only(() => {
|
||||
const documentSize = getSizeBytes(document)
|
||||
logger.debug(`document size: ${documentSize}`)
|
||||
})
|
||||
```
|
||||
|
||||
> You can nest `logger.*` methods in the callback to `logger.only()`.
|
||||
|
||||
## Log levels
|
||||
|
||||
You can specify the log levels to print using the `LOG_LEVEL` environment variable.
|
||||
|
||||
There are the following log levels:
|
||||
|
||||
- `debug`
|
||||
- `info`
|
||||
- `success`
|
||||
- `warning`
|
||||
- `error`
|
||||
|
||||
> Providing no log level will print all the messages.
|
||||
|
||||
Here's an example of how to print only warnings:
|
||||
|
||||
```js
|
||||
// app.js
|
||||
import { Logger } from '@open-draft/logger'
|
||||
|
||||
const logger = new Logger('parser')
|
||||
|
||||
logger.info('some info')
|
||||
logger.warning('some warning')
|
||||
logger.error('some error')
|
||||
```
|
||||
|
||||
```js
|
||||
LOG_LEVEL=warning node ./app.js
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 ⚠ [parser] some warning
|
||||
```
|
||||
|
||||
## Logger filtering
|
||||
|
||||
You can only print a specific logger by providing its name as the `DEBUG` environment variable.
|
||||
|
||||
```js
|
||||
// app.js
|
||||
import { Logger } from '@open-draft/logger'
|
||||
|
||||
const appLogger = new Logger('app')
|
||||
const parserLogger = new Logger('parser')
|
||||
|
||||
appLogger.info('starting app...')
|
||||
parserLogger.info('creating a new parser...')
|
||||
```
|
||||
|
||||
```sh
|
||||
DEBUG=app node ./app.js
|
||||
```
|
||||
|
||||
```
|
||||
12:34:56:789 [app] starting app...
|
||||
```
|
||||
83
node_modules/@open-draft/logger/lib/index.d.ts
generated
vendored
Normal file
83
node_modules/@open-draft/logger/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
type ColorFunction = (text: string) => void;
|
||||
declare function yellow(text: string): string;
|
||||
declare function blue(text: string): string;
|
||||
declare function gray(text: string): string;
|
||||
declare function red(text: string): string;
|
||||
declare function green(text: string): string;
|
||||
|
||||
type colors_ColorFunction = ColorFunction;
|
||||
declare const colors_blue: typeof blue;
|
||||
declare const colors_gray: typeof gray;
|
||||
declare const colors_green: typeof green;
|
||||
declare const colors_red: typeof red;
|
||||
declare const colors_yellow: typeof yellow;
|
||||
declare namespace colors {
|
||||
export {
|
||||
colors_ColorFunction as ColorFunction,
|
||||
colors_blue as blue,
|
||||
colors_gray as gray,
|
||||
colors_green as green,
|
||||
colors_red as red,
|
||||
colors_yellow as yellow,
|
||||
};
|
||||
}
|
||||
|
||||
type LogLevel = 'debug' | 'info' | 'success' | 'warning' | 'error';
|
||||
type LogColors = keyof typeof colors;
|
||||
interface LogEntry {
|
||||
timestamp: Date;
|
||||
level: LogLevel;
|
||||
message: any;
|
||||
}
|
||||
declare class Logger {
|
||||
private readonly name;
|
||||
private prefix;
|
||||
constructor(name: string);
|
||||
extend(domain: string): Logger;
|
||||
/**
|
||||
* Print a debug message.
|
||||
* @example
|
||||
* logger.debug('no duplicates found, creating a document...')
|
||||
*/
|
||||
debug(message: any, ...positionals: Array<unknown>): void;
|
||||
/**
|
||||
* Print an info message.
|
||||
* @example
|
||||
* logger.info('start parsing...')
|
||||
*/
|
||||
info(message: any, ...positionals: Array<unknown>): (message: any, ...positionals: Array<unknown>) => void;
|
||||
/**
|
||||
* Print a success message.
|
||||
* @example
|
||||
* logger.success('successfully created document')
|
||||
*/
|
||||
success(message: any, ...positionals: Array<unknown>): void;
|
||||
/**
|
||||
* Print a warning.
|
||||
* @example
|
||||
* logger.warning('found legacy document format')
|
||||
*/
|
||||
warning(message: any, ...positionals: Array<unknown>): void;
|
||||
/**
|
||||
* Print an error message.
|
||||
* @example
|
||||
* logger.error('something went wrong')
|
||||
*/
|
||||
error(message: any, ...positionals: Array<unknown>): void;
|
||||
/**
|
||||
* Execute the given callback only when the logging is enabled.
|
||||
* This is skipped in its entirety and has no runtime cost otherwise.
|
||||
* This executes regardless of the log level.
|
||||
* @example
|
||||
* logger.only(() => {
|
||||
* logger.info('additional info')
|
||||
* })
|
||||
*/
|
||||
only(callback: () => void): void;
|
||||
private createEntry;
|
||||
private logEntry;
|
||||
private formatTimestamp;
|
||||
private getWriter;
|
||||
}
|
||||
|
||||
export { LogColors, LogEntry, LogLevel, Logger };
|
||||
295
node_modules/@open-draft/logger/lib/index.js
generated
vendored
Normal file
295
node_modules/@open-draft/logger/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,295 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
||||
var __getOwnPropNames = Object.getOwnPropertyNames;
|
||||
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
var __copyProps = (to, from, except, desc) => {
|
||||
if (from && typeof from === "object" || typeof from === "function") {
|
||||
for (let key of __getOwnPropNames(from))
|
||||
if (!__hasOwnProp.call(to, key) && key !== except)
|
||||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
||||
}
|
||||
return to;
|
||||
};
|
||||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
||||
|
||||
// src/index.ts
|
||||
var src_exports = {};
|
||||
__export(src_exports, {
|
||||
Logger: () => Logger
|
||||
});
|
||||
module.exports = __toCommonJS(src_exports);
|
||||
var import_is_node_process = require("is-node-process");
|
||||
var import_outvariant = require("outvariant");
|
||||
|
||||
// src/colors.ts
|
||||
var colors_exports = {};
|
||||
__export(colors_exports, {
|
||||
blue: () => blue,
|
||||
gray: () => gray,
|
||||
green: () => green,
|
||||
red: () => red,
|
||||
yellow: () => yellow
|
||||
});
|
||||
function yellow(text) {
|
||||
return `\x1B[33m${text}\x1B[0m`;
|
||||
}
|
||||
function blue(text) {
|
||||
return `\x1B[34m${text}\x1B[0m`;
|
||||
}
|
||||
function gray(text) {
|
||||
return `\x1B[90m${text}\x1B[0m`;
|
||||
}
|
||||
function red(text) {
|
||||
return `\x1B[31m${text}\x1B[0m`;
|
||||
}
|
||||
function green(text) {
|
||||
return `\x1B[32m${text}\x1B[0m`;
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
var IS_NODE = (0, import_is_node_process.isNodeProcess)();
|
||||
var Logger = class {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
this.prefix = `[${this.name}]`;
|
||||
const LOGGER_NAME = getVariable("DEBUG");
|
||||
const LOGGER_LEVEL = getVariable("LOG_LEVEL");
|
||||
const isLoggingEnabled = LOGGER_NAME === "1" || LOGGER_NAME === "true" || typeof LOGGER_NAME !== "undefined" && this.name.startsWith(LOGGER_NAME);
|
||||
if (isLoggingEnabled) {
|
||||
this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
|
||||
this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
|
||||
this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
|
||||
this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
|
||||
this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
|
||||
} else {
|
||||
this.info = noop;
|
||||
this.success = noop;
|
||||
this.warning = noop;
|
||||
this.error = noop;
|
||||
this.only = noop;
|
||||
}
|
||||
}
|
||||
prefix;
|
||||
extend(domain) {
|
||||
return new Logger(`${this.name}:${domain}`);
|
||||
}
|
||||
/**
|
||||
* Print a debug message.
|
||||
* @example
|
||||
* logger.debug('no duplicates found, creating a document...')
|
||||
*/
|
||||
debug(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "debug",
|
||||
message: gray(message),
|
||||
positionals,
|
||||
prefix: this.prefix,
|
||||
colors: {
|
||||
prefix: "gray"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Print an info message.
|
||||
* @example
|
||||
* logger.info('start parsing...')
|
||||
*/
|
||||
info(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "info",
|
||||
message,
|
||||
positionals,
|
||||
prefix: this.prefix,
|
||||
colors: {
|
||||
prefix: "blue"
|
||||
}
|
||||
});
|
||||
const performance2 = new PerformanceEntry();
|
||||
return (message2, ...positionals2) => {
|
||||
performance2.measure();
|
||||
this.logEntry({
|
||||
level: "info",
|
||||
message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
|
||||
positionals: positionals2,
|
||||
prefix: this.prefix,
|
||||
colors: {
|
||||
prefix: "blue"
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Print a success message.
|
||||
* @example
|
||||
* logger.success('successfully created document')
|
||||
*/
|
||||
success(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "info",
|
||||
message,
|
||||
positionals,
|
||||
prefix: `\u2714 ${this.prefix}`,
|
||||
colors: {
|
||||
timestamp: "green",
|
||||
prefix: "green"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Print a warning.
|
||||
* @example
|
||||
* logger.warning('found legacy document format')
|
||||
*/
|
||||
warning(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "warning",
|
||||
message,
|
||||
positionals,
|
||||
prefix: `\u26A0 ${this.prefix}`,
|
||||
colors: {
|
||||
timestamp: "yellow",
|
||||
prefix: "yellow"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Print an error message.
|
||||
* @example
|
||||
* logger.error('something went wrong')
|
||||
*/
|
||||
error(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "error",
|
||||
message,
|
||||
positionals,
|
||||
prefix: `\u2716 ${this.prefix}`,
|
||||
colors: {
|
||||
timestamp: "red",
|
||||
prefix: "red"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Execute the given callback only when the logging is enabled.
|
||||
* This is skipped in its entirety and has no runtime cost otherwise.
|
||||
* This executes regardless of the log level.
|
||||
* @example
|
||||
* logger.only(() => {
|
||||
* logger.info('additional info')
|
||||
* })
|
||||
*/
|
||||
only(callback) {
|
||||
callback();
|
||||
}
|
||||
createEntry(level, message) {
|
||||
return {
|
||||
timestamp: /* @__PURE__ */ new Date(),
|
||||
level,
|
||||
message
|
||||
};
|
||||
}
|
||||
logEntry(args) {
|
||||
const {
|
||||
level,
|
||||
message,
|
||||
prefix,
|
||||
colors: customColors,
|
||||
positionals = []
|
||||
} = args;
|
||||
const entry = this.createEntry(level, message);
|
||||
const timestampColor = customColors?.timestamp || "gray";
|
||||
const prefixColor = customColors?.prefix || "gray";
|
||||
const colorize = {
|
||||
timestamp: colors_exports[timestampColor],
|
||||
prefix: colors_exports[prefixColor]
|
||||
};
|
||||
const write = this.getWriter(level);
|
||||
write(
|
||||
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
|
||||
...positionals.map(serializeInput)
|
||||
);
|
||||
}
|
||||
formatTimestamp(timestamp) {
|
||||
return `${timestamp.toLocaleTimeString(
|
||||
"en-GB"
|
||||
)}:${timestamp.getMilliseconds()}`;
|
||||
}
|
||||
getWriter(level) {
|
||||
switch (level) {
|
||||
case "debug":
|
||||
case "success":
|
||||
case "info": {
|
||||
return log;
|
||||
}
|
||||
case "warning": {
|
||||
return warn;
|
||||
}
|
||||
case "error": {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var PerformanceEntry = class {
|
||||
startTime;
|
||||
endTime;
|
||||
deltaTime;
|
||||
constructor() {
|
||||
this.startTime = performance.now();
|
||||
}
|
||||
measure() {
|
||||
this.endTime = performance.now();
|
||||
const deltaTime = this.endTime - this.startTime;
|
||||
this.deltaTime = deltaTime.toFixed(2);
|
||||
}
|
||||
};
|
||||
var noop = () => void 0;
|
||||
function log(message, ...positionals) {
|
||||
if (IS_NODE) {
|
||||
process.stdout.write((0, import_outvariant.format)(message, ...positionals) + "\n");
|
||||
return;
|
||||
}
|
||||
console.log(message, ...positionals);
|
||||
}
|
||||
function warn(message, ...positionals) {
|
||||
if (IS_NODE) {
|
||||
process.stderr.write((0, import_outvariant.format)(message, ...positionals) + "\n");
|
||||
return;
|
||||
}
|
||||
console.warn(message, ...positionals);
|
||||
}
|
||||
function error(message, ...positionals) {
|
||||
if (IS_NODE) {
|
||||
process.stderr.write((0, import_outvariant.format)(message, ...positionals) + "\n");
|
||||
return;
|
||||
}
|
||||
console.error(message, ...positionals);
|
||||
}
|
||||
function getVariable(variableName) {
|
||||
if (IS_NODE) {
|
||||
return process.env[variableName];
|
||||
}
|
||||
return globalThis[variableName]?.toString();
|
||||
}
|
||||
function isDefinedAndNotEquals(value, expected) {
|
||||
return value !== void 0 && value !== expected;
|
||||
}
|
||||
function serializeInput(message) {
|
||||
if (typeof message === "undefined") {
|
||||
return "undefined";
|
||||
}
|
||||
if (message === null) {
|
||||
return "null";
|
||||
}
|
||||
if (typeof message === "string") {
|
||||
return message;
|
||||
}
|
||||
if (typeof message === "object") {
|
||||
return JSON.stringify(message);
|
||||
}
|
||||
return message.toString();
|
||||
}
|
||||
281
node_modules/@open-draft/logger/lib/index.mjs
generated
vendored
Normal file
281
node_modules/@open-draft/logger/lib/index.mjs
generated
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
var __defProp = Object.defineProperty;
|
||||
var __export = (target, all) => {
|
||||
for (var name in all)
|
||||
__defProp(target, name, { get: all[name], enumerable: true });
|
||||
};
|
||||
|
||||
// src/index.ts
|
||||
import { isNodeProcess } from "is-node-process";
|
||||
import { format } from "outvariant";
|
||||
|
||||
// src/colors.ts
|
||||
var colors_exports = {};
|
||||
__export(colors_exports, {
|
||||
blue: () => blue,
|
||||
gray: () => gray,
|
||||
green: () => green,
|
||||
red: () => red,
|
||||
yellow: () => yellow
|
||||
});
|
||||
function yellow(text) {
|
||||
return `\x1B[33m${text}\x1B[0m`;
|
||||
}
|
||||
function blue(text) {
|
||||
return `\x1B[34m${text}\x1B[0m`;
|
||||
}
|
||||
function gray(text) {
|
||||
return `\x1B[90m${text}\x1B[0m`;
|
||||
}
|
||||
function red(text) {
|
||||
return `\x1B[31m${text}\x1B[0m`;
|
||||
}
|
||||
function green(text) {
|
||||
return `\x1B[32m${text}\x1B[0m`;
|
||||
}
|
||||
|
||||
// src/index.ts
|
||||
var IS_NODE = isNodeProcess();
|
||||
var Logger = class {
|
||||
constructor(name) {
|
||||
this.name = name;
|
||||
this.prefix = `[${this.name}]`;
|
||||
const LOGGER_NAME = getVariable("DEBUG");
|
||||
const LOGGER_LEVEL = getVariable("LOG_LEVEL");
|
||||
const isLoggingEnabled = LOGGER_NAME === "1" || LOGGER_NAME === "true" || typeof LOGGER_NAME !== "undefined" && this.name.startsWith(LOGGER_NAME);
|
||||
if (isLoggingEnabled) {
|
||||
this.debug = isDefinedAndNotEquals(LOGGER_LEVEL, "debug") ? noop : this.debug;
|
||||
this.info = isDefinedAndNotEquals(LOGGER_LEVEL, "info") ? noop : this.info;
|
||||
this.success = isDefinedAndNotEquals(LOGGER_LEVEL, "success") ? noop : this.success;
|
||||
this.warning = isDefinedAndNotEquals(LOGGER_LEVEL, "warning") ? noop : this.warning;
|
||||
this.error = isDefinedAndNotEquals(LOGGER_LEVEL, "error") ? noop : this.error;
|
||||
} else {
|
||||
this.info = noop;
|
||||
this.success = noop;
|
||||
this.warning = noop;
|
||||
this.error = noop;
|
||||
this.only = noop;
|
||||
}
|
||||
}
|
||||
prefix;
|
||||
extend(domain) {
|
||||
return new Logger(`${this.name}:${domain}`);
|
||||
}
|
||||
/**
|
||||
* Print a debug message.
|
||||
* @example
|
||||
* logger.debug('no duplicates found, creating a document...')
|
||||
*/
|
||||
debug(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "debug",
|
||||
message: gray(message),
|
||||
positionals,
|
||||
prefix: this.prefix,
|
||||
colors: {
|
||||
prefix: "gray"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Print an info message.
|
||||
* @example
|
||||
* logger.info('start parsing...')
|
||||
*/
|
||||
info(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "info",
|
||||
message,
|
||||
positionals,
|
||||
prefix: this.prefix,
|
||||
colors: {
|
||||
prefix: "blue"
|
||||
}
|
||||
});
|
||||
const performance2 = new PerformanceEntry();
|
||||
return (message2, ...positionals2) => {
|
||||
performance2.measure();
|
||||
this.logEntry({
|
||||
level: "info",
|
||||
message: `${message2} ${gray(`${performance2.deltaTime}ms`)}`,
|
||||
positionals: positionals2,
|
||||
prefix: this.prefix,
|
||||
colors: {
|
||||
prefix: "blue"
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Print a success message.
|
||||
* @example
|
||||
* logger.success('successfully created document')
|
||||
*/
|
||||
success(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "info",
|
||||
message,
|
||||
positionals,
|
||||
prefix: `\u2714 ${this.prefix}`,
|
||||
colors: {
|
||||
timestamp: "green",
|
||||
prefix: "green"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Print a warning.
|
||||
* @example
|
||||
* logger.warning('found legacy document format')
|
||||
*/
|
||||
warning(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "warning",
|
||||
message,
|
||||
positionals,
|
||||
prefix: `\u26A0 ${this.prefix}`,
|
||||
colors: {
|
||||
timestamp: "yellow",
|
||||
prefix: "yellow"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Print an error message.
|
||||
* @example
|
||||
* logger.error('something went wrong')
|
||||
*/
|
||||
error(message, ...positionals) {
|
||||
this.logEntry({
|
||||
level: "error",
|
||||
message,
|
||||
positionals,
|
||||
prefix: `\u2716 ${this.prefix}`,
|
||||
colors: {
|
||||
timestamp: "red",
|
||||
prefix: "red"
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Execute the given callback only when the logging is enabled.
|
||||
* This is skipped in its entirety and has no runtime cost otherwise.
|
||||
* This executes regardless of the log level.
|
||||
* @example
|
||||
* logger.only(() => {
|
||||
* logger.info('additional info')
|
||||
* })
|
||||
*/
|
||||
only(callback) {
|
||||
callback();
|
||||
}
|
||||
createEntry(level, message) {
|
||||
return {
|
||||
timestamp: /* @__PURE__ */ new Date(),
|
||||
level,
|
||||
message
|
||||
};
|
||||
}
|
||||
logEntry(args) {
|
||||
const {
|
||||
level,
|
||||
message,
|
||||
prefix,
|
||||
colors: customColors,
|
||||
positionals = []
|
||||
} = args;
|
||||
const entry = this.createEntry(level, message);
|
||||
const timestampColor = customColors?.timestamp || "gray";
|
||||
const prefixColor = customColors?.prefix || "gray";
|
||||
const colorize = {
|
||||
timestamp: colors_exports[timestampColor],
|
||||
prefix: colors_exports[prefixColor]
|
||||
};
|
||||
const write = this.getWriter(level);
|
||||
write(
|
||||
[colorize.timestamp(this.formatTimestamp(entry.timestamp))].concat(prefix != null ? colorize.prefix(prefix) : []).concat(serializeInput(message)).join(" "),
|
||||
...positionals.map(serializeInput)
|
||||
);
|
||||
}
|
||||
formatTimestamp(timestamp) {
|
||||
return `${timestamp.toLocaleTimeString(
|
||||
"en-GB"
|
||||
)}:${timestamp.getMilliseconds()}`;
|
||||
}
|
||||
getWriter(level) {
|
||||
switch (level) {
|
||||
case "debug":
|
||||
case "success":
|
||||
case "info": {
|
||||
return log;
|
||||
}
|
||||
case "warning": {
|
||||
return warn;
|
||||
}
|
||||
case "error": {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var PerformanceEntry = class {
|
||||
startTime;
|
||||
endTime;
|
||||
deltaTime;
|
||||
constructor() {
|
||||
this.startTime = performance.now();
|
||||
}
|
||||
measure() {
|
||||
this.endTime = performance.now();
|
||||
const deltaTime = this.endTime - this.startTime;
|
||||
this.deltaTime = deltaTime.toFixed(2);
|
||||
}
|
||||
};
|
||||
var noop = () => void 0;
|
||||
function log(message, ...positionals) {
|
||||
if (IS_NODE) {
|
||||
process.stdout.write(format(message, ...positionals) + "\n");
|
||||
return;
|
||||
}
|
||||
console.log(message, ...positionals);
|
||||
}
|
||||
function warn(message, ...positionals) {
|
||||
if (IS_NODE) {
|
||||
process.stderr.write(format(message, ...positionals) + "\n");
|
||||
return;
|
||||
}
|
||||
console.warn(message, ...positionals);
|
||||
}
|
||||
function error(message, ...positionals) {
|
||||
if (IS_NODE) {
|
||||
process.stderr.write(format(message, ...positionals) + "\n");
|
||||
return;
|
||||
}
|
||||
console.error(message, ...positionals);
|
||||
}
|
||||
function getVariable(variableName) {
|
||||
if (IS_NODE) {
|
||||
return process.env[variableName];
|
||||
}
|
||||
return globalThis[variableName]?.toString();
|
||||
}
|
||||
function isDefinedAndNotEquals(value, expected) {
|
||||
return value !== void 0 && value !== expected;
|
||||
}
|
||||
function serializeInput(message) {
|
||||
if (typeof message === "undefined") {
|
||||
return "undefined";
|
||||
}
|
||||
if (message === null) {
|
||||
return "null";
|
||||
}
|
||||
if (typeof message === "string") {
|
||||
return message;
|
||||
}
|
||||
if (typeof message === "object") {
|
||||
return JSON.stringify(message);
|
||||
}
|
||||
return message.toString();
|
||||
}
|
||||
export {
|
||||
Logger
|
||||
};
|
||||
56
node_modules/@open-draft/logger/package.json
generated
vendored
Normal file
56
node_modules/@open-draft/logger/package.json
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
{
|
||||
"name": "@open-draft/logger",
|
||||
"version": "0.3.0",
|
||||
"description": "Environment-agnostic, ESM-friendly logger for simple needs.",
|
||||
"main": "./lib/index.js",
|
||||
"module": "./lib/index.mjs",
|
||||
"types": "./lib/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"types": "./lib/index.d.ts",
|
||||
"require": "./lib/index.js",
|
||||
"import": "./lib/index.mjs",
|
||||
"default": "./lib/index.js"
|
||||
},
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"keywords": [
|
||||
"log",
|
||||
"logger",
|
||||
"logging",
|
||||
"universal",
|
||||
"tiny"
|
||||
],
|
||||
"files": [
|
||||
"lib",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"author": "Artem Zakharchenko",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/open-draft/logger"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ossjs/release": "^0.5.1",
|
||||
"@playwright/test": "^1.32.3",
|
||||
"@types/node": "^18.15.11",
|
||||
"playwright": "^1.32.3",
|
||||
"tsup": "^6.7.0",
|
||||
"typescript": "^5.0.3",
|
||||
"vitest": "^0.29.8",
|
||||
"webpack-http-server": "^0.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"is-node-process": "^1.2.0",
|
||||
"outvariant": "^1.4.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsup",
|
||||
"test": "pnpm test:node && pnpm test:browser",
|
||||
"test:node": "vitest run",
|
||||
"test:browser": "playwright test",
|
||||
"release": "release publish"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user