@sapphire/plugin-logger 3.0.8-next.eccc557.0 → 4.0.0-pr-512.86f3d06.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +37 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.ts +383 -0
- package/dist/cjs/lib/Logger.cjs +101 -0
- package/dist/cjs/lib/Logger.cjs.map +1 -0
- package/dist/cjs/lib/LoggerLevel.cjs +48 -0
- package/dist/cjs/lib/LoggerLevel.cjs.map +1 -0
- package/dist/cjs/lib/LoggerStyle.cjs +115 -0
- package/dist/cjs/lib/LoggerStyle.cjs.map +1 -0
- package/dist/cjs/lib/LoggerTimestamp.cjs +55 -0
- package/dist/cjs/lib/LoggerTimestamp.cjs.map +1 -0
- package/dist/cjs/register.cjs +23 -0
- package/dist/cjs/register.cjs.map +1 -0
- package/dist/{register.d.ts → cjs/register.d.ts} +6 -4
- package/dist/esm/chunk-6QB3UK4Q.mjs +11 -0
- package/dist/esm/chunk-6QB3UK4Q.mjs.map +1 -0
- package/dist/esm/index.d.mts +383 -0
- package/dist/esm/index.mjs +11 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/lib/Logger.mjs +93 -0
- package/dist/esm/lib/Logger.mjs.map +1 -0
- package/dist/esm/lib/LoggerLevel.mjs +40 -0
- package/dist/esm/lib/LoggerLevel.mjs.map +1 -0
- package/dist/esm/lib/LoggerStyle.mjs +84 -0
- package/dist/esm/lib/LoggerStyle.mjs.map +1 -0
- package/dist/esm/lib/LoggerTimestamp.mjs +47 -0
- package/dist/esm/lib/LoggerTimestamp.mjs.map +1 -0
- package/dist/esm/register.d.mts +19 -0
- package/dist/esm/register.mjs +20 -0
- package/dist/esm/register.mjs.map +1 -0
- package/package.json +34 -18
- package/dist/index.d.ts +0 -10
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -21
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -10
- package/dist/lib/Logger.d.ts +0 -142
- package/dist/lib/Logger.d.ts.map +0 -1
- package/dist/lib/Logger.js +0 -114
- package/dist/lib/Logger.js.map +0 -1
- package/dist/lib/LoggerLevel.d.ts +0 -50
- package/dist/lib/LoggerLevel.d.ts.map +0 -1
- package/dist/lib/LoggerLevel.js +0 -58
- package/dist/lib/LoggerLevel.js.map +0 -1
- package/dist/lib/LoggerStyle.d.ts +0 -102
- package/dist/lib/LoggerStyle.d.ts.map +0 -1
- package/dist/lib/LoggerStyle.js +0 -130
- package/dist/lib/LoggerStyle.js.map +0 -1
- package/dist/lib/LoggerTimestamp.d.ts +0 -81
- package/dist/lib/LoggerTimestamp.d.ts.map +0 -1
- package/dist/lib/LoggerTimestamp.js +0 -68
- package/dist/lib/LoggerTimestamp.js.map +0 -1
- package/dist/register.d.ts.map +0 -1
- package/dist/register.js +0 -20
- package/dist/register.js.map +0 -1
- package/dist/register.mjs +0 -4
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { __name, __publicField } from '../chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import { Logger as Logger$1, LogLevel } from '@sapphire/framework';
|
|
3
|
+
import { isColorSupported, gray, magenta, cyan, yellow, red, bgRed, white } from 'colorette';
|
|
4
|
+
import { Console } from 'console';
|
|
5
|
+
import { inspect } from 'util';
|
|
6
|
+
import { LoggerLevel } from './LoggerLevel.mjs';
|
|
7
|
+
|
|
8
|
+
var _Logger = class _Logger extends Logger$1 {
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
super(options.level ?? LogLevel.Info);
|
|
11
|
+
/**
|
|
12
|
+
* The console this writes to.
|
|
13
|
+
* @since 1.0.0
|
|
14
|
+
*/
|
|
15
|
+
__publicField(this, "console");
|
|
16
|
+
/**
|
|
17
|
+
* The formats supported by the logger.
|
|
18
|
+
* @since 1.0.0
|
|
19
|
+
*/
|
|
20
|
+
__publicField(this, "formats");
|
|
21
|
+
/**
|
|
22
|
+
* The string `write` will join values by.
|
|
23
|
+
* @since 1.0.0
|
|
24
|
+
*/
|
|
25
|
+
__publicField(this, "join");
|
|
26
|
+
/**
|
|
27
|
+
* The inspect depth when logging objects.
|
|
28
|
+
* @since 1.0.0
|
|
29
|
+
*/
|
|
30
|
+
__publicField(this, "depth");
|
|
31
|
+
this.console = new Console(options.stdout ?? process.stdout, options.stderr ?? process.stderr);
|
|
32
|
+
this.formats = _Logger.createFormatMap(options.format, options.defaultFormat);
|
|
33
|
+
this.join = options.join ?? " ";
|
|
34
|
+
this.depth = options.depth ?? 0;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Writes the log message given a level and the value(s).
|
|
38
|
+
* @param level The log level.
|
|
39
|
+
* @param values The values to log.
|
|
40
|
+
*/
|
|
41
|
+
write(level, ...values) {
|
|
42
|
+
if (level < this.level)
|
|
43
|
+
return;
|
|
44
|
+
const method = this.levels.get(level) ?? "log";
|
|
45
|
+
const formatter = this.formats.get(level) ?? this.formats.get(LogLevel.None);
|
|
46
|
+
this.console[method](formatter.run(this.preprocess(values)));
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Pre-processes an array of values.
|
|
50
|
+
* @since 1.0.0
|
|
51
|
+
* @param values The values to pre-process.
|
|
52
|
+
*/
|
|
53
|
+
preprocess(values) {
|
|
54
|
+
const inspectOptions = { colors: isColorSupported, depth: this.depth };
|
|
55
|
+
return values.map((value) => typeof value === "string" ? value : inspect(value, inspectOptions)).join(this.join);
|
|
56
|
+
}
|
|
57
|
+
get levels() {
|
|
58
|
+
return Reflect.get(Logger$1, "levels");
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Gets whether or not colorette is enabled.
|
|
62
|
+
* @since 1.0.0
|
|
63
|
+
*/
|
|
64
|
+
static get stylize() {
|
|
65
|
+
return isColorSupported;
|
|
66
|
+
}
|
|
67
|
+
static createFormatMap(options = {}, defaults = options.none ?? {}) {
|
|
68
|
+
return /* @__PURE__ */ new Map([
|
|
69
|
+
[LogLevel.Trace, _Logger.ensureDefaultLevel(options.trace, defaults, gray, "TRACE")],
|
|
70
|
+
[LogLevel.Debug, _Logger.ensureDefaultLevel(options.debug, defaults, magenta, "DEBUG")],
|
|
71
|
+
[LogLevel.Info, _Logger.ensureDefaultLevel(options.info, defaults, cyan, "INFO")],
|
|
72
|
+
[LogLevel.Warn, _Logger.ensureDefaultLevel(options.warn, defaults, yellow, "WARN")],
|
|
73
|
+
[LogLevel.Error, _Logger.ensureDefaultLevel(options.error, defaults, red, "ERROR")],
|
|
74
|
+
[LogLevel.Fatal, _Logger.ensureDefaultLevel(options.fatal, defaults, bgRed, "FATAL")],
|
|
75
|
+
[LogLevel.None, _Logger.ensureDefaultLevel(options.none, defaults, white, "")]
|
|
76
|
+
]);
|
|
77
|
+
}
|
|
78
|
+
static ensureDefaultLevel(options, defaults, color, name) {
|
|
79
|
+
if (options)
|
|
80
|
+
return new LoggerLevel(options);
|
|
81
|
+
return new LoggerLevel({
|
|
82
|
+
...defaults,
|
|
83
|
+
timestamp: defaults.timestamp === null ? null : { ...defaults.timestamp ?? {}, color },
|
|
84
|
+
infix: name.length ? `${color(name.padEnd(5, " "))} - ` : ""
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__name(_Logger, "Logger");
|
|
89
|
+
var Logger = _Logger;
|
|
90
|
+
|
|
91
|
+
export { Logger };
|
|
92
|
+
//# sourceMappingURL=out.js.map
|
|
93
|
+
//# sourceMappingURL=Logger.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/Logger.ts"],"names":[],"mappings":"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","sourcesContent":["import { Logger as BuiltinLogger, LogLevel, type LogMethods } from '@sapphire/framework';\nimport { bgRed, cyan, gray, isColorSupported, magenta, red, white, yellow, type Color } from 'colorette';\nimport { Console } from 'console';\nimport { inspect, type InspectOptions } from 'util';\nimport { LoggerLevel, type LoggerLevelOptions } from './LoggerLevel';\n\n/**\n * The logger class.\n * @since 1.0.0\n */\nexport class Logger extends BuiltinLogger {\n\t/**\n\t * The console this writes to.\n\t * @since 1.0.0\n\t */\n\tpublic readonly console: Console;\n\n\t/**\n\t * The formats supported by the logger.\n\t * @since 1.0.0\n\t */\n\tpublic readonly formats: Map<LogLevel, LoggerLevel>;\n\n\t/**\n\t * The string `write` will join values by.\n\t * @since 1.0.0\n\t */\n\tpublic readonly join: string;\n\n\t/**\n\t * The inspect depth when logging objects.\n\t * @since 1.0.0\n\t */\n\tpublic readonly depth: number;\n\n\tpublic constructor(options: LoggerOptions = {}) {\n\t\tsuper(options.level ?? LogLevel.Info);\n\n\t\tthis.console = new Console(options.stdout ?? process.stdout, options.stderr ?? process.stderr);\n\t\tthis.formats = Logger.createFormatMap(options.format, options.defaultFormat);\n\t\tthis.join = options.join ?? ' ';\n\t\tthis.depth = options.depth ?? 0;\n\t}\n\n\t/**\n\t * Writes the log message given a level and the value(s).\n\t * @param level The log level.\n\t * @param values The values to log.\n\t */\n\tpublic override write(level: LogLevel, ...values: readonly unknown[]): void {\n\t\tif (level < this.level) return;\n\n\t\tconst method = this.levels.get(level) ?? 'log';\n\t\tconst formatter = this.formats.get(level) ?? this.formats.get(LogLevel.None)!;\n\n\t\tthis.console[method](formatter.run(this.preprocess(values)));\n\t}\n\n\t/**\n\t * Pre-processes an array of values.\n\t * @since 1.0.0\n\t * @param values The values to pre-process.\n\t */\n\tprotected preprocess(values: readonly unknown[]) {\n\t\tconst inspectOptions: InspectOptions = { colors: isColorSupported, depth: this.depth };\n\t\treturn values.map((value) => (typeof value === 'string' ? value : inspect(value, inspectOptions))).join(this.join);\n\t}\n\n\tprivate get levels() {\n\t\treturn Reflect.get(BuiltinLogger, 'levels') as Map<LogLevel, LogMethods>;\n\t}\n\n\t/**\n\t * Gets whether or not colorette is enabled.\n\t * @since 1.0.0\n\t */\n\tpublic static get stylize() {\n\t\treturn isColorSupported;\n\t}\n\n\tprivate static createFormatMap(options: LoggerFormatOptions = {}, defaults: LoggerLevelOptions = options.none ?? {}) {\n\t\treturn new Map<LogLevel, LoggerLevel>([\n\t\t\t[LogLevel.Trace, Logger.ensureDefaultLevel(options.trace, defaults, gray, 'TRACE')],\n\t\t\t[LogLevel.Debug, Logger.ensureDefaultLevel(options.debug, defaults, magenta, 'DEBUG')],\n\t\t\t[LogLevel.Info, Logger.ensureDefaultLevel(options.info, defaults, cyan, 'INFO')],\n\t\t\t[LogLevel.Warn, Logger.ensureDefaultLevel(options.warn, defaults, yellow, 'WARN')],\n\t\t\t[LogLevel.Error, Logger.ensureDefaultLevel(options.error, defaults, red, 'ERROR')],\n\t\t\t[LogLevel.Fatal, Logger.ensureDefaultLevel(options.fatal, defaults, bgRed, 'FATAL')],\n\t\t\t[LogLevel.None, Logger.ensureDefaultLevel(options.none, defaults, white, '')]\n\t\t]);\n\t}\n\n\tprivate static ensureDefaultLevel(options: LoggerLevelOptions | undefined, defaults: LoggerLevelOptions, color: Color, name: string) {\n\t\tif (options) return new LoggerLevel(options);\n\t\treturn new LoggerLevel({\n\t\t\t...defaults,\n\t\t\ttimestamp: defaults.timestamp === null ? null : { ...(defaults.timestamp ?? {}), color },\n\t\t\tinfix: name.length ? `${color(name.padEnd(5, ' '))} - ` : ''\n\t\t});\n\t}\n}\n\n/**\n * The logger options.\n * @since 1.0.0\n */\nexport interface LoggerOptions {\n\t/**\n\t * A writable stream for the output logs.\n\t * @since 1.0.0\n\t * @default process.stdout\n\t */\n\tstdout?: NodeJS.WritableStream;\n\n\t/**\n\t * A writable stream for the error logs.\n\t * @since 1.0.0\n\t * @default process.stderr\n\t */\n\tstderr?: NodeJS.WritableStream;\n\n\t/**\n\t * The default options used to fill all the possible values for {@link LoggerOptions.format}.\n\t * @since 1.0.0\n\t * @default options.format.none ?? {}\n\t */\n\tdefaultFormat?: LoggerLevelOptions;\n\n\t/**\n\t * The options for each log level. LogLevel.None serves to set the default for all keys, where only\n\t * {@link LoggerTimestampOptions.timestamp} and {@link LoggerLevelOptions.prefix} would be overridden.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\tformat?: LoggerFormatOptions;\n\n\t/**\n\t * The minimum log level.\n\t * @since 1.0.0\n\t * @default LogLevel.Info\n\t */\n\tlevel?: LogLevel;\n\n\t/**\n\t * The string that joins different messages.\n\t * @since 1.0.0\n\t * @default ' '\n\t */\n\tjoin?: string;\n\n\t/**\n\t * The inspect depth when logging objects.\n\t * @since 1.0.0\n\t * @default 0\n\t */\n\tdepth?: number;\n}\n\n/**\n * The logger format options.\n * @since 1.0.0\n */\nexport interface LoggerFormatOptions {\n\t/**\n\t * The logger options for the lowest log level, used when calling {@link ILogger.trace}.\n\t * @since 1.0.0\n\t */\n\ttrace?: LoggerLevelOptions;\n\n\t/**\n\t * The logger options for the debug level, used when calling {@link ILogger.debug}.\n\t * @since 1.0.0\n\t */\n\tdebug?: LoggerLevelOptions;\n\n\t/**\n\t * The logger options for the info level, used when calling {@link ILogger.info}.\n\t * @since 1.0.0\n\t */\n\tinfo?: LoggerLevelOptions;\n\n\t/**\n\t * The logger options for the warning level, used when calling {@link ILogger.warn}.\n\t * @since 1.0.0\n\t */\n\twarn?: LoggerLevelOptions;\n\n\t/**\n\t * The logger options for the error level, used when calling {@link ILogger.error}.\n\t * @since 1.0.0\n\t */\n\terror?: LoggerLevelOptions;\n\n\t/**\n\t * The logger options for the critical level, used when calling {@link ILogger.fatal}.\n\t * @since 1.0.0\n\t */\n\tfatal?: LoggerLevelOptions;\n\n\t/**\n\t * The logger options for an unknown or uncategorised level.\n\t * @since 1.0.0\n\t */\n\tnone?: LoggerLevelOptions;\n}\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __name, __publicField } from '../chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import { LoggerStyle } from './LoggerStyle.mjs';
|
|
3
|
+
import { LoggerTimestamp } from './LoggerTimestamp.mjs';
|
|
4
|
+
|
|
5
|
+
var _LoggerLevel = class _LoggerLevel {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
/**
|
|
8
|
+
* The timestamp formatter.
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
__publicField(this, "timestamp");
|
|
12
|
+
/**
|
|
13
|
+
* The infix, added between the timestamp and the message.
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
__publicField(this, "infix");
|
|
17
|
+
/**
|
|
18
|
+
* The style formatter for the message.
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
__publicField(this, "message");
|
|
22
|
+
this.timestamp = options.timestamp === null ? null : new LoggerTimestamp(options.timestamp);
|
|
23
|
+
this.infix = options.infix ?? "";
|
|
24
|
+
this.message = options.message === null ? null : new LoggerStyle(options.message);
|
|
25
|
+
}
|
|
26
|
+
run(content) {
|
|
27
|
+
const prefix = (this.timestamp?.run() ?? "") + this.infix;
|
|
28
|
+
if (prefix.length) {
|
|
29
|
+
const formatter = this.message ? (line) => prefix + this.message.run(line) : (line) => prefix + line;
|
|
30
|
+
return content.split("\n").map(formatter).join("\n");
|
|
31
|
+
}
|
|
32
|
+
return this.message ? this.message.run(content) : content;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
__name(_LoggerLevel, "LoggerLevel");
|
|
36
|
+
var LoggerLevel = _LoggerLevel;
|
|
37
|
+
|
|
38
|
+
export { LoggerLevel };
|
|
39
|
+
//# sourceMappingURL=out.js.map
|
|
40
|
+
//# sourceMappingURL=LoggerLevel.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/LoggerLevel.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,mBAA+C;AACxD,SAAS,uBAAoD;AAMtD,IAAM,eAAN,MAAM,aAAY;AAAA,EAmBjB,YAAY,UAA8B,CAAC,GAAG;AAdrD;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAGN,SAAK,YAAY,QAAQ,cAAc,OAAO,OAAO,IAAI,gBAAgB,QAAQ,SAAS;AAC1F,SAAK,QAAQ,QAAQ,SAAS;AAC9B,SAAK,UAAU,QAAQ,YAAY,OAAO,OAAO,IAAI,YAAY,QAAQ,OAAO;AAAA,EACjF;AAAA,EAEO,IAAI,SAAiB;AAC3B,UAAM,UAAU,KAAK,WAAW,IAAI,KAAK,MAAM,KAAK;AAEpD,QAAI,OAAO,QAAQ;AAClB,YAAM,YAAY,KAAK,UACpB,CAAC,SAAiB,SAAS,KAAK,QAAS,IAAI,IAAI,IACjD,CAAC,SAAiB,SAAS;AAC9B,aAAO,QAAQ,MAAM,IAAI,EAAE,IAAI,SAAS,EAAE,KAAK,IAAI;AAAA,IACpD;AAEA,WAAO,KAAK,UAAU,KAAK,QAAQ,IAAI,OAAO,IAAI;AAAA,EACnD;AACD;AArCyB;AAAlB,IAAM,cAAN","sourcesContent":["import { LoggerStyle, type LoggerStyleResolvable } from './LoggerStyle';\nimport { LoggerTimestamp, type LoggerTimestampOptions } from './LoggerTimestamp';\n\n/**\n * Logger utility that stores and applies a full style into the message.\n * @since 1.0.0\n */\nexport class LoggerLevel {\n\t/**\n\t * The timestamp formatter.\n\t * @since 1.0.0\n\t */\n\tpublic timestamp: LoggerTimestamp | null;\n\n\t/**\n\t * The infix, added between the timestamp and the message.\n\t * @since 1.0.0\n\t */\n\tpublic infix: string;\n\n\t/**\n\t * The style formatter for the message.\n\t * @since 1.0.0\n\t */\n\tpublic message: LoggerStyle | null;\n\n\tpublic constructor(options: LoggerLevelOptions = {}) {\n\t\tthis.timestamp = options.timestamp === null ? null : new LoggerTimestamp(options.timestamp);\n\t\tthis.infix = options.infix ?? '';\n\t\tthis.message = options.message === null ? null : new LoggerStyle(options.message);\n\t}\n\n\tpublic run(content: string) {\n\t\tconst prefix = (this.timestamp?.run() ?? '') + this.infix;\n\n\t\tif (prefix.length) {\n\t\t\tconst formatter = this.message //\n\t\t\t\t? (line: string) => prefix + this.message!.run(line)\n\t\t\t\t: (line: string) => prefix + line;\n\t\t\treturn content.split('\\n').map(formatter).join('\\n');\n\t\t}\n\n\t\treturn this.message ? this.message.run(content) : content;\n\t}\n}\n\n/**\n * The options for {@link LoggerLevel}.\n * @since 1.0.0\n */\nexport interface LoggerLevelOptions {\n\t/**\n\t * The timestamp options. Set to `null` to disable timestamp parsing.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\ttimestamp?: LoggerTimestampOptions | null;\n\n\t/**\n\t * The infix to be included between the timestamp and the message.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tinfix?: string;\n\n\t/**\n\t * The style options for the message.\n\t * @since 1.0.0\n\t * @default colorette.clear\n\t */\n\tmessage?: LoggerStyleResolvable | null;\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { __name, __publicField } from '../chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import * as Colorette from 'colorette';
|
|
3
|
+
|
|
4
|
+
var _LoggerStyle = class _LoggerStyle {
|
|
5
|
+
constructor(resolvable = {}) {
|
|
6
|
+
__publicField(this, "style");
|
|
7
|
+
if (typeof resolvable === "function") {
|
|
8
|
+
this.style = resolvable;
|
|
9
|
+
} else {
|
|
10
|
+
const styles = [];
|
|
11
|
+
if (resolvable.effects)
|
|
12
|
+
styles.push(...resolvable.effects.map((text) => Colorette[text]));
|
|
13
|
+
if (resolvable.text)
|
|
14
|
+
styles.push(Colorette[resolvable.text]);
|
|
15
|
+
if (resolvable.background)
|
|
16
|
+
styles.push(Colorette[resolvable.background]);
|
|
17
|
+
this.style = styles.length ? styles.length === 1 ? styles[0] : (string) => styles.reduce((out, style) => style(out), string) : Colorette.reset;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Applies the style to a string.
|
|
22
|
+
* @since 1.0.0
|
|
23
|
+
* @param string The value to apply the style to.
|
|
24
|
+
*/
|
|
25
|
+
run(string) {
|
|
26
|
+
return this.style(string);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
__name(_LoggerStyle, "LoggerStyle");
|
|
30
|
+
var LoggerStyle = _LoggerStyle;
|
|
31
|
+
var LoggerStyleEffect = /* @__PURE__ */ ((LoggerStyleEffect2) => {
|
|
32
|
+
LoggerStyleEffect2["Reset"] = "reset";
|
|
33
|
+
LoggerStyleEffect2["Bold"] = "bold";
|
|
34
|
+
LoggerStyleEffect2["Dim"] = "dim";
|
|
35
|
+
LoggerStyleEffect2["Italic"] = "italic";
|
|
36
|
+
LoggerStyleEffect2["Underline"] = "underline";
|
|
37
|
+
LoggerStyleEffect2["Inverse"] = "inverse";
|
|
38
|
+
LoggerStyleEffect2["Hidden"] = "hidden";
|
|
39
|
+
LoggerStyleEffect2["Strikethrough"] = "strikethrough";
|
|
40
|
+
return LoggerStyleEffect2;
|
|
41
|
+
})(LoggerStyleEffect || {});
|
|
42
|
+
var LoggerStyleText = /* @__PURE__ */ ((LoggerStyleText2) => {
|
|
43
|
+
LoggerStyleText2["Black"] = "black";
|
|
44
|
+
LoggerStyleText2["Red"] = "red";
|
|
45
|
+
LoggerStyleText2["Green"] = "green";
|
|
46
|
+
LoggerStyleText2["Yellow"] = "yellow";
|
|
47
|
+
LoggerStyleText2["Blue"] = "blue";
|
|
48
|
+
LoggerStyleText2["Magenta"] = "magenta";
|
|
49
|
+
LoggerStyleText2["Cyan"] = "cyan";
|
|
50
|
+
LoggerStyleText2["White"] = "white";
|
|
51
|
+
LoggerStyleText2["Gray"] = "gray";
|
|
52
|
+
LoggerStyleText2["BlackBright"] = "blackBright";
|
|
53
|
+
LoggerStyleText2["RedBright"] = "redBright";
|
|
54
|
+
LoggerStyleText2["GreenBright"] = "greenBright";
|
|
55
|
+
LoggerStyleText2["YellowBright"] = "yellowBright";
|
|
56
|
+
LoggerStyleText2["BlueBright"] = "blueBright";
|
|
57
|
+
LoggerStyleText2["MagentaBright"] = "magentaBright";
|
|
58
|
+
LoggerStyleText2["CyanBright"] = "cyanBright";
|
|
59
|
+
LoggerStyleText2["WhiteBright"] = "whiteBright";
|
|
60
|
+
return LoggerStyleText2;
|
|
61
|
+
})(LoggerStyleText || {});
|
|
62
|
+
var LoggerStyleBackground = /* @__PURE__ */ ((LoggerStyleBackground2) => {
|
|
63
|
+
LoggerStyleBackground2["Black"] = "bgBlack";
|
|
64
|
+
LoggerStyleBackground2["Red"] = "bgRed";
|
|
65
|
+
LoggerStyleBackground2["Green"] = "bgGreen";
|
|
66
|
+
LoggerStyleBackground2["Yellow"] = "bgYellow";
|
|
67
|
+
LoggerStyleBackground2["Blue"] = "bgBlue";
|
|
68
|
+
LoggerStyleBackground2["Magenta"] = "bgMagenta";
|
|
69
|
+
LoggerStyleBackground2["Cyan"] = "bgCyan";
|
|
70
|
+
LoggerStyleBackground2["White"] = "bgWhite";
|
|
71
|
+
LoggerStyleBackground2["BlackBright"] = "bgBlackBright";
|
|
72
|
+
LoggerStyleBackground2["RedBright"] = "bgRedBright";
|
|
73
|
+
LoggerStyleBackground2["GreenBright"] = "bgGreenBright";
|
|
74
|
+
LoggerStyleBackground2["YellowBright"] = "bgYellowBright";
|
|
75
|
+
LoggerStyleBackground2["BlueBright"] = "bgBlueBright";
|
|
76
|
+
LoggerStyleBackground2["MagentaBright"] = "bgMagentaBright";
|
|
77
|
+
LoggerStyleBackground2["CyanBright"] = "bgCyanBright";
|
|
78
|
+
LoggerStyleBackground2["WhiteBright"] = "bgWhiteBright";
|
|
79
|
+
return LoggerStyleBackground2;
|
|
80
|
+
})(LoggerStyleBackground || {});
|
|
81
|
+
|
|
82
|
+
export { LoggerStyle, LoggerStyleBackground, LoggerStyleEffect, LoggerStyleText };
|
|
83
|
+
//# sourceMappingURL=out.js.map
|
|
84
|
+
//# sourceMappingURL=LoggerStyle.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/LoggerStyle.ts"],"names":["LoggerStyleEffect","LoggerStyleText","LoggerStyleBackground"],"mappings":";;;;;;AAAA,YAAY,eAAe;AAMpB,IAAM,eAAN,MAAM,aAAY;AAAA,EAGjB,YAAY,aAAoC,CAAC,GAAG;AAF3D,wBAAgB;AAGf,QAAI,OAAO,eAAe,YAAY;AACrC,WAAK,QAAQ;AAAA,IACd,OAAO;AACN,YAAM,SAA4B,CAAC;AACnC,UAAI,WAAW;AAAS,eAAO,KAAK,GAAG,WAAW,QAAQ,IAAI,CAAC,SAAS,UAAU,IAAI,CAAC,CAAC;AACxF,UAAI,WAAW;AAAM,eAAO,KAAK,UAAU,WAAW,IAAI,CAAC;AAC3D,UAAI,WAAW;AAAY,eAAO,KAAK,UAAU,WAAW,UAAU,CAAC;AAEvE,WAAK,QAAQ,OAAO,SACjB,OAAO,WAAW,IACjB,OAAO,CAAC,IACR,CAAC,WAAW,OAAO,OAAO,CAAC,KAAK,UAAU,MAAM,GAAG,GAAG,MAAM,IACnD;AAAA,IACd;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOO,IAAI,QAAyB;AACnC,WAAO,KAAK,MAAM,MAAM;AAAA,EACzB;AACD;AA5ByB;AAAlB,IAAM,cAAN;AAiEA,IAAK,oBAAL,kBAAKA,uBAAL;AACN,EAAAA,mBAAA,WAAQ;AACR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,SAAM;AACN,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,eAAY;AACZ,EAAAA,mBAAA,aAAU;AACV,EAAAA,mBAAA,YAAS;AACT,EAAAA,mBAAA,mBAAgB;AARL,SAAAA;AAAA,GAAA;AAeL,IAAK,kBAAL,kBAAKC,qBAAL;AACN,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,SAAM;AACN,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,YAAS;AACT,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,aAAU;AACV,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,WAAQ;AACR,EAAAA,iBAAA,UAAO;AACP,EAAAA,iBAAA,iBAAc;AACd,EAAAA,iBAAA,eAAY;AACZ,EAAAA,iBAAA,iBAAc;AACd,EAAAA,iBAAA,kBAAe;AACf,EAAAA,iBAAA,gBAAa;AACb,EAAAA,iBAAA,mBAAgB;AAChB,EAAAA,iBAAA,gBAAa;AACb,EAAAA,iBAAA,iBAAc;AAjBH,SAAAA;AAAA,GAAA;AAwBL,IAAK,wBAAL,kBAAKC,2BAAL;AACN,EAAAA,uBAAA,WAAQ;AACR,EAAAA,uBAAA,SAAM;AACN,EAAAA,uBAAA,WAAQ;AACR,EAAAA,uBAAA,YAAS;AACT,EAAAA,uBAAA,UAAO;AACP,EAAAA,uBAAA,aAAU;AACV,EAAAA,uBAAA,UAAO;AACP,EAAAA,uBAAA,WAAQ;AACR,EAAAA,uBAAA,iBAAc;AACd,EAAAA,uBAAA,eAAY;AACZ,EAAAA,uBAAA,iBAAc;AACd,EAAAA,uBAAA,kBAAe;AACf,EAAAA,uBAAA,gBAAa;AACb,EAAAA,uBAAA,mBAAgB;AAChB,EAAAA,uBAAA,gBAAa;AACb,EAAAA,uBAAA,iBAAc;AAhBH,SAAAA;AAAA,GAAA","sourcesContent":["import * as Colorette from 'colorette';\n\n/**\n * Logger utility that applies a style to a string.\n * @since 1.0.0\n */\nexport class LoggerStyle {\n\tpublic readonly style: Colorette.Color;\n\n\tpublic constructor(resolvable: LoggerStyleResolvable = {}) {\n\t\tif (typeof resolvable === 'function') {\n\t\t\tthis.style = resolvable;\n\t\t} else {\n\t\t\tconst styles: Colorette.Color[] = [];\n\t\t\tif (resolvable.effects) styles.push(...resolvable.effects.map((text) => Colorette[text]));\n\t\t\tif (resolvable.text) styles.push(Colorette[resolvable.text]);\n\t\t\tif (resolvable.background) styles.push(Colorette[resolvable.background]);\n\n\t\t\tthis.style = styles.length\n\t\t\t\t? styles.length === 1\n\t\t\t\t\t? styles[0]\n\t\t\t\t\t: (string) => styles.reduce((out, style) => style(out), string) as string\n\t\t\t\t: Colorette.reset;\n\t\t}\n\t}\n\n\t/**\n\t * Applies the style to a string.\n\t * @since 1.0.0\n\t * @param string The value to apply the style to.\n\t */\n\tpublic run(string: string | number) {\n\t\treturn this.style(string);\n\t}\n}\n\n/**\n * The options for {@link LoggerStyle}.\n * @since 1.0.0\n */\nexport interface LoggerStyleOptions {\n\t/**\n\t * The text effects, e.g. `italic`, `strikethrough`, etc.\n\t * @since 1.0.0\n\t */\n\teffects?: LoggerStyleEffect[];\n\n\t/**\n\t * The text color, e.g. `red` or `yellow`.\n\t * @since 1.0.0\n\t */\n\ttext?: LoggerStyleText;\n\n\t/**\n\t * The background color, e.g. `magenta` or `red`.\n\t * @since 1.0.0\n\t */\n\tbackground?: LoggerStyleBackground;\n}\n\n/**\n * The value accepted by {@link LoggerStyle}'s constructor. Read `colorette`'s documentation for more information.\n * @since 1.0.0\n * @seealso https://www.npmjs.com/package/colorette\n */\nexport type LoggerStyleResolvable = Colorette.Color | LoggerStyleOptions;\n\n/**\n * The text styles.\n * @since 1.0.0\n */\nexport enum LoggerStyleEffect {\n\tReset = 'reset',\n\tBold = 'bold',\n\tDim = 'dim',\n\tItalic = 'italic',\n\tUnderline = 'underline',\n\tInverse = 'inverse',\n\tHidden = 'hidden',\n\tStrikethrough = 'strikethrough'\n}\n\n/**\n * The text colors.\n * @since 1.0.0\n */\nexport enum LoggerStyleText {\n\tBlack = 'black',\n\tRed = 'red',\n\tGreen = 'green',\n\tYellow = 'yellow',\n\tBlue = 'blue',\n\tMagenta = 'magenta',\n\tCyan = 'cyan',\n\tWhite = 'white',\n\tGray = 'gray',\n\tBlackBright = 'blackBright',\n\tRedBright = 'redBright',\n\tGreenBright = 'greenBright',\n\tYellowBright = 'yellowBright',\n\tBlueBright = 'blueBright',\n\tMagentaBright = 'magentaBright',\n\tCyanBright = 'cyanBright',\n\tWhiteBright = 'whiteBright'\n}\n\n/**\n * The background colors.\n * @since 1.0.0\n */\nexport enum LoggerStyleBackground {\n\tBlack = 'bgBlack',\n\tRed = 'bgRed',\n\tGreen = 'bgGreen',\n\tYellow = 'bgYellow',\n\tBlue = 'bgBlue',\n\tMagenta = 'bgMagenta',\n\tCyan = 'bgCyan',\n\tWhite = 'bgWhite',\n\tBlackBright = 'bgBlackBright',\n\tRedBright = 'bgRedBright',\n\tGreenBright = 'bgGreenBright',\n\tYellowBright = 'bgYellowBright',\n\tBlueBright = 'bgBlueBright',\n\tMagentaBright = 'bgMagentaBright',\n\tCyanBright = 'bgCyanBright',\n\tWhiteBright = 'bgWhiteBright'\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { __name, __publicField } from '../chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import { Timestamp } from '@sapphire/timestamp';
|
|
3
|
+
import { LoggerStyle } from './LoggerStyle.mjs';
|
|
4
|
+
|
|
5
|
+
var _LoggerTimestamp = class _LoggerTimestamp {
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
/**
|
|
8
|
+
* The timestamp used to format the current date.
|
|
9
|
+
* @since 1.0.0
|
|
10
|
+
*/
|
|
11
|
+
__publicField(this, "timestamp");
|
|
12
|
+
/**
|
|
13
|
+
* Whether or not the logger will show a timestamp in UTC.
|
|
14
|
+
* @since 1.0.0
|
|
15
|
+
*/
|
|
16
|
+
__publicField(this, "utc");
|
|
17
|
+
/**
|
|
18
|
+
* The logger style to apply the color to the timestamp.
|
|
19
|
+
* @since 1.0.0
|
|
20
|
+
*/
|
|
21
|
+
__publicField(this, "color");
|
|
22
|
+
/**
|
|
23
|
+
* The final formatter.
|
|
24
|
+
* @since 1.0.0
|
|
25
|
+
*/
|
|
26
|
+
__publicField(this, "formatter");
|
|
27
|
+
this.timestamp = new Timestamp(options.pattern ?? "YYYY-MM-DD HH:mm:ss");
|
|
28
|
+
this.utc = options.utc ?? false;
|
|
29
|
+
this.color = options.color === null ? null : new LoggerStyle(options.color);
|
|
30
|
+
this.formatter = options.formatter ?? ((timestamp) => `${timestamp} - `);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Formats the current time.
|
|
34
|
+
* @since 1.0.0
|
|
35
|
+
*/
|
|
36
|
+
run() {
|
|
37
|
+
const date = /* @__PURE__ */ new Date();
|
|
38
|
+
const result = this.utc ? this.timestamp.displayUTC(date) : this.timestamp.display(date);
|
|
39
|
+
return this.formatter(this.color ? this.color.run(result) : result);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
__name(_LoggerTimestamp, "LoggerTimestamp");
|
|
43
|
+
var LoggerTimestamp = _LoggerTimestamp;
|
|
44
|
+
|
|
45
|
+
export { LoggerTimestamp };
|
|
46
|
+
//# sourceMappingURL=out.js.map
|
|
47
|
+
//# sourceMappingURL=LoggerTimestamp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/lib/LoggerTimestamp.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAA+C;AAMjD,IAAM,mBAAN,MAAM,iBAAgB;AAAA,EAyBrB,YAAY,UAAkC,CAAC,GAAG;AApBzD;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAGN,SAAK,YAAY,IAAI,UAAU,QAAQ,WAAW,qBAAqB;AACvE,SAAK,MAAM,QAAQ,OAAO;AAC1B,SAAK,QAAQ,QAAQ,UAAU,OAAO,OAAO,IAAI,YAAY,QAAQ,KAAK;AAC1E,SAAK,YAAY,QAAQ,cAAc,CAAC,cAAc,GAAG,SAAS;AAAA,EACnE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMO,MAAM;AACZ,UAAM,OAAO,oBAAI,KAAK;AACtB,UAAM,SAAS,KAAK,MAAM,KAAK,UAAU,WAAW,IAAI,IAAI,KAAK,UAAU,QAAQ,IAAI;AACvF,WAAO,KAAK,UAAU,KAAK,QAAQ,KAAK,MAAM,IAAI,MAAM,IAAI,MAAM;AAAA,EACnE;AACD;AAzC6B;AAAtB,IAAM,kBAAN","sourcesContent":["import { Timestamp } from '@sapphire/timestamp';\nimport { LoggerStyle, type LoggerStyleResolvable } from './LoggerStyle';\n\n/**\n * Logger utility that formats a timestamp.\n * @since 1.0.0\n */\nexport class LoggerTimestamp {\n\t/**\n\t * The timestamp used to format the current date.\n\t * @since 1.0.0\n\t */\n\tpublic timestamp: Timestamp;\n\n\t/**\n\t * Whether or not the logger will show a timestamp in UTC.\n\t * @since 1.0.0\n\t */\n\tpublic utc: boolean;\n\n\t/**\n\t * The logger style to apply the color to the timestamp.\n\t * @since 1.0.0\n\t */\n\tpublic color: LoggerStyle | null;\n\n\t/**\n\t * The final formatter.\n\t * @since 1.0.0\n\t */\n\tpublic formatter: LoggerTimestampFormatter;\n\n\tpublic constructor(options: LoggerTimestampOptions = {}) {\n\t\tthis.timestamp = new Timestamp(options.pattern ?? 'YYYY-MM-DD HH:mm:ss');\n\t\tthis.utc = options.utc ?? false;\n\t\tthis.color = options.color === null ? null : new LoggerStyle(options.color);\n\t\tthis.formatter = options.formatter ?? ((timestamp) => `${timestamp} - `);\n\t}\n\n\t/**\n\t * Formats the current time.\n\t * @since 1.0.0\n\t */\n\tpublic run() {\n\t\tconst date = new Date();\n\t\tconst result = this.utc ? this.timestamp.displayUTC(date) : this.timestamp.display(date);\n\t\treturn this.formatter(this.color ? this.color.run(result) : result);\n\t}\n}\n\n/**\n * The options for {@link LoggerTimestamp}.\n * @since 1.0.0\n */\nexport interface LoggerTimestampOptions {\n\t/**\n\t * The {@link Timestamp} pattern.\n\t * @since 1.0.0\n\t * @default 'YYYY-MM-DD HH:mm:ss'\n\t * @example\n\t * ```typescript\n\t * 'YYYY-MM-DD HH:mm:ss'\n\t * // 2020-12-23 22:01:10\n\t * ```\n\t */\n\tpattern?: string;\n\n\t/**\n\t * Whether or not the date should be UTC.\n\t * @since 1.0.0\n\t * @default false\n\t */\n\tutc?: boolean;\n\n\t/**\n\t * The color to use.\n\t * @since 1.0.0\n\t * @default colorette.reset\n\t */\n\tcolor?: LoggerStyleResolvable | null;\n\n\t/**\n\t * The formatter. See {@link LoggerTimestampFormatter} for more information.\n\t * @since 1.0.0\n\t * @default (value) => `${value} - `\n\t */\n\tformatter?: LoggerTimestampFormatter;\n}\n\n/**\n * The formatter used for {@link LoggerTimestampOptions}. This will be run **after** applying the color to the formatter.\n * @since 1.0.0\n */\nexport interface LoggerTimestampFormatter {\n\t/**\n\t * @param timestamp The output of {@link LoggerStyle.run} on {@link Timestamp.display}/{@link Timestamp.displayUTC}.\n\t * @since 1.0.0\n\t */\n\t(timestamp: string): string;\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Plugin, preGenericsInitialization, SapphireClient } from '@sapphire/framework';
|
|
2
|
+
import { ClientOptions } from 'discord.js';
|
|
3
|
+
import { LoggerOptions } from './lib/Logger.mjs';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
declare class LoggerPlugin extends Plugin {
|
|
9
|
+
/**
|
|
10
|
+
* @since 1.0.0
|
|
11
|
+
*/
|
|
12
|
+
static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void;
|
|
13
|
+
}
|
|
14
|
+
declare module '@sapphire/framework' {
|
|
15
|
+
interface ClientLoggerOptions extends LoggerOptions {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { LoggerPlugin };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { __name } from './chunk-6QB3UK4Q.mjs';
|
|
2
|
+
import { SapphireClient, preGenericsInitialization, Plugin } from '@sapphire/framework';
|
|
3
|
+
import { Logger } from './lib/Logger.mjs';
|
|
4
|
+
|
|
5
|
+
var _LoggerPlugin = class _LoggerPlugin extends Plugin {
|
|
6
|
+
/**
|
|
7
|
+
* @since 1.0.0
|
|
8
|
+
*/
|
|
9
|
+
static [preGenericsInitialization](options) {
|
|
10
|
+
options.logger ??= {};
|
|
11
|
+
options.logger.instance = new Logger(options.logger);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
__name(_LoggerPlugin, "LoggerPlugin");
|
|
15
|
+
var LoggerPlugin = _LoggerPlugin;
|
|
16
|
+
SapphireClient.plugins.registerPreGenericsInitializationHook(LoggerPlugin[preGenericsInitialization], "Logger-PreGenericsInitialization");
|
|
17
|
+
|
|
18
|
+
export { LoggerPlugin };
|
|
19
|
+
//# sourceMappingURL=out.js.map
|
|
20
|
+
//# sourceMappingURL=register.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/register.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,QAAQ,2BAA2B,sBAAsB;AAElE,SAAS,cAAkC;AAKpC,IAAM,gBAAN,MAAM,sBAAqB,OAAO;AAAA;AAAA;AAAA;AAAA,EAIxC,QAAe,yBAAyB,EAAwB,SAA8B;AAC7F,YAAQ,WAAW,CAAC;AACpB,YAAQ,OAAO,WAAW,IAAI,OAAO,QAAQ,MAAM;AAAA,EACpD;AACD;AARyC;AAAlC,IAAM,eAAN;AAcP,eAAe,QAAQ,sCAAsC,aAAa,yBAAyB,GAAG,kCAAkC","sourcesContent":["import { Plugin, preGenericsInitialization, SapphireClient } from '@sapphire/framework';\nimport type { ClientOptions } from 'discord.js';\nimport { Logger, type LoggerOptions } from './lib/Logger';\n\n/**\n * @since 1.0.0\n */\nexport class LoggerPlugin extends Plugin {\n\t/**\n\t * @since 1.0.0\n\t */\n\tpublic static [preGenericsInitialization](this: SapphireClient, options: ClientOptions): void {\n\t\toptions.logger ??= {};\n\t\toptions.logger.instance = new Logger(options.logger);\n\t}\n}\n\ndeclare module '@sapphire/framework' {\n\texport interface ClientLoggerOptions extends LoggerOptions {}\n}\n\nSapphireClient.plugins.registerPreGenericsInitializationHook(LoggerPlugin[preGenericsInitialization], 'Logger-PreGenericsInitialization');\n"]}
|
package/package.json
CHANGED
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sapphire/plugin-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-pr-512.86f3d06.0",
|
|
4
4
|
"description": "Plugin for @sapphire/framework to have pretty console output",
|
|
5
5
|
"author": "@sapphire",
|
|
6
6
|
"license": "MIT",
|
|
7
|
-
"main": "dist/index.
|
|
8
|
-
"module": "dist/index.mjs",
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
7
|
+
"main": "dist/cjs/index.cjs",
|
|
8
|
+
"module": "dist/esm/index.mjs",
|
|
9
|
+
"types": "dist/cjs/index.d.ts",
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
"import": {
|
|
13
|
+
"types": "./dist/esm/index.d.mts",
|
|
14
|
+
"default": "./dist/esm/index.mjs"
|
|
15
|
+
},
|
|
16
|
+
"require": {
|
|
17
|
+
"types": "./dist/cjs/index.d.ts",
|
|
18
|
+
"default": "./dist/cjs/index.cjs"
|
|
19
|
+
}
|
|
15
20
|
},
|
|
16
21
|
"./register": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
"import": {
|
|
23
|
+
"types": "./dist/esm/register.d.mts",
|
|
24
|
+
"default": "./dist/esm/register.mjs"
|
|
25
|
+
},
|
|
26
|
+
"require": {
|
|
27
|
+
"types": "./dist/cjs/register.d.ts",
|
|
28
|
+
"default": "./dist/cjs/register.cjs"
|
|
29
|
+
}
|
|
20
30
|
}
|
|
21
31
|
},
|
|
22
32
|
"sideEffects": [
|
|
23
|
-
"./dist/register.
|
|
24
|
-
"./dist/register.mjs"
|
|
33
|
+
"./dist/cjs/register.cjs",
|
|
34
|
+
"./dist/esm/register.mjs"
|
|
25
35
|
],
|
|
26
36
|
"homepage": "https://github.com/sapphiredev/plugins/tree/main/packages/logger",
|
|
27
37
|
"scripts": {
|
|
28
38
|
"test": "vitest run",
|
|
29
39
|
"lint": "eslint src tests --ext ts --fix",
|
|
30
|
-
"build": "
|
|
31
|
-
"
|
|
32
|
-
"
|
|
40
|
+
"build": "tsup && yarn build:types",
|
|
41
|
+
"build:types": "concurrently \"yarn:build:types:*\"",
|
|
42
|
+
"build:types:cjs": "rollup-type-bundler -d dist/cjs",
|
|
43
|
+
"build:types:esm": "rollup-type-bundler -d dist/esm -t .mts",
|
|
44
|
+
"build:types:cleanup": "tsx ../../scripts/clean-register-imports.mts",
|
|
45
|
+
"typecheck": "tsc -b src",
|
|
33
46
|
"docs": "typedoc-json-parser",
|
|
34
47
|
"prepack": "yarn build",
|
|
35
48
|
"bump": "cliff-jumper",
|
|
@@ -70,9 +83,12 @@
|
|
|
70
83
|
},
|
|
71
84
|
"devDependencies": {
|
|
72
85
|
"@favware/cliff-jumper": "^2.2.3",
|
|
73
|
-
"
|
|
74
|
-
"
|
|
86
|
+
"@favware/rollup-type-bundler": "^3.2.0",
|
|
87
|
+
"concurrently": "^8.2.2",
|
|
88
|
+
"tsup": "^8.0.1",
|
|
89
|
+
"tsx": "^4.6.2",
|
|
90
|
+
"typedoc": "^0.25.4",
|
|
75
91
|
"typedoc-json-parser": "^9.0.1",
|
|
76
|
-
"typescript": "^5.
|
|
92
|
+
"typescript": "^5.3.2"
|
|
77
93
|
}
|
|
78
94
|
}
|
package/dist/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { LoggerOptions } from './lib/Logger';
|
|
2
|
-
export * from './lib/Logger';
|
|
3
|
-
export * from './lib/LoggerLevel';
|
|
4
|
-
export * from './lib/LoggerStyle';
|
|
5
|
-
export * from './lib/LoggerTimestamp';
|
|
6
|
-
declare module '@sapphire/framework' {
|
|
7
|
-
interface ClientLoggerOptions extends LoggerOptions {
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AAEtC,OAAO,QAAQ,qBAAqB,CAAC;IACpC,UAAiB,mBAAoB,SAAQ,aAAa;KAAG;CAC7D"}
|
package/dist/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./lib/Logger"), exports);
|
|
18
|
-
__exportStar(require("./lib/LoggerLevel"), exports);
|
|
19
|
-
__exportStar(require("./lib/LoggerStyle"), exports);
|
|
20
|
-
__exportStar(require("./lib/LoggerTimestamp"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,+CAA6B;AAC7B,oDAAkC;AAClC,oDAAkC;AAClC,wDAAsC"}
|
package/dist/index.mjs
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import mod from "./index.js";
|
|
2
|
-
|
|
3
|
-
export default mod;
|
|
4
|
-
export const Logger = mod.Logger;
|
|
5
|
-
export const LoggerLevel = mod.LoggerLevel;
|
|
6
|
-
export const LoggerStyle = mod.LoggerStyle;
|
|
7
|
-
export const LoggerStyleBackground = mod.LoggerStyleBackground;
|
|
8
|
-
export const LoggerStyleEffect = mod.LoggerStyleEffect;
|
|
9
|
-
export const LoggerStyleText = mod.LoggerStyleText;
|
|
10
|
-
export const LoggerTimestamp = mod.LoggerTimestamp;
|
package/dist/lib/Logger.d.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import { Logger as BuiltinLogger, LogLevel } from '@sapphire/framework';
|
|
4
|
-
import { LoggerLevel, type LoggerLevelOptions } from './LoggerLevel';
|
|
5
|
-
/**
|
|
6
|
-
* The logger class.
|
|
7
|
-
* @since 1.0.0
|
|
8
|
-
*/
|
|
9
|
-
export declare class Logger extends BuiltinLogger {
|
|
10
|
-
/**
|
|
11
|
-
* The console this writes to.
|
|
12
|
-
* @since 1.0.0
|
|
13
|
-
*/
|
|
14
|
-
readonly console: Console;
|
|
15
|
-
/**
|
|
16
|
-
* The formats supported by the logger.
|
|
17
|
-
* @since 1.0.0
|
|
18
|
-
*/
|
|
19
|
-
readonly formats: Map<LogLevel, LoggerLevel>;
|
|
20
|
-
/**
|
|
21
|
-
* The string `write` will join values by.
|
|
22
|
-
* @since 1.0.0
|
|
23
|
-
*/
|
|
24
|
-
readonly join: string;
|
|
25
|
-
/**
|
|
26
|
-
* The inspect depth when logging objects.
|
|
27
|
-
* @since 1.0.0
|
|
28
|
-
*/
|
|
29
|
-
readonly depth: number;
|
|
30
|
-
constructor(options?: LoggerOptions);
|
|
31
|
-
/**
|
|
32
|
-
* Writes the log message given a level and the value(s).
|
|
33
|
-
* @param level The log level.
|
|
34
|
-
* @param values The values to log.
|
|
35
|
-
*/
|
|
36
|
-
write(level: LogLevel, ...values: readonly unknown[]): void;
|
|
37
|
-
/**
|
|
38
|
-
* Pre-processes an array of values.
|
|
39
|
-
* @since 1.0.0
|
|
40
|
-
* @param values The values to pre-process.
|
|
41
|
-
*/
|
|
42
|
-
protected preprocess(values: readonly unknown[]): string;
|
|
43
|
-
private get levels();
|
|
44
|
-
/**
|
|
45
|
-
* Gets whether or not colorette is enabled.
|
|
46
|
-
* @since 1.0.0
|
|
47
|
-
*/
|
|
48
|
-
static get stylize(): boolean;
|
|
49
|
-
private static createFormatMap;
|
|
50
|
-
private static ensureDefaultLevel;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* The logger options.
|
|
54
|
-
* @since 1.0.0
|
|
55
|
-
*/
|
|
56
|
-
export interface LoggerOptions {
|
|
57
|
-
/**
|
|
58
|
-
* A writable stream for the output logs.
|
|
59
|
-
* @since 1.0.0
|
|
60
|
-
* @default process.stdout
|
|
61
|
-
*/
|
|
62
|
-
stdout?: NodeJS.WritableStream;
|
|
63
|
-
/**
|
|
64
|
-
* A writable stream for the error logs.
|
|
65
|
-
* @since 1.0.0
|
|
66
|
-
* @default process.stderr
|
|
67
|
-
*/
|
|
68
|
-
stderr?: NodeJS.WritableStream;
|
|
69
|
-
/**
|
|
70
|
-
* The default options used to fill all the possible values for {@link LoggerOptions.format}.
|
|
71
|
-
* @since 1.0.0
|
|
72
|
-
* @default options.format.none ?? {}
|
|
73
|
-
*/
|
|
74
|
-
defaultFormat?: LoggerLevelOptions;
|
|
75
|
-
/**
|
|
76
|
-
* The options for each log level. LogLevel.None serves to set the default for all keys, where only
|
|
77
|
-
* {@link LoggerTimestampOptions.timestamp} and {@link LoggerLevelOptions.prefix} would be overridden.
|
|
78
|
-
* @since 1.0.0
|
|
79
|
-
* @default {}
|
|
80
|
-
*/
|
|
81
|
-
format?: LoggerFormatOptions;
|
|
82
|
-
/**
|
|
83
|
-
* The minimum log level.
|
|
84
|
-
* @since 1.0.0
|
|
85
|
-
* @default LogLevel.Info
|
|
86
|
-
*/
|
|
87
|
-
level?: LogLevel;
|
|
88
|
-
/**
|
|
89
|
-
* The string that joins different messages.
|
|
90
|
-
* @since 1.0.0
|
|
91
|
-
* @default ' '
|
|
92
|
-
*/
|
|
93
|
-
join?: string;
|
|
94
|
-
/**
|
|
95
|
-
* The inspect depth when logging objects.
|
|
96
|
-
* @since 1.0.0
|
|
97
|
-
* @default 0
|
|
98
|
-
*/
|
|
99
|
-
depth?: number;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* The logger format options.
|
|
103
|
-
* @since 1.0.0
|
|
104
|
-
*/
|
|
105
|
-
export interface LoggerFormatOptions {
|
|
106
|
-
/**
|
|
107
|
-
* The logger options for the lowest log level, used when calling {@link ILogger.trace}.
|
|
108
|
-
* @since 1.0.0
|
|
109
|
-
*/
|
|
110
|
-
trace?: LoggerLevelOptions;
|
|
111
|
-
/**
|
|
112
|
-
* The logger options for the debug level, used when calling {@link ILogger.debug}.
|
|
113
|
-
* @since 1.0.0
|
|
114
|
-
*/
|
|
115
|
-
debug?: LoggerLevelOptions;
|
|
116
|
-
/**
|
|
117
|
-
* The logger options for the info level, used when calling {@link ILogger.info}.
|
|
118
|
-
* @since 1.0.0
|
|
119
|
-
*/
|
|
120
|
-
info?: LoggerLevelOptions;
|
|
121
|
-
/**
|
|
122
|
-
* The logger options for the warning level, used when calling {@link ILogger.warn}.
|
|
123
|
-
* @since 1.0.0
|
|
124
|
-
*/
|
|
125
|
-
warn?: LoggerLevelOptions;
|
|
126
|
-
/**
|
|
127
|
-
* The logger options for the error level, used when calling {@link ILogger.error}.
|
|
128
|
-
* @since 1.0.0
|
|
129
|
-
*/
|
|
130
|
-
error?: LoggerLevelOptions;
|
|
131
|
-
/**
|
|
132
|
-
* The logger options for the critical level, used when calling {@link ILogger.fatal}.
|
|
133
|
-
* @since 1.0.0
|
|
134
|
-
*/
|
|
135
|
-
fatal?: LoggerLevelOptions;
|
|
136
|
-
/**
|
|
137
|
-
* The logger options for an unknown or uncategorised level.
|
|
138
|
-
* @since 1.0.0
|
|
139
|
-
*/
|
|
140
|
-
none?: LoggerLevelOptions;
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=Logger.d.ts.map
|
package/dist/lib/Logger.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/lib/Logger.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,QAAQ,EAAmB,MAAM,qBAAqB,CAAC;AAIzF,OAAO,EAAE,WAAW,EAAE,KAAK,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAErE;;;GAGG;AACH,qBAAa,MAAO,SAAQ,aAAa;IACxC;;;OAGG;IACH,SAAgB,OAAO,EAAE,OAAO,CAAC;IAEjC;;;OAGG;IACH,SAAgB,OAAO,EAAE,GAAG,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAEpD;;;OAGG;IACH,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B;;;OAGG;IACH,SAAgB,KAAK,EAAE,MAAM,CAAC;gBAEX,OAAO,GAAE,aAAkB;IAS9C;;;;OAIG;IACa,KAAK,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,EAAE,SAAS,OAAO,EAAE,GAAG,IAAI;IAS3E;;;;OAIG;IACH,SAAS,CAAC,UAAU,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE;IAK/C,OAAO,KAAK,MAAM,GAEjB;IAED;;;OAGG;IACH,WAAkB,OAAO,YAExB;IAED,OAAO,CAAC,MAAM,CAAC,eAAe;IAY9B,OAAO,CAAC,MAAM,CAAC,kBAAkB;CAQjC;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAE/B;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;IAE/B;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IAEnC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAE7B;;;;OAIG;IACH,KAAK,CAAC,EAAE,QAAQ,CAAC;IAEjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC;;;OAGG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;OAGG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAE1B;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;IAE1B;;;OAGG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;OAGG;IACH,KAAK,CAAC,EAAE,kBAAkB,CAAC;IAE3B;;;OAGG;IACH,IAAI,CAAC,EAAE,kBAAkB,CAAC;CAC1B"}
|