@logtape/logtape 0.11.0 → 0.12.0-dev.181

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 (171) hide show
  1. package/config.test.ts +591 -0
  2. package/config.ts +421 -0
  3. package/context.test.ts +187 -0
  4. package/context.ts +55 -0
  5. package/deno.json +36 -0
  6. package/dist/_virtual/rolldown_runtime.cjs +30 -0
  7. package/dist/config.cjs +247 -0
  8. package/dist/config.d.cts +189 -0
  9. package/dist/config.d.cts.map +1 -0
  10. package/dist/config.d.ts +189 -0
  11. package/dist/config.d.ts.map +1 -0
  12. package/dist/config.js +241 -0
  13. package/dist/config.js.map +1 -0
  14. package/dist/context.cjs +30 -0
  15. package/dist/context.d.cts +39 -0
  16. package/dist/context.d.cts.map +1 -0
  17. package/dist/context.d.ts +39 -0
  18. package/dist/context.d.ts.map +1 -0
  19. package/dist/context.js +31 -0
  20. package/dist/context.js.map +1 -0
  21. package/dist/filter.cjs +32 -0
  22. package/dist/filter.d.cts +37 -0
  23. package/dist/filter.d.cts.map +1 -0
  24. package/{types → dist}/filter.d.ts +12 -6
  25. package/dist/filter.d.ts.map +1 -0
  26. package/dist/filter.js +31 -0
  27. package/dist/filter.js.map +1 -0
  28. package/dist/formatter.cjs +281 -0
  29. package/dist/formatter.d.cts +338 -0
  30. package/dist/formatter.d.cts.map +1 -0
  31. package/dist/formatter.d.ts +338 -0
  32. package/dist/formatter.d.ts.map +1 -0
  33. package/dist/formatter.js +275 -0
  34. package/dist/formatter.js.map +1 -0
  35. package/dist/level.cjs +64 -0
  36. package/dist/level.d.cts +34 -0
  37. package/dist/level.d.cts.map +1 -0
  38. package/{types → dist}/level.d.ts +7 -5
  39. package/dist/level.d.ts.map +1 -0
  40. package/dist/level.js +62 -0
  41. package/dist/level.js.map +1 -0
  42. package/dist/logger.cjs +351 -0
  43. package/dist/logger.d.cts +501 -0
  44. package/dist/logger.d.cts.map +1 -0
  45. package/dist/logger.d.ts +501 -0
  46. package/dist/logger.d.ts.map +1 -0
  47. package/dist/logger.js +351 -0
  48. package/dist/logger.js.map +1 -0
  49. package/dist/mod.cjs +33 -0
  50. package/dist/mod.d.cts +9 -0
  51. package/dist/mod.d.ts +9 -0
  52. package/dist/mod.js +9 -0
  53. package/dist/record.d.cts +50 -0
  54. package/dist/record.d.cts.map +1 -0
  55. package/dist/record.d.ts +50 -0
  56. package/dist/record.d.ts.map +1 -0
  57. package/dist/sink.cjs +95 -0
  58. package/dist/sink.d.cts +112 -0
  59. package/dist/sink.d.cts.map +1 -0
  60. package/{types → dist}/sink.d.ts +49 -45
  61. package/dist/sink.d.ts.map +1 -0
  62. package/dist/sink.js +94 -0
  63. package/dist/sink.js.map +1 -0
  64. package/dist/util.cjs +9 -0
  65. package/dist/util.d.cts +12 -0
  66. package/dist/util.d.cts.map +1 -0
  67. package/dist/util.d.ts +12 -0
  68. package/dist/util.d.ts.map +1 -0
  69. package/dist/util.deno.cjs +16 -0
  70. package/dist/util.deno.d.cts +12 -0
  71. package/dist/util.deno.d.cts.map +1 -0
  72. package/dist/util.deno.d.ts +12 -0
  73. package/dist/util.deno.d.ts.map +1 -0
  74. package/dist/util.deno.js +16 -0
  75. package/dist/util.deno.js.map +1 -0
  76. package/dist/util.js +9 -0
  77. package/dist/util.js.map +1 -0
  78. package/dist/util.node.cjs +10 -0
  79. package/dist/util.node.d.cts +12 -0
  80. package/dist/util.node.d.cts.map +1 -0
  81. package/dist/util.node.d.ts +12 -0
  82. package/dist/util.node.d.ts.map +1 -0
  83. package/dist/util.node.js +10 -0
  84. package/dist/util.node.js.map +1 -0
  85. package/filter.test.ts +70 -0
  86. package/filter.ts +57 -0
  87. package/fixtures.ts +30 -0
  88. package/formatter.test.ts +530 -0
  89. package/formatter.ts +724 -0
  90. package/level.test.ts +47 -0
  91. package/level.ts +67 -0
  92. package/logger.test.ts +823 -0
  93. package/logger.ts +1124 -0
  94. package/mod.ts +54 -0
  95. package/package.json +35 -23
  96. package/record.ts +49 -0
  97. package/sink.test.ts +219 -0
  98. package/sink.ts +167 -0
  99. package/tsdown.config.ts +24 -0
  100. package/util.deno.ts +19 -0
  101. package/util.node.ts +12 -0
  102. package/util.ts +11 -0
  103. package/esm/_dnt.shims.js +0 -57
  104. package/esm/config.js +0 -297
  105. package/esm/context.js +0 -23
  106. package/esm/filter.js +0 -42
  107. package/esm/formatter.js +0 -370
  108. package/esm/level.js +0 -59
  109. package/esm/logger.js +0 -517
  110. package/esm/mod.js +0 -8
  111. package/esm/nodeUtil.cjs +0 -20
  112. package/esm/nodeUtil.js +0 -2
  113. package/esm/package.json +0 -3
  114. package/esm/record.js +0 -1
  115. package/esm/sink.js +0 -96
  116. package/script/_dnt.shims.js +0 -60
  117. package/script/config.js +0 -331
  118. package/script/context.js +0 -26
  119. package/script/filter.js +0 -46
  120. package/script/formatter.js +0 -380
  121. package/script/level.js +0 -64
  122. package/script/logger.js +0 -548
  123. package/script/mod.js +0 -36
  124. package/script/nodeUtil.js +0 -20
  125. package/script/package.json +0 -3
  126. package/script/record.js +0 -2
  127. package/script/sink.js +0 -101
  128. package/types/_dnt.shims.d.ts +0 -2
  129. package/types/_dnt.shims.d.ts.map +0 -1
  130. package/types/_dnt.test_shims.d.ts.map +0 -1
  131. package/types/config.d.ts +0 -183
  132. package/types/config.d.ts.map +0 -1
  133. package/types/config.test.d.ts.map +0 -1
  134. package/types/context.d.ts +0 -35
  135. package/types/context.d.ts.map +0 -1
  136. package/types/context.test.d.ts.map +0 -1
  137. package/types/deps/jsr.io/@std/assert/0.222.1/_constants.d.ts.map +0 -1
  138. package/types/deps/jsr.io/@std/assert/0.222.1/_diff.d.ts.map +0 -1
  139. package/types/deps/jsr.io/@std/assert/0.222.1/_format.d.ts.map +0 -1
  140. package/types/deps/jsr.io/@std/assert/0.222.1/assert.d.ts.map +0 -1
  141. package/types/deps/jsr.io/@std/assert/0.222.1/assert_equals.d.ts.map +0 -1
  142. package/types/deps/jsr.io/@std/assert/0.222.1/assert_false.d.ts.map +0 -1
  143. package/types/deps/jsr.io/@std/assert/0.222.1/assert_greater_or_equal.d.ts.map +0 -1
  144. package/types/deps/jsr.io/@std/assert/0.222.1/assert_is_error.d.ts.map +0 -1
  145. package/types/deps/jsr.io/@std/assert/0.222.1/assert_less_or_equal.d.ts.map +0 -1
  146. package/types/deps/jsr.io/@std/assert/0.222.1/assert_rejects.d.ts.map +0 -1
  147. package/types/deps/jsr.io/@std/assert/0.222.1/assert_strict_equals.d.ts.map +0 -1
  148. package/types/deps/jsr.io/@std/assert/0.222.1/assert_throws.d.ts.map +0 -1
  149. package/types/deps/jsr.io/@std/assert/0.222.1/assertion_error.d.ts.map +0 -1
  150. package/types/deps/jsr.io/@std/assert/0.222.1/equal.d.ts.map +0 -1
  151. package/types/deps/jsr.io/@std/async/0.222.1/delay.d.ts.map +0 -1
  152. package/types/deps/jsr.io/@std/fmt/0.222.1/colors.d.ts.map +0 -1
  153. package/types/filter.d.ts.map +0 -1
  154. package/types/filter.test.d.ts.map +0 -1
  155. package/types/fixtures.d.ts.map +0 -1
  156. package/types/formatter.d.ts +0 -332
  157. package/types/formatter.d.ts.map +0 -1
  158. package/types/formatter.test.d.ts.map +0 -1
  159. package/types/level.d.ts.map +0 -1
  160. package/types/level.test.d.ts.map +0 -1
  161. package/types/logger.d.ts +0 -573
  162. package/types/logger.d.ts.map +0 -1
  163. package/types/logger.test.d.ts.map +0 -1
  164. package/types/mod.d.ts +0 -9
  165. package/types/mod.d.ts.map +0 -1
  166. package/types/nodeUtil.d.ts +0 -12
  167. package/types/nodeUtil.d.ts.map +0 -1
  168. package/types/record.d.ts +0 -44
  169. package/types/record.d.ts.map +0 -1
  170. package/types/sink.d.ts.map +0 -1
  171. package/types/sink.test.d.ts.map +0 -1
@@ -1,380 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.jsonLinesFormatter = exports.ansiColorFormatter = exports.defaultTextFormatter = void 0;
7
- exports.getTextFormatter = getTextFormatter;
8
- exports.getAnsiColorFormatter = getAnsiColorFormatter;
9
- exports.getJsonLinesFormatter = getJsonLinesFormatter;
10
- exports.defaultConsoleFormatter = defaultConsoleFormatter;
11
- const nodeUtil_js_1 = __importDefault(require("./nodeUtil.js"));
12
- /**
13
- * The severity level abbreviations.
14
- */
15
- const levelAbbreviations = {
16
- "debug": "DBG",
17
- "info": "INF",
18
- "warning": "WRN",
19
- "error": "ERR",
20
- "fatal": "FTL",
21
- };
22
- /**
23
- * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
24
- * and in Node.js/Bun it is `util.inspect()`. If neither is available, it
25
- * falls back to {@link JSON.stringify}.
26
- *
27
- * @param value The value to inspect.
28
- * @param options The options for inspecting the value.
29
- * If `colors` is `true`, the output will be ANSI-colored.
30
- * @returns The string representation of the value.
31
- */
32
- const inspect =
33
- // @ts-ignore: Browser detection
34
- // dnt-shim-ignore
35
- typeof document !== "undefined" ||
36
- // @ts-ignore: React Native detection
37
- // dnt-shim-ignore
38
- typeof navigator !== "undefined" && navigator.product === "ReactNative"
39
- ? (v) => JSON.stringify(v)
40
- // @ts-ignore: Deno global
41
- // dnt-shim-ignore
42
- : "Deno" in globalThis && "inspect" in globalThis.Deno &&
43
- // @ts-ignore: Deno global
44
- // dnt-shim-ignore
45
- typeof globalThis.Deno.inspect === "function"
46
- ? (v, opts) =>
47
- // @ts-ignore: Deno global
48
- // dnt-shim-ignore
49
- globalThis.Deno.inspect(v, {
50
- strAbbreviateSize: Infinity,
51
- iterableLimit: Infinity,
52
- ...opts,
53
- })
54
- // @ts-ignore: Node.js global
55
- // dnt-shim-ignore
56
- : nodeUtil_js_1.default != null && "inspect" in nodeUtil_js_1.default && typeof nodeUtil_js_1.default.inspect === "function"
57
- ? (v, opts) =>
58
- // @ts-ignore: Node.js global
59
- // dnt-shim-ignore
60
- nodeUtil_js_1.default.inspect(v, {
61
- maxArrayLength: Infinity,
62
- maxStringLength: Infinity,
63
- ...opts,
64
- })
65
- : (v) => JSON.stringify(v);
66
- /**
67
- * Get a text formatter with the specified options. Although it's flexible
68
- * enough to create a custom formatter, if you want more control, you can
69
- * create a custom formatter that satisfies the {@link TextFormatter} type
70
- * instead.
71
- *
72
- * For more information on the options, see {@link TextFormatterOptions}.
73
- *
74
- * By default, the formatter formats log records as follows:
75
- *
76
- * ```
77
- * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
78
- * ```
79
- * @param options The options for the text formatter.
80
- * @returns The text formatter.
81
- * @since 0.6.0
82
- */
83
- function getTextFormatter(options = {}) {
84
- const timestampRenderer = options.timestamp == null || options.timestamp === "date-time-timezone"
85
- ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00:00")
86
- : options.timestamp === "date-time-tz"
87
- ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00")
88
- : options.timestamp === "date-time"
89
- ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", "")
90
- : options.timestamp === "time-timezone"
91
- ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00:00")
92
- : options.timestamp === "time-tz"
93
- ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00")
94
- : options.timestamp === "time"
95
- ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", "")
96
- : options.timestamp === "date"
97
- ? (ts) => new Date(ts).toISOString().replace(/T.*/, "")
98
- : options.timestamp === "rfc3339"
99
- ? (ts) => new Date(ts).toISOString()
100
- : options.timestamp === "none" || options.timestamp === "disabled"
101
- ? () => null
102
- : options.timestamp;
103
- const categorySeparator = options.category ?? "·";
104
- const valueRenderer = options.value ?? inspect;
105
- const levelRenderer = options.level == null || options.level === "ABBR"
106
- ? (level) => levelAbbreviations[level]
107
- : options.level === "abbr"
108
- ? (level) => levelAbbreviations[level].toLowerCase()
109
- : options.level === "FULL"
110
- ? (level) => level.toUpperCase()
111
- : options.level === "full"
112
- ? (level) => level
113
- : options.level === "L"
114
- ? (level) => level.charAt(0).toUpperCase()
115
- : options.level === "l"
116
- ? (level) => level.charAt(0)
117
- : options.level;
118
- const formatter = options.format ??
119
- (({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
120
- return (record) => {
121
- let message = "";
122
- for (let i = 0; i < record.message.length; i++) {
123
- if (i % 2 === 0)
124
- message += record.message[i];
125
- else
126
- message += valueRenderer(record.message[i]);
127
- }
128
- const timestamp = timestampRenderer(record.timestamp);
129
- const level = levelRenderer(record.level);
130
- const category = typeof categorySeparator === "function"
131
- ? categorySeparator(record.category)
132
- : record.category.join(categorySeparator);
133
- const values = {
134
- timestamp,
135
- level,
136
- category,
137
- message,
138
- record,
139
- };
140
- return `${formatter(values)}\n`;
141
- };
142
- }
143
- /**
144
- * The default text formatter. This formatter formats log records as follows:
145
- *
146
- * ```
147
- * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
148
- * ```
149
- *
150
- * @param record The log record to format.
151
- * @returns The formatted log record.
152
- */
153
- exports.defaultTextFormatter = getTextFormatter();
154
- const RESET = "\x1b[0m";
155
- const ansiColors = {
156
- black: "\x1b[30m",
157
- red: "\x1b[31m",
158
- green: "\x1b[32m",
159
- yellow: "\x1b[33m",
160
- blue: "\x1b[34m",
161
- magenta: "\x1b[35m",
162
- cyan: "\x1b[36m",
163
- white: "\x1b[37m",
164
- };
165
- const ansiStyles = {
166
- bold: "\x1b[1m",
167
- dim: "\x1b[2m",
168
- italic: "\x1b[3m",
169
- underline: "\x1b[4m",
170
- strikethrough: "\x1b[9m",
171
- };
172
- const defaultLevelColors = {
173
- debug: "blue",
174
- info: "green",
175
- warning: "yellow",
176
- error: "red",
177
- fatal: "magenta",
178
- };
179
- /**
180
- * Get an ANSI color formatter with the specified options.
181
- *
182
- * ![A preview of an ANSI color formatter.](https://i.imgur.com/I8LlBUf.png)
183
- * @param option The options for the ANSI color formatter.
184
- * @returns The ANSI color formatter.
185
- * @since 0.6.0
186
- */
187
- function getAnsiColorFormatter(options = {}) {
188
- const format = options.format;
189
- const timestampStyle = typeof options.timestampStyle === "undefined"
190
- ? "dim"
191
- : options.timestampStyle;
192
- const timestampColor = options.timestampColor ?? null;
193
- const timestampPrefix = `${timestampStyle == null ? "" : ansiStyles[timestampStyle]}${timestampColor == null ? "" : ansiColors[timestampColor]}`;
194
- const timestampSuffix = timestampStyle == null && timestampColor == null
195
- ? ""
196
- : RESET;
197
- const levelStyle = typeof options.levelStyle === "undefined"
198
- ? "bold"
199
- : options.levelStyle;
200
- const levelColors = options.levelColors ?? defaultLevelColors;
201
- const categoryStyle = typeof options.categoryStyle === "undefined"
202
- ? "dim"
203
- : options.categoryStyle;
204
- const categoryColor = options.categoryColor ?? null;
205
- const categoryPrefix = `${categoryStyle == null ? "" : ansiStyles[categoryStyle]}${categoryColor == null ? "" : ansiColors[categoryColor]}`;
206
- const categorySuffix = categoryStyle == null && categoryColor == null
207
- ? ""
208
- : RESET;
209
- return getTextFormatter({
210
- timestamp: "date-time-tz",
211
- value(value) {
212
- return inspect(value, { colors: true });
213
- },
214
- ...options,
215
- format({ timestamp, level, category, message, record }) {
216
- const levelColor = levelColors[record.level];
217
- timestamp = `${timestampPrefix}${timestamp}${timestampSuffix}`;
218
- level = `${levelStyle == null ? "" : ansiStyles[levelStyle]}${levelColor == null ? "" : ansiColors[levelColor]}${level}${levelStyle == null && levelColor == null ? "" : RESET}`;
219
- return format == null
220
- ? `${timestamp} ${level} ${categoryPrefix}${category}:${categorySuffix} ${message}`
221
- : format({
222
- timestamp,
223
- level,
224
- category: `${categoryPrefix}${category}${categorySuffix}`,
225
- message,
226
- record,
227
- });
228
- },
229
- });
230
- }
231
- /**
232
- * A text formatter that uses ANSI colors to format log records.
233
- *
234
- * ![A preview of ansiColorFormatter.](https://i.imgur.com/I8LlBUf.png)
235
- *
236
- * @param record The log record to format.
237
- * @returns The formatted log record.
238
- * @since 0.5.0
239
- */
240
- exports.ansiColorFormatter = getAnsiColorFormatter();
241
- /**
242
- * Get a [JSON Lines] formatter with the specified options. The log records
243
- * will be rendered as JSON objects, one per line, which is a common format
244
- * for log files. This format is also known as Newline-Delimited JSON (NDJSON).
245
- * It looks like this:
246
- *
247
- * ```json
248
- * {"@timestamp":"2023-11-14T22:13:20.000Z","level":"INFO","message":"Hello, world!","logger":"my.logger","properties":{"key":"value"}}
249
- * ```
250
- *
251
- * [JSON Lines]: https://jsonlines.org/
252
- * @param options The options for the JSON Lines formatter.
253
- * @returns The JSON Lines formatter.
254
- * @since 0.11.0
255
- */
256
- function getJsonLinesFormatter(options = {}) {
257
- let joinCategory;
258
- if (typeof options.categorySeparator === "function") {
259
- joinCategory = options.categorySeparator;
260
- }
261
- else {
262
- const separator = options.categorySeparator ?? ".";
263
- joinCategory = (category) => category.join(separator);
264
- }
265
- let getMessage;
266
- if (options.message === "template") {
267
- getMessage = (record) => {
268
- if (typeof record.rawMessage === "string") {
269
- return record.rawMessage;
270
- }
271
- let msg = "";
272
- for (let i = 0; i < record.rawMessage.length; i++) {
273
- msg += i % 2 < 1 ? record.rawMessage[i] : "{}";
274
- }
275
- return msg;
276
- };
277
- }
278
- else {
279
- getMessage = (record) => {
280
- let msg = "";
281
- for (let i = 0; i < record.message.length; i++) {
282
- msg += i % 2 < 1
283
- ? record.message[i]
284
- : JSON.stringify(record.message[i]);
285
- }
286
- return msg;
287
- };
288
- }
289
- const propertiesOption = options.properties ?? "nest:properties";
290
- let getProperties;
291
- if (propertiesOption === "flatten") {
292
- getProperties = (properties) => properties;
293
- }
294
- else if (propertiesOption.startsWith("prepend:")) {
295
- const prefix = propertiesOption.substring(8);
296
- if (prefix === "") {
297
- throw new TypeError(`Invalid properties option: ${JSON.stringify(propertiesOption)}. It must be of the form "prepend:<prefix>" where <prefix> is a non-empty string.`);
298
- }
299
- getProperties = (properties) => {
300
- const result = {};
301
- for (const key in properties) {
302
- result[`${prefix}${key}`] = properties[key];
303
- }
304
- return result;
305
- };
306
- }
307
- else if (propertiesOption.startsWith("nest:")) {
308
- const key = propertiesOption.substring(5);
309
- getProperties = (properties) => ({ [key]: properties });
310
- }
311
- else {
312
- throw new TypeError(`Invalid properties option: ${JSON.stringify(propertiesOption)}. It must be "flatten", "prepend:<prefix>", or "nest:<key>".`);
313
- }
314
- return (record) => {
315
- return JSON.stringify({
316
- "@timestamp": new Date(record.timestamp).toISOString(),
317
- level: record.level === "warning" ? "WARN" : record.level.toUpperCase(),
318
- message: getMessage(record),
319
- logger: joinCategory(record.category),
320
- ...getProperties(record.properties),
321
- });
322
- };
323
- }
324
- /**
325
- * The default [JSON Lines] formatter. This formatter formats log records
326
- * as JSON objects, one per line, which is a common format for log files.
327
- * It looks like this:
328
- *
329
- * ```json
330
- * {"@timestamp":"2023-11-14T22:13:20.000Z","level":"INFO","message":"Hello, world!","logger":"my.logger","properties":{"key":"value"}}
331
- * ```
332
- *
333
- * You can customize the output by passing options to
334
- * {@link getJsonLinesFormatter}. For example, you can change the category
335
- * separator, the message format, and how the properties are formatted.
336
- *
337
- * [JSON Lines]: https://jsonlines.org/
338
- * @since 0.11.0
339
- */
340
- exports.jsonLinesFormatter = getJsonLinesFormatter();
341
- /**
342
- * The styles for the log level in the console.
343
- */
344
- const logLevelStyles = {
345
- "debug": "background-color: gray; color: white;",
346
- "info": "background-color: white; color: black;",
347
- "warning": "background-color: orange; color: black;",
348
- "error": "background-color: red; color: white;",
349
- "fatal": "background-color: maroon; color: white;",
350
- };
351
- /**
352
- * The default console formatter.
353
- *
354
- * @param record The log record to format.
355
- * @returns The formatted log record, as an array of arguments for
356
- * {@link console.log}.
357
- */
358
- function defaultConsoleFormatter(record) {
359
- let msg = "";
360
- const values = [];
361
- for (let i = 0; i < record.message.length; i++) {
362
- if (i % 2 === 0)
363
- msg += record.message[i];
364
- else {
365
- msg += "%o";
366
- values.push(record.message[i]);
367
- }
368
- }
369
- const date = new Date(record.timestamp);
370
- const time = `${date.getUTCHours().toString().padStart(2, "0")}:${date.getUTCMinutes().toString().padStart(2, "0")}:${date.getUTCSeconds().toString().padStart(2, "0")}.${date.getUTCMilliseconds().toString().padStart(3, "0")}`;
371
- return [
372
- `%c${time} %c${levelAbbreviations[record.level]}%c %c${record.category.join("\xb7")} %c${msg}`,
373
- "color: gray;",
374
- logLevelStyles[record.level],
375
- "background-color: default;",
376
- "color: gray;",
377
- "color: default;",
378
- ...values,
379
- ];
380
- }
package/script/level.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseLogLevel = parseLogLevel;
4
- exports.isLogLevel = isLogLevel;
5
- exports.compareLogLevel = compareLogLevel;
6
- const logLevels = ["debug", "info", "warning", "error", "fatal"];
7
- /**
8
- * Parses a log level from a string.
9
- *
10
- * @param level The log level as a string. This is case-insensitive.
11
- * @returns The log level.
12
- * @throws {TypeError} If the log level is invalid.
13
- */
14
- function parseLogLevel(level) {
15
- level = level.toLowerCase();
16
- switch (level) {
17
- case "debug":
18
- case "info":
19
- case "warning":
20
- case "error":
21
- case "fatal":
22
- return level;
23
- default:
24
- throw new TypeError(`Invalid log level: ${level}.`);
25
- }
26
- }
27
- /**
28
- * Checks if a string is a valid log level. This function can be used as
29
- * as a type guard to narrow the type of a string to a {@link LogLevel}.
30
- *
31
- * @param level The log level as a string. This is case-sensitive.
32
- * @returns `true` if the string is a valid log level.
33
- */
34
- function isLogLevel(level) {
35
- switch (level) {
36
- case "debug":
37
- case "info":
38
- case "warning":
39
- case "error":
40
- case "fatal":
41
- return true;
42
- default:
43
- return false;
44
- }
45
- }
46
- /**
47
- * Compares two log levels.
48
- * @param a The first log level.
49
- * @param b The second log level.
50
- * @returns A negative number if `a` is less than `b`, a positive number if `a`
51
- * is greater than `b`, or zero if they are equal.
52
- * @since 0.8.0
53
- */
54
- function compareLogLevel(a, b) {
55
- const aIndex = logLevels.indexOf(a);
56
- if (aIndex < 0) {
57
- throw new TypeError(`Invalid log level: ${JSON.stringify(a)}.`);
58
- }
59
- const bIndex = logLevels.indexOf(b);
60
- if (bIndex < 0) {
61
- throw new TypeError(`Invalid log level: ${JSON.stringify(b)}.`);
62
- }
63
- return aIndex - bIndex;
64
- }