@logtape/logtape 0.9.0-dev.128 → 0.9.0-dev.129
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/esm/config.js +1 -1
- package/esm/sink.js +14 -22
- package/package.json +1 -1
- package/script/config.js +1 -1
- package/script/sink.js +14 -22
- package/types/sink.d.ts +18 -0
- package/types/sink.d.ts.map +1 -1
package/esm/config.js
CHANGED
|
@@ -208,7 +208,7 @@ function configureInternal(config, allowAsync) {
|
|
|
208
208
|
meta.info("LogTape loggers are configured. Note that LogTape itself uses the meta " +
|
|
209
209
|
"logger, which has category {metaLoggerCategory}. The meta logger " +
|
|
210
210
|
"purposes to log internal errors such as sink exceptions. If you " +
|
|
211
|
-
"are seeing this message, the meta logger is
|
|
211
|
+
"are seeing this message, the meta logger is automatically configured. " +
|
|
212
212
|
"It's recommended to configure the meta logger with a separate sink " +
|
|
213
213
|
"so that you can easily notice if logging itself fails or is " +
|
|
214
214
|
"misconfigured. To turn off this message, configure the meta logger " +
|
package/esm/sink.js
CHANGED
|
@@ -70,35 +70,27 @@ export function getStreamSink(stream, options = {}) {
|
|
|
70
70
|
*/
|
|
71
71
|
export function getConsoleSink(options = {}) {
|
|
72
72
|
const formatter = options.formatter ?? defaultConsoleFormatter;
|
|
73
|
+
const levelMap = {
|
|
74
|
+
debug: "debug",
|
|
75
|
+
info: "info",
|
|
76
|
+
warning: "warn",
|
|
77
|
+
error: "error",
|
|
78
|
+
fatal: "error",
|
|
79
|
+
...(options.levelMap ?? {}),
|
|
80
|
+
};
|
|
73
81
|
const console = options.console ?? globalThis.console;
|
|
74
82
|
return (record) => {
|
|
75
83
|
const args = formatter(record);
|
|
84
|
+
const method = levelMap[record.level];
|
|
85
|
+
if (method === undefined) {
|
|
86
|
+
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
87
|
+
}
|
|
76
88
|
if (typeof args === "string") {
|
|
77
89
|
const msg = args.replace(/\r?\n$/, "");
|
|
78
|
-
|
|
79
|
-
console.debug(msg);
|
|
80
|
-
else if (record.level === "info")
|
|
81
|
-
console.info(msg);
|
|
82
|
-
else if (record.level === "warning")
|
|
83
|
-
console.warn(msg);
|
|
84
|
-
else if (record.level === "error" || record.level === "fatal") {
|
|
85
|
-
console.error(msg);
|
|
86
|
-
}
|
|
87
|
-
else
|
|
88
|
-
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
90
|
+
console[method](msg);
|
|
89
91
|
}
|
|
90
92
|
else {
|
|
91
|
-
|
|
92
|
-
console.debug(...args);
|
|
93
|
-
else if (record.level === "info")
|
|
94
|
-
console.info(...args);
|
|
95
|
-
else if (record.level === "warning")
|
|
96
|
-
console.warn(...args);
|
|
97
|
-
else if (record.level === "error" || record.level === "fatal") {
|
|
98
|
-
console.error(...args);
|
|
99
|
-
}
|
|
100
|
-
else
|
|
101
|
-
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
93
|
+
console[method](...args);
|
|
102
94
|
}
|
|
103
95
|
};
|
|
104
96
|
}
|
package/package.json
CHANGED
package/script/config.js
CHANGED
|
@@ -241,7 +241,7 @@ function configureInternal(config, allowAsync) {
|
|
|
241
241
|
meta.info("LogTape loggers are configured. Note that LogTape itself uses the meta " +
|
|
242
242
|
"logger, which has category {metaLoggerCategory}. The meta logger " +
|
|
243
243
|
"purposes to log internal errors such as sink exceptions. If you " +
|
|
244
|
-
"are seeing this message, the meta logger is
|
|
244
|
+
"are seeing this message, the meta logger is automatically configured. " +
|
|
245
245
|
"It's recommended to configure the meta logger with a separate sink " +
|
|
246
246
|
"so that you can easily notice if logging itself fails or is " +
|
|
247
247
|
"misconfigured. To turn off this message, configure the meta logger " +
|
package/script/sink.js
CHANGED
|
@@ -77,35 +77,27 @@ function getStreamSink(stream, options = {}) {
|
|
|
77
77
|
*/
|
|
78
78
|
function getConsoleSink(options = {}) {
|
|
79
79
|
const formatter = options.formatter ?? formatter_js_1.defaultConsoleFormatter;
|
|
80
|
+
const levelMap = {
|
|
81
|
+
debug: "debug",
|
|
82
|
+
info: "info",
|
|
83
|
+
warning: "warn",
|
|
84
|
+
error: "error",
|
|
85
|
+
fatal: "error",
|
|
86
|
+
...(options.levelMap ?? {}),
|
|
87
|
+
};
|
|
80
88
|
const console = options.console ?? globalThis.console;
|
|
81
89
|
return (record) => {
|
|
82
90
|
const args = formatter(record);
|
|
91
|
+
const method = levelMap[record.level];
|
|
92
|
+
if (method === undefined) {
|
|
93
|
+
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
94
|
+
}
|
|
83
95
|
if (typeof args === "string") {
|
|
84
96
|
const msg = args.replace(/\r?\n$/, "");
|
|
85
|
-
|
|
86
|
-
console.debug(msg);
|
|
87
|
-
else if (record.level === "info")
|
|
88
|
-
console.info(msg);
|
|
89
|
-
else if (record.level === "warning")
|
|
90
|
-
console.warn(msg);
|
|
91
|
-
else if (record.level === "error" || record.level === "fatal") {
|
|
92
|
-
console.error(msg);
|
|
93
|
-
}
|
|
94
|
-
else
|
|
95
|
-
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
97
|
+
console[method](msg);
|
|
96
98
|
}
|
|
97
99
|
else {
|
|
98
|
-
|
|
99
|
-
console.debug(...args);
|
|
100
|
-
else if (record.level === "info")
|
|
101
|
-
console.info(...args);
|
|
102
|
-
else if (record.level === "warning")
|
|
103
|
-
console.warn(...args);
|
|
104
|
-
else if (record.level === "error" || record.level === "fatal") {
|
|
105
|
-
console.error(...args);
|
|
106
|
-
}
|
|
107
|
-
else
|
|
108
|
-
throw new TypeError(`Invalid log level: ${record.level}.`);
|
|
100
|
+
console[method](...args);
|
|
109
101
|
}
|
|
110
102
|
};
|
|
111
103
|
}
|
package/types/sink.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type FilterLike } from "./filter.js";
|
|
2
2
|
import { type ConsoleFormatter, type TextFormatter } from "./formatter.js";
|
|
3
|
+
import type { LogLevel } from "./level.js";
|
|
3
4
|
import type { LogRecord } from "./record.js";
|
|
4
5
|
/**
|
|
5
6
|
* A sink is a function that accepts a log record and prints it somewhere.
|
|
@@ -66,6 +67,7 @@ export interface StreamSinkOptions {
|
|
|
66
67
|
* @returns A sink that writes to the stream.
|
|
67
68
|
*/
|
|
68
69
|
export declare function getStreamSink(stream: WritableStream, options?: StreamSinkOptions): Sink & AsyncDisposable;
|
|
70
|
+
type ConsoleMethod = "debug" | "info" | "log" | "warn" | "error";
|
|
69
71
|
/**
|
|
70
72
|
* Options for the {@link getConsoleSink} function.
|
|
71
73
|
*/
|
|
@@ -75,6 +77,21 @@ export interface ConsoleSinkOptions {
|
|
|
75
77
|
* Defaults to {@link defaultConsoleFormatter}.
|
|
76
78
|
*/
|
|
77
79
|
formatter?: ConsoleFormatter | TextFormatter;
|
|
80
|
+
/**
|
|
81
|
+
* The mapping from log levels to console methods. Defaults to:
|
|
82
|
+
*
|
|
83
|
+
* ```typescript
|
|
84
|
+
* {
|
|
85
|
+
* debug: "debug",
|
|
86
|
+
* info: "info",
|
|
87
|
+
* warning: "warn",
|
|
88
|
+
* error: "error",
|
|
89
|
+
* fatal: "error",
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
* @since 0.9.0
|
|
93
|
+
*/
|
|
94
|
+
levelMap?: Record<LogLevel, ConsoleMethod>;
|
|
78
95
|
/**
|
|
79
96
|
* The console to log to. Defaults to {@link console}.
|
|
80
97
|
*/
|
|
@@ -174,4 +191,5 @@ export interface RotatingFileSinkDriver<TFile> extends FileSinkDriver<TFile> {
|
|
|
174
191
|
* object that closes the file when disposed.
|
|
175
192
|
*/
|
|
176
193
|
export declare function getRotatingFileSink<TFile>(path: string, options: RotatingFileSinkOptions & RotatingFileSinkDriver<TFile>): Sink & Disposable;
|
|
194
|
+
export {};
|
|
177
195
|
//# sourceMappingURL=sink.d.ts.map
|
package/types/sink.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sink.d.ts","sourceRoot":"","sources":["../src/sink.ts"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