@logtape/file 0.10.0-dev.149 → 0.10.0-dev.162

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 (62) hide show
  1. package/esm/file/filesink.base.js +1 -1
  2. package/package.json +4 -1
  3. package/script/file/filesink.base.js +3 -3
  4. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/_common/assert_path.d.ts.map +1 -1
  5. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/_common/constants.d.ts.map +1 -1
  6. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/_common/normalize.d.ts.map +1 -1
  7. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/_common/normalize_string.d.ts.map +1 -1
  8. package/types/deps/jsr.io/@std/path/1.0.9/_os.d.ts.map +1 -0
  9. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/join.d.ts.map +1 -1
  10. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/posix/_util.d.ts.map +1 -1
  11. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/posix/join.d.ts.map +1 -1
  12. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/posix/normalize.d.ts.map +1 -1
  13. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/windows/_util.d.ts.map +1 -1
  14. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/windows/join.d.ts.map +1 -1
  15. package/types/deps/jsr.io/@std/path/{1.0.8 → 1.0.9}/windows/normalize.d.ts.map +1 -1
  16. package/types/file/filesink.base.d.ts +1 -1
  17. package/types/file/filesink.base.d.ts.map +1 -1
  18. package/types/file/filesink.node.d.ts +1 -1
  19. package/types/file/filesink.node.d.ts.map +1 -1
  20. package/esm/_dnt.shims.js +0 -57
  21. package/esm/logtape/config.js +0 -287
  22. package/esm/logtape/context.js +0 -23
  23. package/esm/logtape/filter.js +0 -42
  24. package/esm/logtape/formatter.js +0 -263
  25. package/esm/logtape/level.js +0 -59
  26. package/esm/logtape/logger.js +0 -480
  27. package/esm/logtape/mod.js +0 -8
  28. package/esm/logtape/nodeUtil.js +0 -2
  29. package/esm/logtape/record.js +0 -1
  30. package/esm/logtape/sink.js +0 -96
  31. package/script/_dnt.shims.js +0 -60
  32. package/script/logtape/config.js +0 -321
  33. package/script/logtape/context.js +0 -26
  34. package/script/logtape/filter.js +0 -46
  35. package/script/logtape/formatter.js +0 -272
  36. package/script/logtape/level.js +0 -64
  37. package/script/logtape/logger.js +0 -511
  38. package/script/logtape/mod.js +0 -34
  39. package/script/logtape/nodeUtil.js +0 -7
  40. package/script/logtape/record.js +0 -2
  41. package/script/logtape/sink.js +0 -101
  42. package/types/_dnt.shims.d.ts +0 -2
  43. package/types/_dnt.shims.d.ts.map +0 -1
  44. package/types/deps/jsr.io/@std/path/1.0.8/_os.d.ts.map +0 -1
  45. package/types/logtape/config.d.ts +0 -183
  46. package/types/logtape/config.d.ts.map +0 -1
  47. package/types/logtape/context.d.ts +0 -35
  48. package/types/logtape/context.d.ts.map +0 -1
  49. package/types/logtape/filter.d.ts +0 -31
  50. package/types/logtape/filter.d.ts.map +0 -1
  51. package/types/logtape/formatter.d.ts +0 -261
  52. package/types/logtape/formatter.d.ts.map +0 -1
  53. package/types/logtape/level.d.ts +0 -32
  54. package/types/logtape/logger.d.ts +0 -423
  55. package/types/logtape/logger.d.ts.map +0 -1
  56. package/types/logtape/mod.d.ts +0 -9
  57. package/types/logtape/mod.d.ts.map +0 -1
  58. package/types/logtape/nodeUtil.d.ts +0 -3
  59. package/types/logtape/nodeUtil.d.ts.map +0 -1
  60. package/types/logtape/record.d.ts +0 -44
  61. package/types/logtape/sink.d.ts +0 -108
  62. package/types/logtape/sink.d.ts.map +0 -1
@@ -1,263 +0,0 @@
1
- import util from "./nodeUtil.js";
2
- /**
3
- * The severity level abbreviations.
4
- */
5
- const levelAbbreviations = {
6
- "debug": "DBG",
7
- "info": "INF",
8
- "warning": "WRN",
9
- "error": "ERR",
10
- "fatal": "FTL",
11
- };
12
- /**
13
- * A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
14
- * and in Node.js/Bun it is `util.inspect()`. If neither is available, it
15
- * falls back to {@link JSON.stringify}.
16
- *
17
- * @param value The value to inspect.
18
- * @param options The options for inspecting the value.
19
- * If `colors` is `true`, the output will be ANSI-colored.
20
- * @returns The string representation of the value.
21
- */
22
- const inspect =
23
- // @ts-ignore: Deno global
24
- // dnt-shim-ignore
25
- "Deno" in globalThis && "inspect" in globalThis.Deno &&
26
- // @ts-ignore: Deno global
27
- // dnt-shim-ignore
28
- typeof globalThis.Deno.inspect === "function"
29
- ? (v, opts) =>
30
- // @ts-ignore: Deno global
31
- // dnt-shim-ignore
32
- globalThis.Deno.inspect(v, {
33
- strAbbreviateSize: Infinity,
34
- iterableLimit: Infinity,
35
- ...opts,
36
- })
37
- // @ts-ignore: Node.js global
38
- // dnt-shim-ignore
39
- : util != null && "inspect" in util && typeof util.inspect === "function"
40
- ? (v, opts) =>
41
- // @ts-ignore: Node.js global
42
- // dnt-shim-ignore
43
- util.inspect(v, {
44
- maxArrayLength: Infinity,
45
- maxStringLength: Infinity,
46
- ...opts,
47
- })
48
- : (v) => JSON.stringify(v);
49
- /**
50
- * Get a text formatter with the specified options. Although it's flexible
51
- * enough to create a custom formatter, if you want more control, you can
52
- * create a custom formatter that satisfies the {@link TextFormatter} type
53
- * instead.
54
- *
55
- * For more information on the options, see {@link TextFormatterOptions}.
56
- *
57
- * By default, the formatter formats log records as follows:
58
- *
59
- * ```
60
- * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
61
- * ```
62
- * @param options The options for the text formatter.
63
- * @returns The text formatter.
64
- * @since 0.6.0
65
- */
66
- export function getTextFormatter(options = {}) {
67
- const timestampRenderer = options.timestamp == null || options.timestamp === "date-time-timezone"
68
- ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00:00")
69
- : options.timestamp === "date-time-tz"
70
- ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", " +00")
71
- : options.timestamp === "date-time"
72
- ? (ts) => new Date(ts).toISOString().replace("T", " ").replace("Z", "")
73
- : options.timestamp === "time-timezone"
74
- ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00:00")
75
- : options.timestamp === "time-tz"
76
- ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", " +00")
77
- : options.timestamp === "time"
78
- ? (ts) => new Date(ts).toISOString().replace(/.*T/, "").replace("Z", "")
79
- : options.timestamp === "date"
80
- ? (ts) => new Date(ts).toISOString().replace(/T.*/, "")
81
- : options.timestamp === "rfc3339"
82
- ? (ts) => new Date(ts).toISOString()
83
- : options.timestamp === "none" || options.timestamp === "disabled"
84
- ? () => null
85
- : options.timestamp;
86
- const categorySeparator = options.category ?? "·";
87
- const valueRenderer = options.value ?? inspect;
88
- const levelRenderer = options.level == null || options.level === "ABBR"
89
- ? (level) => levelAbbreviations[level]
90
- : options.level === "abbr"
91
- ? (level) => levelAbbreviations[level].toLowerCase()
92
- : options.level === "FULL"
93
- ? (level) => level.toUpperCase()
94
- : options.level === "full"
95
- ? (level) => level
96
- : options.level === "L"
97
- ? (level) => level.charAt(0).toUpperCase()
98
- : options.level === "l"
99
- ? (level) => level.charAt(0)
100
- : options.level;
101
- const formatter = options.format ??
102
- (({ timestamp, level, category, message }) => `${timestamp ? `${timestamp} ` : ""}[${level}] ${category}: ${message}`);
103
- return (record) => {
104
- let message = "";
105
- for (let i = 0; i < record.message.length; i++) {
106
- if (i % 2 === 0)
107
- message += record.message[i];
108
- else
109
- message += valueRenderer(record.message[i]);
110
- }
111
- const timestamp = timestampRenderer(record.timestamp);
112
- const level = levelRenderer(record.level);
113
- const category = typeof categorySeparator === "function"
114
- ? categorySeparator(record.category)
115
- : record.category.join(categorySeparator);
116
- const values = {
117
- timestamp,
118
- level,
119
- category,
120
- message,
121
- record,
122
- };
123
- return `${formatter(values)}\n`;
124
- };
125
- }
126
- /**
127
- * The default text formatter. This formatter formats log records as follows:
128
- *
129
- * ```
130
- * 2023-11-14 22:13:20.000 +00:00 [INF] category·subcategory: Hello, world!
131
- * ```
132
- *
133
- * @param record The log record to format.
134
- * @returns The formatted log record.
135
- */
136
- export const defaultTextFormatter = getTextFormatter();
137
- const RESET = "\x1b[0m";
138
- const ansiColors = {
139
- black: "\x1b[30m",
140
- red: "\x1b[31m",
141
- green: "\x1b[32m",
142
- yellow: "\x1b[33m",
143
- blue: "\x1b[34m",
144
- magenta: "\x1b[35m",
145
- cyan: "\x1b[36m",
146
- white: "\x1b[37m",
147
- };
148
- const ansiStyles = {
149
- bold: "\x1b[1m",
150
- dim: "\x1b[2m",
151
- italic: "\x1b[3m",
152
- underline: "\x1b[4m",
153
- strikethrough: "\x1b[9m",
154
- };
155
- const defaultLevelColors = {
156
- debug: "blue",
157
- info: "green",
158
- warning: "yellow",
159
- error: "red",
160
- fatal: "magenta",
161
- };
162
- /**
163
- * Get an ANSI color formatter with the specified options.
164
- *
165
- * ![A preview of an ANSI color formatter.](https://i.imgur.com/I8LlBUf.png)
166
- * @param option The options for the ANSI color formatter.
167
- * @returns The ANSI color formatter.
168
- * @since 0.6.0
169
- */
170
- export function getAnsiColorFormatter(options = {}) {
171
- const format = options.format;
172
- const timestampStyle = typeof options.timestampStyle === "undefined"
173
- ? "dim"
174
- : options.timestampStyle;
175
- const timestampColor = options.timestampColor ?? null;
176
- const timestampPrefix = `${timestampStyle == null ? "" : ansiStyles[timestampStyle]}${timestampColor == null ? "" : ansiColors[timestampColor]}`;
177
- const timestampSuffix = timestampStyle == null && timestampColor == null
178
- ? ""
179
- : RESET;
180
- const levelStyle = typeof options.levelStyle === "undefined"
181
- ? "bold"
182
- : options.levelStyle;
183
- const levelColors = options.levelColors ?? defaultLevelColors;
184
- const categoryStyle = typeof options.categoryStyle === "undefined"
185
- ? "dim"
186
- : options.categoryStyle;
187
- const categoryColor = options.categoryColor ?? null;
188
- const categoryPrefix = `${categoryStyle == null ? "" : ansiStyles[categoryStyle]}${categoryColor == null ? "" : ansiColors[categoryColor]}`;
189
- const categorySuffix = categoryStyle == null && categoryColor == null
190
- ? ""
191
- : RESET;
192
- return getTextFormatter({
193
- timestamp: "date-time-tz",
194
- value(value) {
195
- return inspect(value, { colors: true });
196
- },
197
- ...options,
198
- format({ timestamp, level, category, message, record }) {
199
- const levelColor = levelColors[record.level];
200
- timestamp = `${timestampPrefix}${timestamp}${timestampSuffix}`;
201
- level = `${levelStyle == null ? "" : ansiStyles[levelStyle]}${levelColor == null ? "" : ansiColors[levelColor]}${level}${levelStyle == null && levelColor == null ? "" : RESET}`;
202
- return format == null
203
- ? `${timestamp} ${level} ${categoryPrefix}${category}:${categorySuffix} ${message}`
204
- : format({
205
- timestamp,
206
- level,
207
- category: `${categoryPrefix}${category}${categorySuffix}`,
208
- message,
209
- record,
210
- });
211
- },
212
- });
213
- }
214
- /**
215
- * A text formatter that uses ANSI colors to format log records.
216
- *
217
- * ![A preview of ansiColorFormatter.](https://i.imgur.com/I8LlBUf.png)
218
- *
219
- * @param record The log record to format.
220
- * @returns The formatted log record.
221
- * @since 0.5.0
222
- */
223
- export const ansiColorFormatter = getAnsiColorFormatter();
224
- /**
225
- * The styles for the log level in the console.
226
- */
227
- const logLevelStyles = {
228
- "debug": "background-color: gray; color: white;",
229
- "info": "background-color: white; color: black;",
230
- "warning": "background-color: orange; color: black;",
231
- "error": "background-color: red; color: white;",
232
- "fatal": "background-color: maroon; color: white;",
233
- };
234
- /**
235
- * The default console formatter.
236
- *
237
- * @param record The log record to format.
238
- * @returns The formatted log record, as an array of arguments for
239
- * {@link console.log}.
240
- */
241
- export function defaultConsoleFormatter(record) {
242
- let msg = "";
243
- const values = [];
244
- for (let i = 0; i < record.message.length; i++) {
245
- if (i % 2 === 0)
246
- msg += record.message[i];
247
- else {
248
- msg += "%o";
249
- values.push(record.message[i]);
250
- }
251
- }
252
- const date = new Date(record.timestamp);
253
- 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")}`;
254
- return [
255
- `%c${time} %c${levelAbbreviations[record.level]}%c %c${record.category.join("\xb7")} %c${msg}`,
256
- "color: gray;",
257
- logLevelStyles[record.level],
258
- "background-color: default;",
259
- "color: gray;",
260
- "color: default;",
261
- ...values,
262
- ];
263
- }
@@ -1,59 +0,0 @@
1
- const logLevels = ["debug", "info", "warning", "error", "fatal"];
2
- /**
3
- * Parses a log level from a string.
4
- *
5
- * @param level The log level as a string. This is case-insensitive.
6
- * @returns The log level.
7
- * @throws {TypeError} If the log level is invalid.
8
- */
9
- export function parseLogLevel(level) {
10
- level = level.toLowerCase();
11
- switch (level) {
12
- case "debug":
13
- case "info":
14
- case "warning":
15
- case "error":
16
- case "fatal":
17
- return level;
18
- default:
19
- throw new TypeError(`Invalid log level: ${level}.`);
20
- }
21
- }
22
- /**
23
- * Checks if a string is a valid log level. This function can be used as
24
- * as a type guard to narrow the type of a string to a {@link LogLevel}.
25
- *
26
- * @param level The log level as a string. This is case-sensitive.
27
- * @returns `true` if the string is a valid log level.
28
- */
29
- export function isLogLevel(level) {
30
- switch (level) {
31
- case "debug":
32
- case "info":
33
- case "warning":
34
- case "error":
35
- case "fatal":
36
- return true;
37
- default:
38
- return false;
39
- }
40
- }
41
- /**
42
- * Compares two log levels.
43
- * @param a The first log level.
44
- * @param b The second log level.
45
- * @returns A negative number if `a` is less than `b`, a positive number if `a`
46
- * is greater than `b`, or zero if they are equal.
47
- * @since 0.8.0
48
- */
49
- export function compareLogLevel(a, b) {
50
- const aIndex = logLevels.indexOf(a);
51
- if (aIndex < 0) {
52
- throw new TypeError(`Invalid log level: ${JSON.stringify(a)}.`);
53
- }
54
- const bIndex = logLevels.indexOf(b);
55
- if (bIndex < 0) {
56
- throw new TypeError(`Invalid log level: ${JSON.stringify(b)}.`);
57
- }
58
- return aIndex - bIndex;
59
- }