@sapphire/plugin-logger 3.0.8-next.eccc557.0 → 4.0.0-next.8540da8.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.
Files changed (57) hide show
  1. package/dist/cjs/index.cjs +37 -0
  2. package/dist/cjs/index.cjs.map +1 -0
  3. package/dist/cjs/index.d.ts +383 -0
  4. package/dist/cjs/lib/Logger.cjs +101 -0
  5. package/dist/cjs/lib/Logger.cjs.map +1 -0
  6. package/dist/cjs/lib/LoggerLevel.cjs +48 -0
  7. package/dist/cjs/lib/LoggerLevel.cjs.map +1 -0
  8. package/dist/cjs/lib/LoggerStyle.cjs +115 -0
  9. package/dist/cjs/lib/LoggerStyle.cjs.map +1 -0
  10. package/dist/cjs/lib/LoggerTimestamp.cjs +55 -0
  11. package/dist/cjs/lib/LoggerTimestamp.cjs.map +1 -0
  12. package/dist/cjs/register.cjs +23 -0
  13. package/dist/cjs/register.cjs.map +1 -0
  14. package/dist/cjs/register.d.ts +14 -0
  15. package/dist/esm/chunk-6QB3UK4Q.mjs +11 -0
  16. package/dist/esm/chunk-6QB3UK4Q.mjs.map +1 -0
  17. package/dist/esm/index.d.mts +383 -0
  18. package/dist/esm/index.mjs +11 -0
  19. package/dist/esm/index.mjs.map +1 -0
  20. package/dist/esm/lib/Logger.mjs +93 -0
  21. package/dist/esm/lib/Logger.mjs.map +1 -0
  22. package/dist/esm/lib/LoggerLevel.mjs +40 -0
  23. package/dist/esm/lib/LoggerLevel.mjs.map +1 -0
  24. package/dist/esm/lib/LoggerStyle.mjs +84 -0
  25. package/dist/esm/lib/LoggerStyle.mjs.map +1 -0
  26. package/dist/esm/lib/LoggerTimestamp.mjs +47 -0
  27. package/dist/esm/lib/LoggerTimestamp.mjs.map +1 -0
  28. package/dist/esm/register.d.mts +14 -0
  29. package/dist/esm/register.mjs +20 -0
  30. package/dist/esm/register.mjs.map +1 -0
  31. package/package.json +36 -21
  32. package/dist/index.d.ts +0 -10
  33. package/dist/index.d.ts.map +0 -1
  34. package/dist/index.js +0 -21
  35. package/dist/index.js.map +0 -1
  36. package/dist/index.mjs +0 -10
  37. package/dist/lib/Logger.d.ts +0 -142
  38. package/dist/lib/Logger.d.ts.map +0 -1
  39. package/dist/lib/Logger.js +0 -114
  40. package/dist/lib/Logger.js.map +0 -1
  41. package/dist/lib/LoggerLevel.d.ts +0 -50
  42. package/dist/lib/LoggerLevel.d.ts.map +0 -1
  43. package/dist/lib/LoggerLevel.js +0 -58
  44. package/dist/lib/LoggerLevel.js.map +0 -1
  45. package/dist/lib/LoggerStyle.d.ts +0 -102
  46. package/dist/lib/LoggerStyle.d.ts.map +0 -1
  47. package/dist/lib/LoggerStyle.js +0 -130
  48. package/dist/lib/LoggerStyle.js.map +0 -1
  49. package/dist/lib/LoggerTimestamp.d.ts +0 -81
  50. package/dist/lib/LoggerTimestamp.d.ts.map +0 -1
  51. package/dist/lib/LoggerTimestamp.js +0 -68
  52. package/dist/lib/LoggerTimestamp.js.map +0 -1
  53. package/dist/register.d.ts +0 -17
  54. package/dist/register.d.ts.map +0 -1
  55. package/dist/register.js +0 -20
  56. package/dist/register.js.map +0 -1
  57. package/dist/register.mjs +0 -4
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var Logger_cjs = require('./lib/Logger.cjs');
4
+ var LoggerLevel_cjs = require('./lib/LoggerLevel.cjs');
5
+ var LoggerStyle_cjs = require('./lib/LoggerStyle.cjs');
6
+ var LoggerTimestamp_cjs = require('./lib/LoggerTimestamp.cjs');
7
+
8
+ // src/index.ts
9
+ var version = "4.0.0-next.8540da8.0";
10
+
11
+ exports.version = version;
12
+ Object.keys(Logger_cjs).forEach(function (k) {
13
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
14
+ enumerable: true,
15
+ get: function () { return Logger_cjs[k]; }
16
+ });
17
+ });
18
+ Object.keys(LoggerLevel_cjs).forEach(function (k) {
19
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
20
+ enumerable: true,
21
+ get: function () { return LoggerLevel_cjs[k]; }
22
+ });
23
+ });
24
+ Object.keys(LoggerStyle_cjs).forEach(function (k) {
25
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
26
+ enumerable: true,
27
+ get: function () { return LoggerStyle_cjs[k]; }
28
+ });
29
+ });
30
+ Object.keys(LoggerTimestamp_cjs).forEach(function (k) {
31
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
32
+ enumerable: true,
33
+ get: function () { return LoggerTimestamp_cjs[k]; }
34
+ });
35
+ });
36
+ //# sourceMappingURL=out.js.map
37
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";AAEA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAaP,IAAM,UAAkB","sourcesContent":["import type { LoggerOptions } from './lib/Logger';\n\nexport * from './lib/Logger';\nexport * from './lib/LoggerLevel';\nexport * from './lib/LoggerStyle';\nexport * from './lib/LoggerTimestamp';\n\ndeclare module '@sapphire/framework' {\n\texport interface ClientLoggerOptions extends LoggerOptions {}\n}\n\n/**\n * The [@sapphire/plugin-logger](https://github.com/sapphiredev/plugins/blob/main/packages/logger) version that you are currently using.\n * An example use of this is showing it of in a bot information command.\n *\n * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild\n */\n// eslint-disable-next-line @typescript-eslint/no-inferrable-types\nexport const version: string = '4.0.0-next.8540da8.0';\n"]}
@@ -0,0 +1,383 @@
1
+ import { Logger as Logger$1, LogLevel } from '@sapphire/framework';
2
+ import * as Colorette from 'colorette';
3
+ import { Timestamp } from '@sapphire/timestamp';
4
+
5
+ /**
6
+ * Logger utility that applies a style to a string.
7
+ * @since 1.0.0
8
+ */
9
+ declare class LoggerStyle {
10
+ readonly style: Colorette.Color;
11
+ constructor(resolvable?: LoggerStyleResolvable);
12
+ /**
13
+ * Applies the style to a string.
14
+ * @since 1.0.0
15
+ * @param string The value to apply the style to.
16
+ */
17
+ run(string: string | number): string;
18
+ }
19
+ /**
20
+ * The options for {@link LoggerStyle}.
21
+ * @since 1.0.0
22
+ */
23
+ interface LoggerStyleOptions {
24
+ /**
25
+ * The text effects, e.g. `italic`, `strikethrough`, etc.
26
+ * @since 1.0.0
27
+ */
28
+ effects?: LoggerStyleEffect[];
29
+ /**
30
+ * The text color, e.g. `red` or `yellow`.
31
+ * @since 1.0.0
32
+ */
33
+ text?: LoggerStyleText;
34
+ /**
35
+ * The background color, e.g. `magenta` or `red`.
36
+ * @since 1.0.0
37
+ */
38
+ background?: LoggerStyleBackground;
39
+ }
40
+ /**
41
+ * The value accepted by {@link LoggerStyle}'s constructor. Read `colorette`'s documentation for more information.
42
+ * @since 1.0.0
43
+ * @seealso https://www.npmjs.com/package/colorette
44
+ */
45
+ type LoggerStyleResolvable = Colorette.Color | LoggerStyleOptions;
46
+ /**
47
+ * The text styles.
48
+ * @since 1.0.0
49
+ */
50
+ declare enum LoggerStyleEffect {
51
+ Reset = "reset",
52
+ Bold = "bold",
53
+ Dim = "dim",
54
+ Italic = "italic",
55
+ Underline = "underline",
56
+ Inverse = "inverse",
57
+ Hidden = "hidden",
58
+ Strikethrough = "strikethrough"
59
+ }
60
+ /**
61
+ * The text colors.
62
+ * @since 1.0.0
63
+ */
64
+ declare enum LoggerStyleText {
65
+ Black = "black",
66
+ Red = "red",
67
+ Green = "green",
68
+ Yellow = "yellow",
69
+ Blue = "blue",
70
+ Magenta = "magenta",
71
+ Cyan = "cyan",
72
+ White = "white",
73
+ Gray = "gray",
74
+ BlackBright = "blackBright",
75
+ RedBright = "redBright",
76
+ GreenBright = "greenBright",
77
+ YellowBright = "yellowBright",
78
+ BlueBright = "blueBright",
79
+ MagentaBright = "magentaBright",
80
+ CyanBright = "cyanBright",
81
+ WhiteBright = "whiteBright"
82
+ }
83
+ /**
84
+ * The background colors.
85
+ * @since 1.0.0
86
+ */
87
+ declare enum LoggerStyleBackground {
88
+ Black = "bgBlack",
89
+ Red = "bgRed",
90
+ Green = "bgGreen",
91
+ Yellow = "bgYellow",
92
+ Blue = "bgBlue",
93
+ Magenta = "bgMagenta",
94
+ Cyan = "bgCyan",
95
+ White = "bgWhite",
96
+ BlackBright = "bgBlackBright",
97
+ RedBright = "bgRedBright",
98
+ GreenBright = "bgGreenBright",
99
+ YellowBright = "bgYellowBright",
100
+ BlueBright = "bgBlueBright",
101
+ MagentaBright = "bgMagentaBright",
102
+ CyanBright = "bgCyanBright",
103
+ WhiteBright = "bgWhiteBright"
104
+ }
105
+
106
+ /**
107
+ * Logger utility that formats a timestamp.
108
+ * @since 1.0.0
109
+ */
110
+ declare class LoggerTimestamp {
111
+ /**
112
+ * The timestamp used to format the current date.
113
+ * @since 1.0.0
114
+ */
115
+ timestamp: Timestamp;
116
+ /**
117
+ * Whether or not the logger will show a timestamp in UTC.
118
+ * @since 1.0.0
119
+ */
120
+ utc: boolean;
121
+ /**
122
+ * The logger style to apply the color to the timestamp.
123
+ * @since 1.0.0
124
+ */
125
+ color: LoggerStyle | null;
126
+ /**
127
+ * The final formatter.
128
+ * @since 1.0.0
129
+ */
130
+ formatter: LoggerTimestampFormatter;
131
+ constructor(options?: LoggerTimestampOptions);
132
+ /**
133
+ * Formats the current time.
134
+ * @since 1.0.0
135
+ */
136
+ run(): string;
137
+ }
138
+ /**
139
+ * The options for {@link LoggerTimestamp}.
140
+ * @since 1.0.0
141
+ */
142
+ interface LoggerTimestampOptions {
143
+ /**
144
+ * The {@link Timestamp} pattern.
145
+ * @since 1.0.0
146
+ * @default 'YYYY-MM-DD HH:mm:ss'
147
+ * @example
148
+ * ```typescript
149
+ * 'YYYY-MM-DD HH:mm:ss'
150
+ * // 2020-12-23 22:01:10
151
+ * ```
152
+ */
153
+ pattern?: string;
154
+ /**
155
+ * Whether or not the date should be UTC.
156
+ * @since 1.0.0
157
+ * @default false
158
+ */
159
+ utc?: boolean;
160
+ /**
161
+ * The color to use.
162
+ * @since 1.0.0
163
+ * @default colorette.reset
164
+ */
165
+ color?: LoggerStyleResolvable | null;
166
+ /**
167
+ * The formatter. See {@link LoggerTimestampFormatter} for more information.
168
+ * @since 1.0.0
169
+ * @default (value) => `${value} - `
170
+ */
171
+ formatter?: LoggerTimestampFormatter;
172
+ }
173
+ /**
174
+ * The formatter used for {@link LoggerTimestampOptions}. This will be run **after** applying the color to the formatter.
175
+ * @since 1.0.0
176
+ */
177
+ interface LoggerTimestampFormatter {
178
+ /**
179
+ * @param timestamp The output of {@link LoggerStyle.run} on {@link Timestamp.display}/{@link Timestamp.displayUTC}.
180
+ * @since 1.0.0
181
+ */
182
+ (timestamp: string): string;
183
+ }
184
+
185
+ /**
186
+ * Logger utility that stores and applies a full style into the message.
187
+ * @since 1.0.0
188
+ */
189
+ declare class LoggerLevel {
190
+ /**
191
+ * The timestamp formatter.
192
+ * @since 1.0.0
193
+ */
194
+ timestamp: LoggerTimestamp | null;
195
+ /**
196
+ * The infix, added between the timestamp and the message.
197
+ * @since 1.0.0
198
+ */
199
+ infix: string;
200
+ /**
201
+ * The style formatter for the message.
202
+ * @since 1.0.0
203
+ */
204
+ message: LoggerStyle | null;
205
+ constructor(options?: LoggerLevelOptions);
206
+ run(content: string): string;
207
+ }
208
+ /**
209
+ * The options for {@link LoggerLevel}.
210
+ * @since 1.0.0
211
+ */
212
+ interface LoggerLevelOptions {
213
+ /**
214
+ * The timestamp options. Set to `null` to disable timestamp parsing.
215
+ * @since 1.0.0
216
+ * @default {}
217
+ */
218
+ timestamp?: LoggerTimestampOptions | null;
219
+ /**
220
+ * The infix to be included between the timestamp and the message.
221
+ * @since 1.0.0
222
+ * @default ''
223
+ */
224
+ infix?: string;
225
+ /**
226
+ * The style options for the message.
227
+ * @since 1.0.0
228
+ * @default colorette.clear
229
+ */
230
+ message?: LoggerStyleResolvable | null;
231
+ }
232
+
233
+ /**
234
+ * The logger class.
235
+ * @since 1.0.0
236
+ */
237
+ declare class Logger extends Logger$1 {
238
+ /**
239
+ * The console this writes to.
240
+ * @since 1.0.0
241
+ */
242
+ readonly console: Console;
243
+ /**
244
+ * The formats supported by the logger.
245
+ * @since 1.0.0
246
+ */
247
+ readonly formats: Map<LogLevel, LoggerLevel>;
248
+ /**
249
+ * The string `write` will join values by.
250
+ * @since 1.0.0
251
+ */
252
+ readonly join: string;
253
+ /**
254
+ * The inspect depth when logging objects.
255
+ * @since 1.0.0
256
+ */
257
+ readonly depth: number;
258
+ constructor(options?: LoggerOptions);
259
+ /**
260
+ * Writes the log message given a level and the value(s).
261
+ * @param level The log level.
262
+ * @param values The values to log.
263
+ */
264
+ write(level: LogLevel, ...values: readonly unknown[]): void;
265
+ /**
266
+ * Pre-processes an array of values.
267
+ * @since 1.0.0
268
+ * @param values The values to pre-process.
269
+ */
270
+ protected preprocess(values: readonly unknown[]): string;
271
+ private get levels();
272
+ /**
273
+ * Gets whether or not colorette is enabled.
274
+ * @since 1.0.0
275
+ */
276
+ static get stylize(): boolean;
277
+ private static createFormatMap;
278
+ private static ensureDefaultLevel;
279
+ }
280
+ /**
281
+ * The logger options.
282
+ * @since 1.0.0
283
+ */
284
+ interface LoggerOptions {
285
+ /**
286
+ * A writable stream for the output logs.
287
+ * @since 1.0.0
288
+ * @default process.stdout
289
+ */
290
+ stdout?: NodeJS.WritableStream;
291
+ /**
292
+ * A writable stream for the error logs.
293
+ * @since 1.0.0
294
+ * @default process.stderr
295
+ */
296
+ stderr?: NodeJS.WritableStream;
297
+ /**
298
+ * The default options used to fill all the possible values for {@link LoggerOptions.format}.
299
+ * @since 1.0.0
300
+ * @default options.format.none ?? {}
301
+ */
302
+ defaultFormat?: LoggerLevelOptions;
303
+ /**
304
+ * The options for each log level. LogLevel.None serves to set the default for all keys, where only
305
+ * {@link LoggerTimestampOptions.timestamp} and {@link LoggerLevelOptions.prefix} would be overridden.
306
+ * @since 1.0.0
307
+ * @default {}
308
+ */
309
+ format?: LoggerFormatOptions;
310
+ /**
311
+ * The minimum log level.
312
+ * @since 1.0.0
313
+ * @default LogLevel.Info
314
+ */
315
+ level?: LogLevel;
316
+ /**
317
+ * The string that joins different messages.
318
+ * @since 1.0.0
319
+ * @default ' '
320
+ */
321
+ join?: string;
322
+ /**
323
+ * The inspect depth when logging objects.
324
+ * @since 1.0.0
325
+ * @default 0
326
+ */
327
+ depth?: number;
328
+ }
329
+ /**
330
+ * The logger format options.
331
+ * @since 1.0.0
332
+ */
333
+ interface LoggerFormatOptions {
334
+ /**
335
+ * The logger options for the lowest log level, used when calling {@link ILogger.trace}.
336
+ * @since 1.0.0
337
+ */
338
+ trace?: LoggerLevelOptions;
339
+ /**
340
+ * The logger options for the debug level, used when calling {@link ILogger.debug}.
341
+ * @since 1.0.0
342
+ */
343
+ debug?: LoggerLevelOptions;
344
+ /**
345
+ * The logger options for the info level, used when calling {@link ILogger.info}.
346
+ * @since 1.0.0
347
+ */
348
+ info?: LoggerLevelOptions;
349
+ /**
350
+ * The logger options for the warning level, used when calling {@link ILogger.warn}.
351
+ * @since 1.0.0
352
+ */
353
+ warn?: LoggerLevelOptions;
354
+ /**
355
+ * The logger options for the error level, used when calling {@link ILogger.error}.
356
+ * @since 1.0.0
357
+ */
358
+ error?: LoggerLevelOptions;
359
+ /**
360
+ * The logger options for the critical level, used when calling {@link ILogger.fatal}.
361
+ * @since 1.0.0
362
+ */
363
+ fatal?: LoggerLevelOptions;
364
+ /**
365
+ * The logger options for an unknown or uncategorised level.
366
+ * @since 1.0.0
367
+ */
368
+ none?: LoggerLevelOptions;
369
+ }
370
+
371
+ declare module '@sapphire/framework' {
372
+ interface ClientLoggerOptions extends LoggerOptions {
373
+ }
374
+ }
375
+ /**
376
+ * The [@sapphire/plugin-logger](https://github.com/sapphiredev/plugins/blob/main/packages/logger) version that you are currently using.
377
+ * An example use of this is showing it of in a bot information command.
378
+ *
379
+ * Note to Sapphire developers: This needs to explicitly be `string` so it is not typed as the string that gets replaced by esbuild
380
+ */
381
+ declare const version: string;
382
+
383
+ export { Logger, type LoggerFormatOptions, LoggerLevel, type LoggerLevelOptions, type LoggerOptions, LoggerStyle, LoggerStyleBackground, LoggerStyleEffect, type LoggerStyleOptions, type LoggerStyleResolvable, LoggerStyleText, LoggerTimestamp, type LoggerTimestampFormatter, type LoggerTimestampOptions, version };
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ var framework = require('@sapphire/framework');
4
+ var colorette = require('colorette');
5
+ var console = require('console');
6
+ var util = require('util');
7
+ var LoggerLevel_cjs = require('./LoggerLevel.cjs');
8
+
9
+ var __defProp = Object.defineProperty;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __publicField = (obj, key, value) => {
13
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
14
+ return value;
15
+ };
16
+ var _Logger = class _Logger extends framework.Logger {
17
+ constructor(options = {}) {
18
+ super(options.level ?? framework.LogLevel.Info);
19
+ /**
20
+ * The console this writes to.
21
+ * @since 1.0.0
22
+ */
23
+ __publicField(this, "console");
24
+ /**
25
+ * The formats supported by the logger.
26
+ * @since 1.0.0
27
+ */
28
+ __publicField(this, "formats");
29
+ /**
30
+ * The string `write` will join values by.
31
+ * @since 1.0.0
32
+ */
33
+ __publicField(this, "join");
34
+ /**
35
+ * The inspect depth when logging objects.
36
+ * @since 1.0.0
37
+ */
38
+ __publicField(this, "depth");
39
+ this.console = new console.Console(options.stdout ?? process.stdout, options.stderr ?? process.stderr);
40
+ this.formats = _Logger.createFormatMap(options.format, options.defaultFormat);
41
+ this.join = options.join ?? " ";
42
+ this.depth = options.depth ?? 0;
43
+ }
44
+ /**
45
+ * Writes the log message given a level and the value(s).
46
+ * @param level The log level.
47
+ * @param values The values to log.
48
+ */
49
+ write(level, ...values) {
50
+ if (level < this.level)
51
+ return;
52
+ const method = this.levels.get(level) ?? "log";
53
+ const formatter = this.formats.get(level) ?? this.formats.get(framework.LogLevel.None);
54
+ this.console[method](formatter.run(this.preprocess(values)));
55
+ }
56
+ /**
57
+ * Pre-processes an array of values.
58
+ * @since 1.0.0
59
+ * @param values The values to pre-process.
60
+ */
61
+ preprocess(values) {
62
+ const inspectOptions = { colors: colorette.isColorSupported, depth: this.depth };
63
+ return values.map((value) => typeof value === "string" ? value : util.inspect(value, inspectOptions)).join(this.join);
64
+ }
65
+ get levels() {
66
+ return Reflect.get(framework.Logger, "levels");
67
+ }
68
+ /**
69
+ * Gets whether or not colorette is enabled.
70
+ * @since 1.0.0
71
+ */
72
+ static get stylize() {
73
+ return colorette.isColorSupported;
74
+ }
75
+ static createFormatMap(options = {}, defaults = options.none ?? {}) {
76
+ return /* @__PURE__ */ new Map([
77
+ [framework.LogLevel.Trace, _Logger.ensureDefaultLevel(options.trace, defaults, colorette.gray, "TRACE")],
78
+ [framework.LogLevel.Debug, _Logger.ensureDefaultLevel(options.debug, defaults, colorette.magenta, "DEBUG")],
79
+ [framework.LogLevel.Info, _Logger.ensureDefaultLevel(options.info, defaults, colorette.cyan, "INFO")],
80
+ [framework.LogLevel.Warn, _Logger.ensureDefaultLevel(options.warn, defaults, colorette.yellow, "WARN")],
81
+ [framework.LogLevel.Error, _Logger.ensureDefaultLevel(options.error, defaults, colorette.red, "ERROR")],
82
+ [framework.LogLevel.Fatal, _Logger.ensureDefaultLevel(options.fatal, defaults, colorette.bgRed, "FATAL")],
83
+ [framework.LogLevel.None, _Logger.ensureDefaultLevel(options.none, defaults, colorette.white, "")]
84
+ ]);
85
+ }
86
+ static ensureDefaultLevel(options, defaults, color, name) {
87
+ if (options)
88
+ return new LoggerLevel_cjs.LoggerLevel(options);
89
+ return new LoggerLevel_cjs.LoggerLevel({
90
+ ...defaults,
91
+ timestamp: defaults.timestamp === null ? null : { ...defaults.timestamp ?? {}, color },
92
+ infix: name.length ? `${color(name.padEnd(5, " "))} - ` : ""
93
+ });
94
+ }
95
+ };
96
+ __name(_Logger, "Logger");
97
+ var Logger = _Logger;
98
+
99
+ exports.Logger = Logger;
100
+ //# sourceMappingURL=out.js.map
101
+ //# sourceMappingURL=Logger.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/lib/Logger.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,UAAU,eAAe,gBAAiC;AACnE,SAAS,OAAO,MAAM,MAAM,kBAAkB,SAAS,KAAK,OAAO,cAA0B;AAC7F,SAAS,eAAe;AACxB,SAAS,eAAoC;AAC7C,SAAS,mBAA4C;AAM9C,IAAM,UAAN,MAAM,gBAAe,cAAc;AAAA,EAyBlC,YAAY,UAAyB,CAAC,GAAG;AAC/C,UAAM,QAAQ,SAAS,SAAS,IAAI;AArBrC;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAMhB;AAAA;AAAA;AAAA;AAAA,wBAAgB;AAKf,SAAK,UAAU,IAAI,QAAQ,QAAQ,UAAU,QAAQ,QAAQ,QAAQ,UAAU,QAAQ,MAAM;AAC7F,SAAK,UAAU,QAAO,gBAAgB,QAAQ,QAAQ,QAAQ,aAAa;AAC3E,SAAK,OAAO,QAAQ,QAAQ;AAC5B,SAAK,QAAQ,QAAQ,SAAS;AAAA,EAC/B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOgB,MAAM,UAAoB,QAAkC;AAC3E,QAAI,QAAQ,KAAK;AAAO;AAExB,UAAM,SAAS,KAAK,OAAO,IAAI,KAAK,KAAK;AACzC,UAAM,YAAY,KAAK,QAAQ,IAAI,KAAK,KAAK,KAAK,QAAQ,IAAI,SAAS,IAAI;AAE3E,SAAK,QAAQ,MAAM,EAAE,UAAU,IAAI,KAAK,WAAW,MAAM,CAAC,CAAC;AAAA,EAC5D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOU,WAAW,QAA4B;AAChD,UAAM,iBAAiC,EAAE,QAAQ,kBAAkB,OAAO,KAAK,MAAM;AACrF,WAAO,OAAO,IAAI,CAAC,UAAW,OAAO,UAAU,WAAW,QAAQ,QAAQ,OAAO,cAAc,CAAE,EAAE,KAAK,KAAK,IAAI;AAAA,EAClH;AAAA,EAEA,IAAY,SAAS;AACpB,WAAO,QAAQ,IAAI,eAAe,QAAQ;AAAA,EAC3C;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,WAAkB,UAAU;AAC3B,WAAO;AAAA,EACR;AAAA,EAEA,OAAe,gBAAgB,UAA+B,CAAC,GAAG,WAA+B,QAAQ,QAAQ,CAAC,GAAG;AACpH,WAAO,oBAAI,IAA2B;AAAA,MACrC,CAAC,SAAS,OAAO,QAAO,mBAAmB,QAAQ,OAAO,UAAU,MAAM,OAAO,CAAC;AAAA,MAClF,CAAC,SAAS,OAAO,QAAO,mBAAmB,QAAQ,OAAO,UAAU,SAAS,OAAO,CAAC;AAAA,MACrF,CAAC,SAAS,MAAM,QAAO,mBAAmB,QAAQ,MAAM,UAAU,MAAM,MAAM,CAAC;AAAA,MAC/E,CAAC,SAAS,MAAM,QAAO,mBAAmB,QAAQ,MAAM,UAAU,QAAQ,MAAM,CAAC;AAAA,MACjF,CAAC,SAAS,OAAO,QAAO,mBAAmB,QAAQ,OAAO,UAAU,KAAK,OAAO,CAAC;AAAA,MACjF,CAAC,SAAS,OAAO,QAAO,mBAAmB,QAAQ,OAAO,UAAU,OAAO,OAAO,CAAC;AAAA,MACnF,CAAC,SAAS,MAAM,QAAO,mBAAmB,QAAQ,MAAM,UAAU,OAAO,EAAE,CAAC;AAAA,IAC7E,CAAC;AAAA,EACF;AAAA,EAEA,OAAe,mBAAmB,SAAyC,UAA8B,OAAc,MAAc;AACpI,QAAI;AAAS,aAAO,IAAI,YAAY,OAAO;AAC3C,WAAO,IAAI,YAAY;AAAA,MACtB,GAAG;AAAA,MACH,WAAW,SAAS,cAAc,OAAO,OAAO,EAAE,GAAI,SAAS,aAAa,CAAC,GAAI,MAAM;AAAA,MACvF,OAAO,KAAK,SAAS,GAAG,MAAM,KAAK,OAAO,GAAG,GAAG,CAAC,CAAC,QAAQ;AAAA,IAC3D,CAAC;AAAA,EACF;AACD;AA1F0C;AAAnC,IAAM,SAAN","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,48 @@
1
+ 'use strict';
2
+
3
+ var LoggerStyle_cjs = require('./LoggerStyle.cjs');
4
+ var LoggerTimestamp_cjs = require('./LoggerTimestamp.cjs');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __publicField = (obj, key, value) => {
10
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
11
+ return value;
12
+ };
13
+ var _LoggerLevel = class _LoggerLevel {
14
+ constructor(options = {}) {
15
+ /**
16
+ * The timestamp formatter.
17
+ * @since 1.0.0
18
+ */
19
+ __publicField(this, "timestamp");
20
+ /**
21
+ * The infix, added between the timestamp and the message.
22
+ * @since 1.0.0
23
+ */
24
+ __publicField(this, "infix");
25
+ /**
26
+ * The style formatter for the message.
27
+ * @since 1.0.0
28
+ */
29
+ __publicField(this, "message");
30
+ this.timestamp = options.timestamp === null ? null : new LoggerTimestamp_cjs.LoggerTimestamp(options.timestamp);
31
+ this.infix = options.infix ?? "";
32
+ this.message = options.message === null ? null : new LoggerStyle_cjs.LoggerStyle(options.message);
33
+ }
34
+ run(content) {
35
+ const prefix = (this.timestamp?.run() ?? "") + this.infix;
36
+ if (prefix.length) {
37
+ const formatter = this.message ? (line) => prefix + this.message.run(line) : (line) => prefix + line;
38
+ return content.split("\n").map(formatter).join("\n");
39
+ }
40
+ return this.message ? this.message.run(content) : content;
41
+ }
42
+ };
43
+ __name(_LoggerLevel, "LoggerLevel");
44
+ var LoggerLevel = _LoggerLevel;
45
+
46
+ exports.LoggerLevel = LoggerLevel;
47
+ //# sourceMappingURL=out.js.map
48
+ //# sourceMappingURL=LoggerLevel.cjs.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"]}