nightingale 14.2.1 → 16.0.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/CHANGELOG.md +33 -0
- package/README.md +204 -57
- package/dist/definitions/config.d.ts +1 -1
- package/dist/definitions/debug/debug.d.ts +5 -0
- package/dist/definitions/debug/debug.d.ts.map +1 -0
- package/dist/definitions/debug/debug.test.d.ts +2 -0
- package/dist/definitions/debug/debug.test.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/formatObject.d.ts +9 -0
- package/dist/definitions/formatter-utils/formatObject.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/formatObject.test.d.ts +2 -0
- package/dist/definitions/formatter-utils/formatObject.test.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/formatRecordToString.d.ts +4 -0
- package/dist/definitions/formatter-utils/formatRecordToString.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/index.d.ts +15 -0
- package/dist/definitions/formatter-utils/index.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/index.test.d.ts +2 -0
- package/dist/definitions/formatter-utils/index.test.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/levelToStyles.d.ts +3 -0
- package/dist/definitions/formatter-utils/levelToStyles.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/levelToSymbol.d.ts +3 -0
- package/dist/definitions/formatter-utils/levelToSymbol.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/styleToHexColor.d.ts +7 -0
- package/dist/definitions/formatter-utils/styleToHexColor.d.ts.map +1 -0
- package/dist/definitions/formatter-utils/styleToHtmlStyle.d.ts +109 -0
- package/dist/definitions/formatter-utils/styleToHtmlStyle.d.ts.map +1 -0
- package/dist/definitions/formatters/ANSIFormatter.d.ts +6 -0
- package/dist/definitions/formatters/ANSIFormatter.d.ts.map +1 -0
- package/dist/definitions/formatters/ANSIFormatter.test.d.ts +2 -0
- package/dist/definitions/formatters/ANSIFormatter.test.d.ts.map +1 -0
- package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts +10 -0
- package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts.map +1 -0
- package/dist/definitions/formatters/BrowserConsoleFormatter.test.d.ts +2 -0
- package/dist/definitions/formatters/BrowserConsoleFormatter.test.d.ts.map +1 -0
- package/dist/definitions/formatters/HTMLFormatter.d.ts +5 -0
- package/dist/definitions/formatters/HTMLFormatter.d.ts.map +1 -0
- package/dist/definitions/formatters/HTMLFormatter.test.d.ts +2 -0
- package/dist/definitions/formatters/HTMLFormatter.test.d.ts.map +1 -0
- package/dist/definitions/formatters/JSONFormatter.d.ts +4 -0
- package/dist/definitions/formatters/JSONFormatter.d.ts.map +1 -0
- package/dist/definitions/formatters/JSONFormatter.test.d.ts +2 -0
- package/dist/definitions/formatters/JSONFormatter.test.d.ts.map +1 -0
- package/dist/definitions/formatters/MarkdownFormatter.d.ts +5 -0
- package/dist/definitions/formatters/MarkdownFormatter.d.ts.map +1 -0
- package/dist/definitions/formatters/MarkdownFormatter.test.d.ts +2 -0
- package/dist/definitions/formatters/MarkdownFormatter.test.d.ts.map +1 -0
- package/dist/definitions/formatters/RawFormatter.d.ts +5 -0
- package/dist/definitions/formatters/RawFormatter.d.ts.map +1 -0
- package/dist/definitions/formatters/RawFormatter.test.d.ts +2 -0
- package/dist/definitions/formatters/RawFormatter.test.d.ts.map +1 -0
- package/dist/definitions/handlers/BrowserConsoleHandler.d.ts +14 -0
- package/dist/definitions/handlers/BrowserConsoleHandler.d.ts.map +1 -0
- package/dist/definitions/handlers/ConsoleCLIHandler.d.ts +12 -0
- package/dist/definitions/handlers/ConsoleCLIHandler.d.ts.map +1 -0
- package/dist/definitions/handlers/ConsoleHandler.d.ts +14 -0
- package/dist/definitions/handlers/ConsoleHandler.d.ts.map +1 -0
- package/dist/definitions/handlers/StringHandler.d.ts +9 -0
- package/dist/definitions/handlers/StringHandler.d.ts.map +1 -0
- package/dist/definitions/index.d.ts +18 -4
- package/dist/definitions/index.d.ts.map +1 -1
- package/dist/definitions/loggers/LoggerCLI.d.ts +23 -0
- package/dist/definitions/loggers/LoggerCLI.d.ts.map +1 -0
- package/dist/definitions/outputs/cliConsoleOutput.d.ts +3 -0
- package/dist/definitions/outputs/cliConsoleOutput.d.ts.map +1 -0
- package/dist/definitions/outputs/consoleOutput.d.ts +3 -0
- package/dist/definitions/outputs/consoleOutput.d.ts.map +1 -0
- package/dist/index-browser.es.js +936 -46
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-node20.mjs +1023 -0
- package/dist/index-node20.mjs.map +1 -0
- package/package.json +31 -37
- package/src/config.ts +12 -12
- package/src/debug/debug.test.ts +50 -0
- package/src/debug/debug.ts +100 -0
- package/src/formatter-utils/formatObject.test.ts +153 -0
- package/src/formatter-utils/formatObject.ts +462 -0
- package/src/formatter-utils/formatRecordToString.ts +67 -0
- package/src/formatter-utils/index.test.ts +33 -0
- package/src/formatter-utils/index.ts +20 -0
- package/src/formatter-utils/levelToStyles.ts +14 -0
- package/src/formatter-utils/levelToSymbol.ts +14 -0
- package/src/formatter-utils/styleToHexColor.ts +9 -0
- package/src/formatter-utils/styleToHtmlStyle.ts +69 -0
- package/src/formatters/ANSIFormatter.test.ts +27 -0
- package/src/formatters/ANSIFormatter.ts +68 -0
- package/src/formatters/BrowserConsoleFormatter.test.ts +59 -0
- package/src/formatters/BrowserConsoleFormatter.ts +45 -0
- package/src/formatters/HTMLFormatter.test.ts +23 -0
- package/src/formatters/HTMLFormatter.ts +28 -0
- package/src/formatters/JSONFormatter.test.ts +62 -0
- package/src/formatters/JSONFormatter.ts +62 -0
- package/src/formatters/MarkdownFormatter.test.ts +19 -0
- package/src/formatters/MarkdownFormatter.ts +31 -0
- package/src/formatters/RawFormatter.test.ts +21 -0
- package/src/formatters/RawFormatter.ts +13 -0
- package/src/handlers/BrowserConsoleHandler.ts +78 -0
- package/src/handlers/ConsoleCLIHandler.ts +41 -0
- package/src/handlers/ConsoleHandler.ts +55 -0
- package/src/handlers/StringHandler.ts +21 -0
- package/src/index.test.ts +29 -29
- package/src/index.ts +24 -10
- package/src/loggers/LoggerCLI.ts +91 -0
- package/src/outputs/cliConsoleOutput.ts +17 -0
- package/src/outputs/consoleOutput.ts +18 -0
- package/dist/index-browsermodern.es.js +0 -120
- package/dist/index-browsermodern.es.js.map +0 -1
- package/dist/index-node18.mjs +0 -120
- package/dist/index-node18.mjs.map +0 -1
- package/src/.eslintrc.json +0 -30
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Level } from "nightingale-levels";
|
|
2
|
+
import type {
|
|
3
|
+
Handle,
|
|
4
|
+
Handler,
|
|
5
|
+
IsHandling,
|
|
6
|
+
LogRecord,
|
|
7
|
+
Metadata,
|
|
8
|
+
} from "nightingale-types";
|
|
9
|
+
import { createFindDebugLevel } from "../debug/debug";
|
|
10
|
+
import { ANSIFormatter } from "../formatters/ANSIFormatter";
|
|
11
|
+
import { JSONFormatter } from "../formatters/JSONFormatter";
|
|
12
|
+
import { cliConsoleOutput } from "../outputs/cliConsoleOutput";
|
|
13
|
+
import { consoleOutput } from "../outputs/consoleOutput";
|
|
14
|
+
|
|
15
|
+
const createHandle = ({ json }: ConsoleCLIHandlerOptions): Handle => {
|
|
16
|
+
const formatter = json ? JSONFormatter.format : ANSIFormatter.format;
|
|
17
|
+
const output = json ? consoleOutput : cliConsoleOutput;
|
|
18
|
+
return <T extends Metadata>(record: LogRecord<T>): void => {
|
|
19
|
+
output(formatter(record), record);
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
|
|
23
|
+
|
|
24
|
+
export interface ConsoleCLIHandlerOptions {
|
|
25
|
+
json?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class ConsoleCLIHandler implements Handler {
|
|
29
|
+
minLevel: Level = Level.ALL;
|
|
30
|
+
|
|
31
|
+
isHandling: IsHandling;
|
|
32
|
+
|
|
33
|
+
handle: Handle;
|
|
34
|
+
|
|
35
|
+
constructor(minLevel: Level, options: ConsoleCLIHandlerOptions = {}) {
|
|
36
|
+
this.minLevel = minLevel;
|
|
37
|
+
this.isHandling = (level: Level, key: string) =>
|
|
38
|
+
level >= findDebugLevel(minLevel, key);
|
|
39
|
+
this.handle = createHandle(options);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Level } from "nightingale-levels";
|
|
2
|
+
import type {
|
|
3
|
+
Handle,
|
|
4
|
+
Handler,
|
|
5
|
+
IsHandling,
|
|
6
|
+
LogRecord,
|
|
7
|
+
Metadata,
|
|
8
|
+
} from "nightingale-types";
|
|
9
|
+
import { POB_TARGET } from "pob-babel";
|
|
10
|
+
import { createFindDebugLevel } from "../debug/debug";
|
|
11
|
+
import { ANSIFormatter } from "../formatters/ANSIFormatter";
|
|
12
|
+
import { JSONFormatter } from "../formatters/JSONFormatter";
|
|
13
|
+
import { consoleOutput } from "../outputs/consoleOutput";
|
|
14
|
+
|
|
15
|
+
const defaultFormatter =
|
|
16
|
+
POB_TARGET === "node" &&
|
|
17
|
+
!process.stdout.isTTY &&
|
|
18
|
+
process.env.NIGHTINGALE_CONSOLE_FORMATTER !== "ansi"
|
|
19
|
+
? JSONFormatter.format
|
|
20
|
+
: ANSIFormatter.format;
|
|
21
|
+
|
|
22
|
+
const createHandle = (
|
|
23
|
+
formatter = defaultFormatter,
|
|
24
|
+
output = consoleOutput,
|
|
25
|
+
): Handle => {
|
|
26
|
+
return <T extends Metadata>(record: LogRecord<T>): void => {
|
|
27
|
+
output(formatter(record), record);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
|
|
31
|
+
|
|
32
|
+
export interface ConsoleHandlerOptions {
|
|
33
|
+
formatter?: <T extends Metadata>(record: LogRecord<T>) => string;
|
|
34
|
+
output?: <T extends Metadata>(
|
|
35
|
+
param: string[] | string,
|
|
36
|
+
record: LogRecord<T>,
|
|
37
|
+
) => void;
|
|
38
|
+
// compat with nightingale-app-console, not used yet
|
|
39
|
+
theme?: "dark" | "light";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class ConsoleHandler implements Handler {
|
|
43
|
+
minLevel: Level = Level.ALL;
|
|
44
|
+
|
|
45
|
+
isHandling: IsHandling;
|
|
46
|
+
|
|
47
|
+
handle: Handle;
|
|
48
|
+
|
|
49
|
+
constructor(minLevel: Level, options: ConsoleHandlerOptions = {}) {
|
|
50
|
+
this.minLevel = minLevel;
|
|
51
|
+
this.isHandling = (level: Level, key: string) =>
|
|
52
|
+
level >= findDebugLevel(minLevel, key);
|
|
53
|
+
this.handle = createHandle(options.formatter, options.output);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/* eslint-disable prefer-template */
|
|
2
|
+
import type { Handler, Level, LogRecord, Metadata } from "nightingale-types";
|
|
3
|
+
import { RawFormatter } from "../formatters/RawFormatter";
|
|
4
|
+
|
|
5
|
+
export class StringHandler implements Handler {
|
|
6
|
+
readonly minLevel: Level;
|
|
7
|
+
|
|
8
|
+
private _buffer = "";
|
|
9
|
+
|
|
10
|
+
constructor(minLevel: Level) {
|
|
11
|
+
this.minLevel = minLevel;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get string(): string {
|
|
15
|
+
return this._buffer;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
handle<T extends Metadata>(record: LogRecord<T>): void {
|
|
19
|
+
this._buffer += RawFormatter.format(record) + "\n";
|
|
20
|
+
}
|
|
21
|
+
}
|
package/src/index.test.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { ComputedConfigForKey } from
|
|
2
|
-
import { StringHandler } from
|
|
3
|
-
import {
|
|
1
|
+
import type { ComputedConfigForKey } from "nightingale-logger";
|
|
2
|
+
import { StringHandler } from "./handlers/StringHandler";
|
|
3
|
+
import { Level, Logger } from ".";
|
|
4
4
|
|
|
5
5
|
class TestableStringLogger extends Logger {
|
|
6
6
|
private readonly stringHandler: StringHandler;
|
|
7
7
|
|
|
8
8
|
constructor() {
|
|
9
|
-
super(
|
|
9
|
+
super("");
|
|
10
10
|
this.stringHandler = new StringHandler(Level.ALL);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
protected getHandlersAndProcessors(): ComputedConfigForKey {
|
|
13
|
+
protected override getHandlersAndProcessors(): ComputedConfigForKey {
|
|
14
14
|
return {
|
|
15
15
|
handlers: [this.stringHandler],
|
|
16
16
|
processors: [],
|
|
@@ -22,50 +22,50 @@ class TestableStringLogger extends Logger {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
test(
|
|
25
|
+
test("log method", () => {
|
|
26
26
|
const logger = new TestableStringLogger();
|
|
27
|
-
logger.log(
|
|
28
|
-
expect(logger.string.slice(9)).toBe(
|
|
27
|
+
logger.log("log()");
|
|
28
|
+
expect(logger.string.slice(9)).toBe("→ log()\n");
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
test(
|
|
31
|
+
test("info method", () => {
|
|
32
32
|
const logger = new TestableStringLogger();
|
|
33
|
-
logger.info(
|
|
34
|
-
expect(logger.string.slice(9)).toBe(
|
|
33
|
+
logger.info("info()");
|
|
34
|
+
expect(logger.string.slice(9)).toBe("→ info()\n");
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
test(
|
|
37
|
+
test("warn method", () => {
|
|
38
38
|
const logger = new TestableStringLogger();
|
|
39
|
-
logger.warn(
|
|
40
|
-
expect(logger.string.slice(9)).toBe(
|
|
39
|
+
logger.warn("warn()");
|
|
40
|
+
expect(logger.string.slice(9)).toBe("⚠ warn()\n");
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
test(
|
|
43
|
+
test("error method", () => {
|
|
44
44
|
const logger = new TestableStringLogger();
|
|
45
|
-
logger.error(
|
|
46
|
-
expect(logger.string.slice(9)).toBe(
|
|
45
|
+
logger.error("error()");
|
|
46
|
+
expect(logger.string.slice(9)).toBe("✖ error()\n");
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
test(
|
|
49
|
+
test("alert method", () => {
|
|
50
50
|
const logger = new TestableStringLogger();
|
|
51
|
-
logger.alert(
|
|
52
|
-
expect(logger.string.slice(9)).toBe(
|
|
51
|
+
logger.alert("alert()");
|
|
52
|
+
expect(logger.string.slice(9)).toBe("‼ alert()\n");
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
-
test(
|
|
55
|
+
test("fatal method", () => {
|
|
56
56
|
const logger = new TestableStringLogger();
|
|
57
|
-
logger.fatal(
|
|
58
|
-
expect(logger.string.slice(9)).toBe(
|
|
57
|
+
logger.fatal("fatal()");
|
|
58
|
+
expect(logger.string.slice(9)).toBe("‼ fatal()\n");
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
test(
|
|
61
|
+
test("debug method", () => {
|
|
62
62
|
const logger = new TestableStringLogger();
|
|
63
|
-
logger.debug(
|
|
64
|
-
expect(logger.string.slice(9)).toBe(
|
|
63
|
+
logger.debug("debug()");
|
|
64
|
+
expect(logger.string.slice(9)).toBe("• debug()\n");
|
|
65
65
|
});
|
|
66
66
|
|
|
67
|
-
test(
|
|
67
|
+
test("success method", () => {
|
|
68
68
|
const logger = new TestableStringLogger();
|
|
69
|
-
logger.success(
|
|
70
|
-
expect(logger.string.slice(9)).toBe(
|
|
69
|
+
logger.success("success()");
|
|
70
|
+
expect(logger.string.slice(9)).toBe("✔ success()\n");
|
|
71
71
|
});
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import { Logger } from
|
|
1
|
+
import { Logger } from "nightingale-logger";
|
|
2
2
|
|
|
3
|
-
export { Logger } from
|
|
4
|
-
export { Level, Level as levels } from
|
|
5
|
-
export { configure, addConfig } from
|
|
3
|
+
export { Logger } from "nightingale-logger";
|
|
4
|
+
export { Level, Level as levels } from "nightingale-levels";
|
|
5
|
+
export { configure, addConfig } from "./config";
|
|
6
|
+
export * from "./formatter-utils";
|
|
7
|
+
export { createFindDebugLevel } from "./debug/debug";
|
|
8
|
+
export { RawFormatter } from "./formatters/RawFormatter";
|
|
9
|
+
export { MarkdownFormatter } from "./formatters/MarkdownFormatter";
|
|
10
|
+
export { JSONFormatter } from "./formatters/JSONFormatter";
|
|
11
|
+
export { ANSIFormatter } from "./formatters/ANSIFormatter";
|
|
12
|
+
export { HTMLFormatter } from "./formatters/HTMLFormatter";
|
|
13
|
+
export { BrowserConsoleFormatter } from "./formatters/BrowserConsoleFormatter";
|
|
14
|
+
export { consoleOutput } from "./outputs/consoleOutput";
|
|
15
|
+
export { StringHandler } from "./handlers/StringHandler";
|
|
16
|
+
export { BrowserConsoleHandler } from "./handlers/BrowserConsoleHandler";
|
|
17
|
+
export { ConsoleHandler } from "./handlers/ConsoleHandler";
|
|
18
|
+
export { ConsoleCLIHandler } from "./handlers/ConsoleCLIHandler";
|
|
19
|
+
export { LoggerCLI } from "./loggers/LoggerCLI";
|
|
6
20
|
|
|
7
21
|
/**
|
|
8
22
|
* listen to uncaughtException and unhandledRejection
|
|
@@ -10,20 +24,20 @@ export { configure, addConfig } from './config';
|
|
|
10
24
|
*/
|
|
11
25
|
export function listenUnhandledErrors(
|
|
12
26
|
logger: Logger = new Logger(
|
|
13
|
-
|
|
14
|
-
|
|
27
|
+
"nightingale:listenUnhandledErrors",
|
|
28
|
+
"UnhandledErrors",
|
|
15
29
|
),
|
|
16
30
|
): void {
|
|
17
|
-
process.on(
|
|
31
|
+
process.on("uncaughtException", (error) => {
|
|
18
32
|
logger.error(error, {
|
|
19
33
|
unhandled: true,
|
|
20
|
-
type:
|
|
34
|
+
type: "uncaughtException",
|
|
21
35
|
});
|
|
22
36
|
});
|
|
23
|
-
process.on(
|
|
37
|
+
process.on("unhandledRejection", (error) => {
|
|
24
38
|
logger.error(error as Error, {
|
|
25
39
|
unhandled: true,
|
|
26
|
-
type:
|
|
40
|
+
type: "unhandledRejection",
|
|
27
41
|
});
|
|
28
42
|
});
|
|
29
43
|
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { ComputedConfigForKey } from "nightingale-logger";
|
|
2
|
+
import { Level, Logger } from "nightingale-logger";
|
|
3
|
+
import type { Handler, Processor } from "nightingale-types";
|
|
4
|
+
import { ConsoleCLIHandler } from "../handlers/ConsoleCLIHandler";
|
|
5
|
+
|
|
6
|
+
export interface LoggerCLIOptions {
|
|
7
|
+
displayName?: string;
|
|
8
|
+
handlers?: Handler[];
|
|
9
|
+
processors?: Processor[];
|
|
10
|
+
json?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export class LoggerCLI extends Logger {
|
|
14
|
+
private handlers: Handler[];
|
|
15
|
+
private processors: Processor[] = [];
|
|
16
|
+
private json: boolean;
|
|
17
|
+
constructor(
|
|
18
|
+
key: string,
|
|
19
|
+
{ displayName, processors, json = false }: LoggerCLIOptions = {},
|
|
20
|
+
) {
|
|
21
|
+
super(key, displayName);
|
|
22
|
+
this.handlers = [new ConsoleCLIHandler(Level.INFO, { json })];
|
|
23
|
+
this.processors = processors ?? [];
|
|
24
|
+
this.json = json;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
protected override getHandlersAndProcessors(
|
|
28
|
+
recordLevel: number,
|
|
29
|
+
): ComputedConfigForKey {
|
|
30
|
+
return {
|
|
31
|
+
handlers: this.handlers,
|
|
32
|
+
processors: this.processors,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
logJsonOnly(
|
|
37
|
+
messageOrError: string,
|
|
38
|
+
metadata: Record<string, unknown>,
|
|
39
|
+
level: Level = Level.INFO,
|
|
40
|
+
): void {
|
|
41
|
+
if (this.json) {
|
|
42
|
+
this.log(messageOrError, metadata, level);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
debugJsonOnly(
|
|
47
|
+
messageOrError: string,
|
|
48
|
+
metadata: Record<string, unknown>,
|
|
49
|
+
): void {
|
|
50
|
+
if (this.json) {
|
|
51
|
+
this.debug(messageOrError, metadata);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
noticeJsonOnly(
|
|
56
|
+
messageOrError: string,
|
|
57
|
+
metadata: Record<string, unknown>,
|
|
58
|
+
): void {
|
|
59
|
+
if (this.json) {
|
|
60
|
+
this.notice(messageOrError, metadata);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
infoJsonOnly(
|
|
65
|
+
messageOrError: string,
|
|
66
|
+
metadata: Record<string, unknown>,
|
|
67
|
+
): void {
|
|
68
|
+
if (this.json) {
|
|
69
|
+
this.info(messageOrError, metadata);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
warnJsonOnly(
|
|
74
|
+
messageOrError: string,
|
|
75
|
+
metadata: Record<string, unknown>,
|
|
76
|
+
): void {
|
|
77
|
+
if (this.json) {
|
|
78
|
+
this.warn(messageOrError, metadata);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
group(name: string, fn: () => void): void {
|
|
83
|
+
if (this.json) {
|
|
84
|
+
fn();
|
|
85
|
+
} else {
|
|
86
|
+
console.group(name);
|
|
87
|
+
fn();
|
|
88
|
+
console.groupEnd();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { Level } from "nightingale-levels";
|
|
3
|
+
import type { LogRecord, Metadata } from "nightingale-types";
|
|
4
|
+
import { POB_TARGET } from "pob-babel";
|
|
5
|
+
|
|
6
|
+
export function cliConsoleOutput<T extends Metadata>(
|
|
7
|
+
param: string[] | string,
|
|
8
|
+
record: LogRecord<T>,
|
|
9
|
+
): void {
|
|
10
|
+
if (POB_TARGET !== "browser") {
|
|
11
|
+
console[record.level >= Level.ERROR ? "error" : "log"](param as string);
|
|
12
|
+
} else {
|
|
13
|
+
console[record.level >= Level.ERROR ? "error" : "log"](
|
|
14
|
+
...(param as string[]),
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import { Level } from "nightingale-levels";
|
|
3
|
+
import type { LogRecord, Metadata } from "nightingale-types";
|
|
4
|
+
import { POB_TARGET } from "pob-babel";
|
|
5
|
+
|
|
6
|
+
export function consoleOutput<T extends Metadata>(
|
|
7
|
+
param: string[] | string,
|
|
8
|
+
record: LogRecord<T>,
|
|
9
|
+
): void {
|
|
10
|
+
if (POB_TARGET !== "browser") {
|
|
11
|
+
const outKey = record.level >= Level.ERROR ? "stderr" : "stdout";
|
|
12
|
+
process[outKey].write(`${param as string}\n`);
|
|
13
|
+
} else {
|
|
14
|
+
console[record.level >= Level.ERROR ? "error" : "log"](
|
|
15
|
+
...(param as string[]),
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'nightingale-logger';
|
|
2
|
-
export { Logger } from 'nightingale-logger';
|
|
3
|
-
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
|
-
|
|
5
|
-
const globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
6
|
-
if (process.env.NODE_ENV !== 'production' && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
7
|
-
throw new Error('nightingale: update all to ^5.0.0');
|
|
8
|
-
}
|
|
9
|
-
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
10
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
11
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
12
|
-
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
|
-
handlers: [],
|
|
14
|
-
processors: []
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function clearCache() {
|
|
18
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
19
|
-
}
|
|
20
|
-
function handleConfig(config) {
|
|
21
|
-
if (config.keys) {
|
|
22
|
-
if (config.pattern) {
|
|
23
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
24
|
-
}
|
|
25
|
-
if (config.key) {
|
|
26
|
-
throw new Error('Cannot have key and keys for the same config');
|
|
27
|
-
}
|
|
28
|
-
} else if (config.key) {
|
|
29
|
-
if (config.pattern) {
|
|
30
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
31
|
-
}
|
|
32
|
-
config.keys = [config.key];
|
|
33
|
-
delete config.key;
|
|
34
|
-
}
|
|
35
|
-
if (config.handler) {
|
|
36
|
-
if (config.handlers) {
|
|
37
|
-
throw new Error('Cannot have handler and handlers for the same config');
|
|
38
|
-
}
|
|
39
|
-
config.handlers = [config.handler];
|
|
40
|
-
delete config.handler;
|
|
41
|
-
}
|
|
42
|
-
if (config.processor) {
|
|
43
|
-
if (config.processors) {
|
|
44
|
-
throw new Error('Cannot have processors and processors for the same config');
|
|
45
|
-
}
|
|
46
|
-
config.processors = [config.processor];
|
|
47
|
-
delete config.processor;
|
|
48
|
-
}
|
|
49
|
-
return config;
|
|
50
|
-
}
|
|
51
|
-
function configure(config) {
|
|
52
|
-
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
console.log('nightingale: warning: config overridden');
|
|
55
|
-
}
|
|
56
|
-
clearCache();
|
|
57
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
58
|
-
}
|
|
59
|
-
function addConfig(config, unshift = false) {
|
|
60
|
-
config = handleConfig(config);
|
|
61
|
-
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
62
|
-
clearCache();
|
|
63
|
-
}
|
|
64
|
-
const configIsForKey = key => config => {
|
|
65
|
-
if (config.keys) return config.keys.includes(key);
|
|
66
|
-
if (config.pattern) return config.pattern.test(key);
|
|
67
|
-
return true;
|
|
68
|
-
};
|
|
69
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
70
|
-
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
71
|
-
const existingCache = globalCache.get(key);
|
|
72
|
-
if (existingCache) {
|
|
73
|
-
return existingCache;
|
|
74
|
-
}
|
|
75
|
-
const loggerConfig = {
|
|
76
|
-
handlers: [],
|
|
77
|
-
processors: []
|
|
78
|
-
};
|
|
79
|
-
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
80
|
-
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
81
|
-
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
82
|
-
return config.stop;
|
|
83
|
-
});
|
|
84
|
-
globalCache.set(key, loggerConfig);
|
|
85
|
-
return loggerConfig;
|
|
86
|
-
};
|
|
87
|
-
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
88
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
89
|
-
const {
|
|
90
|
-
handlers,
|
|
91
|
-
processors
|
|
92
|
-
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
93
|
-
return {
|
|
94
|
-
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
95
|
-
processors
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* listen to uncaughtException and unhandledRejection
|
|
102
|
-
* @param {Logger} [logger]
|
|
103
|
-
*/
|
|
104
|
-
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
105
|
-
process.on('uncaughtException', error => {
|
|
106
|
-
logger.error(error, {
|
|
107
|
-
unhandled: true,
|
|
108
|
-
type: 'uncaughtException'
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
process.on('unhandledRejection', error => {
|
|
112
|
-
logger.error(error, {
|
|
113
|
-
unhandled: true,
|
|
114
|
-
type: 'unhandledRejection'
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export { addConfig, configure, listenUnhandledErrors };
|
|
120
|
-
//# sourceMappingURL=index-browsermodern.es.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index-browsermodern.es.js","sources":["../src/config.ts","../src/index.ts"],"sourcesContent":["import type { ComputedConfigForKey, Config } from 'nightingale-logger';\nimport type { Handler, Level } from 'nightingale-types';\n\nconst globalOrWindow: typeof global =\n typeof global !== 'undefined' ? global : (window as typeof global);\n\nif (\n process.env.NODE_ENV !== 'production' &&\n globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS\n) {\n throw new Error('nightingale: update all to ^5.0.0');\n}\n\nif (!globalOrWindow.__NIGHTINGALE_CONFIG) {\n globalOrWindow.__NIGHTINGALE_CONFIG = [];\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map<\n string,\n ComputedConfigForKey\n >();\n globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {\n handlers: [],\n processors: [],\n };\n}\n\nfunction clearCache(): void {\n globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();\n}\n\nfunction handleConfig(config: Config): Config {\n if (config.keys) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n if (config.key) {\n throw new Error('Cannot have key and keys for the same config');\n }\n } else if (config.key) {\n if (config.pattern) {\n throw new Error('Cannot have key and pattern for the same config');\n }\n config.keys = [config.key];\n delete config.key;\n }\n\n if (config.handler) {\n if (config.handlers) {\n throw new Error('Cannot have handler and handlers for the same config');\n }\n config.handlers = [config.handler];\n delete config.handler;\n }\n\n if (config.processor) {\n if (config.processors) {\n throw new Error(\n 'Cannot have processors and processors for the same config',\n );\n }\n config.processors = [config.processor];\n delete config.processor;\n }\n\n return config;\n}\n\nexport function configure(config: Config[]): void {\n if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {\n // eslint-disable-next-line no-console\n console.log('nightingale: warning: config overridden');\n }\n\n clearCache();\n globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);\n}\n\nexport function addConfig(config: Config, unshift = false): void {\n config = handleConfig(config);\n globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);\n clearCache();\n}\n\nconst configIsForKey = (key: string) => (config: Config) => {\n if (config.keys) return config.keys.includes(key);\n if (config.pattern) return config.pattern.test(key);\n return true;\n};\n\nglobalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = (\n key: string,\n): ComputedConfigForKey => {\n const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;\n\n const existingCache = globalCache.get(key);\n\n if (existingCache) {\n return existingCache;\n }\n\n const loggerConfig: ComputedConfigForKey = {\n handlers: [],\n processors: [],\n };\n\n globalOrWindow.__NIGHTINGALE_CONFIG\n .filter(configIsForKey(key))\n .some((config: Config) => {\n if (config.handlers) loggerConfig.handlers.push(...config.handlers);\n if (config.processors) loggerConfig.processors.push(...config.processors);\n return config.stop;\n });\n\n globalCache.set(key, loggerConfig);\n return loggerConfig;\n};\n\nif (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (\n key: string,\n level: Level,\n ): ComputedConfigForKey => {\n const { handlers, processors }: ComputedConfigForKey =\n globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);\n\n return {\n handlers: handlers.filter(\n (handler: Handler) =>\n level >= handler.minLevel &&\n (!handler.isHandling || handler.isHandling(level, key)),\n ),\n processors,\n };\n };\n}\n","import { Logger } from 'nightingale-logger';\n\nexport { Logger } from 'nightingale-logger';\nexport { Level, Level as levels } from 'nightingale-levels';\nexport { configure, addConfig } from './config';\n\n/**\n * listen to uncaughtException and unhandledRejection\n * @param {Logger} [logger]\n */\nexport function listenUnhandledErrors(\n logger: Logger = new Logger(\n 'nightingale:listenUnhandledErrors',\n 'UnhandledErrors',\n ),\n): void {\n process.on('uncaughtException', (error) => {\n logger.error(error, {\n unhandled: true,\n type: 'uncaughtException',\n });\n });\n process.on('unhandledRejection', (error) => {\n logger.error(error as Error, {\n unhandled: true,\n type: 'unhandledRejection',\n });\n });\n}\n"],"names":["globalOrWindow","global","window","process","env","NODE_ENV","__NIGHTINGALE_GLOBAL_HANDLERS","Error","__NIGHTINGALE_CONFIG","__NIGHTINGALE_LOGGER_MAP_CACHE","Map","__NIGHTINGALE_CONFIG_DEFAULT","handlers","processors","clearCache","clear","handleConfig","config","keys","pattern","key","handler","processor","configure","length","console","log","map","addConfig","unshift","configIsForKey","includes","test","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER","globalCache","existingCache","get","loggerConfig","filter","some","push","stop","set","__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD","level","minLevel","isHandling","listenUnhandledErrors","logger","Logger","on","error","unhandled","type"],"mappings":";;;;AAGA,MAAMA,cAA6B,GACjC,OAAOC,MAAM,KAAK,WAAW,GAAGA,MAAM,GAAIC,MAAwB,CAAA;AAEpE,IACEC,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,YAAY,IACrCL,cAAc,CAACM,6BAA6B,EAC5C;AACA,EAAA,MAAM,IAAIC,KAAK,CAAC,mCAAmC,CAAC,CAAA;AACtD,CAAA;AAEA,IAAI,CAACP,cAAc,CAACQ,oBAAoB,EAAE;EACxCR,cAAc,CAACQ,oBAAoB,GAAG,EAAE,CAAA;AACxCR,EAAAA,cAAc,CAACS,8BAA8B,GAAG,IAAIC,GAAG,EAGpD,CA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/HA;AACA;AACA;AACA;AACO,SAASkC,qBAAqBA,CACnCC,MAAc,GAAG,IAAIC,MAAM,CACzB,mCAAmC,EACnC,iBACF,CAAC,EACK;AACN9C,EAAAA,OAAO,CAAC+C,EAAE,CAAC,mBAAmB,EAAGC,KAAK,IAAK;AACzCH,IAAAA,MAAM,CAACG,KAAK,CAACA,KAAK,EAAE;AAClBC,MAAAA,SAAS,EAAE,IAAI;AACfC,MAAAA,IAAI,EAAE,mBAAA;AACR,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AACFlD,EAAAA,OAAO,CAAC+C,EAAE,CAAC,oBAAoB,EAAGC,KAAK,IAAK;AAC1CH,IAAAA,MAAM,CAACG,KAAK,CAACA,KAAK,EAAW;AAC3BC,MAAAA,SAAS,EAAE,IAAI;AACfC,MAAAA,IAAI,EAAE,oBAAA;AACR,KAAC,CAAC,CAAA;AACJ,GAAC,CAAC,CAAA;AACJ;;;;"}
|
package/dist/index-node18.mjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'nightingale-logger';
|
|
2
|
-
export { Logger } from 'nightingale-logger';
|
|
3
|
-
export { Level, Level as levels } from 'nightingale-levels';
|
|
4
|
-
|
|
5
|
-
const globalOrWindow = typeof global !== 'undefined' ? global : window;
|
|
6
|
-
if (process.env.NODE_ENV !== 'production' && globalOrWindow.__NIGHTINGALE_GLOBAL_HANDLERS) {
|
|
7
|
-
throw new Error('nightingale: update all to ^5.0.0');
|
|
8
|
-
}
|
|
9
|
-
if (!globalOrWindow.__NIGHTINGALE_CONFIG) {
|
|
10
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = [];
|
|
11
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE = new Map();
|
|
12
|
-
globalOrWindow.__NIGHTINGALE_CONFIG_DEFAULT = {
|
|
13
|
-
handlers: [],
|
|
14
|
-
processors: []
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
function clearCache() {
|
|
18
|
-
globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE.clear();
|
|
19
|
-
}
|
|
20
|
-
function handleConfig(config) {
|
|
21
|
-
if (config.keys) {
|
|
22
|
-
if (config.pattern) {
|
|
23
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
24
|
-
}
|
|
25
|
-
if (config.key) {
|
|
26
|
-
throw new Error('Cannot have key and keys for the same config');
|
|
27
|
-
}
|
|
28
|
-
} else if (config.key) {
|
|
29
|
-
if (config.pattern) {
|
|
30
|
-
throw new Error('Cannot have key and pattern for the same config');
|
|
31
|
-
}
|
|
32
|
-
config.keys = [config.key];
|
|
33
|
-
delete config.key;
|
|
34
|
-
}
|
|
35
|
-
if (config.handler) {
|
|
36
|
-
if (config.handlers) {
|
|
37
|
-
throw new Error('Cannot have handler and handlers for the same config');
|
|
38
|
-
}
|
|
39
|
-
config.handlers = [config.handler];
|
|
40
|
-
delete config.handler;
|
|
41
|
-
}
|
|
42
|
-
if (config.processor) {
|
|
43
|
-
if (config.processors) {
|
|
44
|
-
throw new Error('Cannot have processors and processors for the same config');
|
|
45
|
-
}
|
|
46
|
-
config.processors = [config.processor];
|
|
47
|
-
delete config.processor;
|
|
48
|
-
}
|
|
49
|
-
return config;
|
|
50
|
-
}
|
|
51
|
-
function configure(config) {
|
|
52
|
-
if (globalOrWindow.__NIGHTINGALE_CONFIG.length > 0) {
|
|
53
|
-
// eslint-disable-next-line no-console
|
|
54
|
-
console.log('nightingale: warning: config overridden');
|
|
55
|
-
}
|
|
56
|
-
clearCache();
|
|
57
|
-
globalOrWindow.__NIGHTINGALE_CONFIG = config.map(handleConfig);
|
|
58
|
-
}
|
|
59
|
-
function addConfig(config, unshift = false) {
|
|
60
|
-
config = handleConfig(config);
|
|
61
|
-
globalOrWindow.__NIGHTINGALE_CONFIG[unshift ? 'unshift' : 'push'](config);
|
|
62
|
-
clearCache();
|
|
63
|
-
}
|
|
64
|
-
const configIsForKey = key => config => {
|
|
65
|
-
if (config.keys) return config.keys.includes(key);
|
|
66
|
-
if (config.pattern) return config.pattern.test(key);
|
|
67
|
-
return true;
|
|
68
|
-
};
|
|
69
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER = key => {
|
|
70
|
-
const globalCache = globalOrWindow.__NIGHTINGALE_LOGGER_MAP_CACHE;
|
|
71
|
-
const existingCache = globalCache.get(key);
|
|
72
|
-
if (existingCache) {
|
|
73
|
-
return existingCache;
|
|
74
|
-
}
|
|
75
|
-
const loggerConfig = {
|
|
76
|
-
handlers: [],
|
|
77
|
-
processors: []
|
|
78
|
-
};
|
|
79
|
-
globalOrWindow.__NIGHTINGALE_CONFIG.filter(configIsForKey(key)).some(config => {
|
|
80
|
-
if (config.handlers) loggerConfig.handlers.push(...config.handlers);
|
|
81
|
-
if (config.processors) loggerConfig.processors.push(...config.processors);
|
|
82
|
-
return config.stop;
|
|
83
|
-
});
|
|
84
|
-
globalCache.set(key, loggerConfig);
|
|
85
|
-
return loggerConfig;
|
|
86
|
-
};
|
|
87
|
-
if (globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD) {
|
|
88
|
-
globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER_RECORD = (key, level) => {
|
|
89
|
-
const {
|
|
90
|
-
handlers,
|
|
91
|
-
processors
|
|
92
|
-
} = globalOrWindow.__NIGHTINGALE_GET_CONFIG_FOR_LOGGER(key);
|
|
93
|
-
return {
|
|
94
|
-
handlers: handlers.filter(handler => level >= handler.minLevel && (!handler.isHandling || handler.isHandling(level, key))),
|
|
95
|
-
processors
|
|
96
|
-
};
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* listen to uncaughtException and unhandledRejection
|
|
102
|
-
* @param {Logger} [logger]
|
|
103
|
-
*/
|
|
104
|
-
function listenUnhandledErrors(logger = new Logger('nightingale:listenUnhandledErrors', 'UnhandledErrors')) {
|
|
105
|
-
process.on('uncaughtException', error => {
|
|
106
|
-
logger.error(error, {
|
|
107
|
-
unhandled: true,
|
|
108
|
-
type: 'uncaughtException'
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
process.on('unhandledRejection', error => {
|
|
112
|
-
logger.error(error, {
|
|
113
|
-
unhandled: true,
|
|
114
|
-
type: 'unhandledRejection'
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export { addConfig, configure, listenUnhandledErrors };
|
|
120
|
-
//# sourceMappingURL=index-node18.mjs.map
|