nightingale 16.2.0 → 17.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 +17 -0
- package/README.md +1 -1
- package/dist/definitions/formatter-utils/formatRecordToString.d.ts +1 -1
- package/dist/definitions/formatter-utils/formatRecordToString.d.ts.map +1 -1
- package/dist/definitions/formatter-utils/index.d.ts +1 -4
- package/dist/definitions/formatter-utils/index.d.ts.map +1 -1
- package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts +3 -3
- package/dist/definitions/formatters/BrowserConsoleFormatter.d.ts.map +1 -1
- package/dist/definitions/formatters/JSONFormatter.d.ts.map +1 -1
- package/dist/definitions/handlers/ConsoleCLIHandler.d.ts +1 -0
- package/dist/definitions/handlers/ConsoleCLIHandler.d.ts.map +1 -1
- package/dist/definitions/handlers/ConsoleHandler.d.ts +2 -1
- package/dist/definitions/handlers/ConsoleHandler.d.ts.map +1 -1
- package/dist/definitions/handlers/defaultFormatter.d.ts +2 -0
- package/dist/definitions/handlers/defaultFormatter.d.ts.map +1 -0
- package/dist/definitions/handlers/defaultFormatter.target-node.d.ts +2 -0
- package/dist/definitions/handlers/defaultFormatter.target-node.d.ts.map +1 -0
- package/dist/definitions/loggers/LoggerCLI.d.ts +6 -1
- package/dist/definitions/loggers/LoggerCLI.d.ts.map +1 -1
- package/dist/definitions/loggers/LoggerCLI.test.d.ts +2 -0
- package/dist/definitions/loggers/LoggerCLI.test.d.ts.map +1 -0
- package/dist/definitions/outputs/cliConsoleOutput.d.ts +1 -1
- package/dist/definitions/outputs/cliConsoleOutput.d.ts.map +1 -1
- package/dist/definitions/outputs/consoleOutput.d.ts +1 -1
- package/dist/definitions/outputs/consoleOutput.d.ts.map +1 -1
- package/dist/definitions/outputs/consoleOutput.target-node.d.ts +3 -0
- package/dist/definitions/outputs/consoleOutput.target-node.d.ts.map +1 -0
- package/dist/index-browser.es.js +262 -357
- package/dist/index-browser.es.js.map +1 -1
- package/dist/index-node20.mjs +266 -362
- package/dist/index-node20.mjs.map +1 -1
- package/package.json +14 -12
- package/src/formatter-utils/formatObject.test.ts +1 -3
- package/src/formatter-utils/formatRecordToString.ts +2 -2
- package/src/formatter-utils/index.ts +1 -5
- package/src/formatters/ANSIFormatter.test.ts +1 -1
- package/src/formatters/BrowserConsoleFormatter.ts +4 -6
- package/src/formatters/HTMLFormatter.test.ts +2 -2
- package/src/formatters/JSONFormatter.test.ts +5 -5
- package/src/formatters/JSONFormatter.ts +19 -15
- package/src/formatters/MarkdownFormatter.test.ts +3 -1
- package/src/formatters/RawFormatter.test.ts +2 -2
- package/src/handlers/ConsoleCLIHandler.ts +11 -2
- package/src/handlers/ConsoleHandler.ts +3 -11
- package/src/handlers/StringHandler.ts +1 -1
- package/src/handlers/defaultFormatter.target-node.ts +7 -0
- package/src/handlers/defaultFormatter.ts +3 -0
- package/src/loggers/LoggerCLI.test.ts +19 -0
- package/src/loggers/LoggerCLI.ts +22 -2
- package/src/outputs/cliConsoleOutput.ts +2 -9
- package/src/outputs/consoleOutput.target-node.ts +10 -0
- package/src/outputs/consoleOutput.ts +2 -10
|
@@ -38,25 +38,29 @@ function stringify(value: unknown, space?: number | string): string {
|
|
|
38
38
|
|
|
39
39
|
export const JSONFormatter: NightingaleFormatter = {
|
|
40
40
|
format(record) {
|
|
41
|
-
return
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
return [
|
|
42
|
+
stringify({
|
|
43
|
+
key: record.key,
|
|
44
|
+
level: record.level,
|
|
45
|
+
datetime: record.datetime,
|
|
46
|
+
message: record.message,
|
|
47
|
+
metadata: record.metadata,
|
|
48
|
+
extra: record.extra,
|
|
49
|
+
}),
|
|
50
|
+
];
|
|
49
51
|
},
|
|
50
52
|
};
|
|
51
53
|
|
|
52
54
|
export const JSONCLIFormatter: NightingaleFormatter = {
|
|
53
55
|
format(record) {
|
|
54
|
-
return
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
return [
|
|
57
|
+
stringify({
|
|
58
|
+
key: record.key,
|
|
59
|
+
time: record.datetime.toTimeString().split(" ", 2)[0]!,
|
|
60
|
+
message: record.message,
|
|
61
|
+
...record.metadata,
|
|
62
|
+
...record.extra,
|
|
63
|
+
}),
|
|
64
|
+
];
|
|
61
65
|
},
|
|
62
66
|
};
|
|
@@ -9,11 +9,19 @@ import type {
|
|
|
9
9
|
import { createFindDebugLevel } from "../debug/debug";
|
|
10
10
|
import { ANSIFormatter } from "../formatters/ANSIFormatter";
|
|
11
11
|
import { JSONFormatter } from "../formatters/JSONFormatter";
|
|
12
|
+
import { RawFormatter } from "../formatters/RawFormatter";
|
|
12
13
|
import { cliConsoleOutput } from "../outputs/cliConsoleOutput";
|
|
13
14
|
import { consoleOutput } from "../outputs/consoleOutput";
|
|
14
15
|
|
|
15
|
-
const createHandle = ({
|
|
16
|
-
|
|
16
|
+
const createHandle = ({
|
|
17
|
+
json,
|
|
18
|
+
noColor = process.env.NO_COLOR === "1" || process.env.NO_COLOR === "true",
|
|
19
|
+
}: ConsoleCLIHandlerOptions): Handle => {
|
|
20
|
+
const formatter = (() => {
|
|
21
|
+
if (json) return JSONFormatter.format;
|
|
22
|
+
if (noColor) return RawFormatter.format;
|
|
23
|
+
return ANSIFormatter.format;
|
|
24
|
+
})();
|
|
17
25
|
const output = json ? consoleOutput : cliConsoleOutput;
|
|
18
26
|
return <T extends Metadata>(record: LogRecord<T>): void => {
|
|
19
27
|
output(formatter(record), record);
|
|
@@ -23,6 +31,7 @@ const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
|
|
|
23
31
|
|
|
24
32
|
export interface ConsoleCLIHandlerOptions {
|
|
25
33
|
json?: boolean;
|
|
34
|
+
noColor?: boolean;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
export class ConsoleCLIHandler implements Handler {
|
|
@@ -6,18 +6,10 @@ import type {
|
|
|
6
6
|
LogRecord,
|
|
7
7
|
Metadata,
|
|
8
8
|
} from "nightingale-types";
|
|
9
|
-
import { POB_TARGET } from "pob-babel";
|
|
10
9
|
import { createFindDebugLevel } from "../debug/debug";
|
|
11
|
-
import {
|
|
12
|
-
import { JSONFormatter } from "../formatters/JSONFormatter";
|
|
10
|
+
import type { NightingaleFormatter } from "../formatter-utils";
|
|
13
11
|
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;
|
|
12
|
+
import { defaultFormatter } from "./defaultFormatter";
|
|
21
13
|
|
|
22
14
|
const createHandle = (
|
|
23
15
|
formatter = defaultFormatter,
|
|
@@ -30,7 +22,7 @@ const createHandle = (
|
|
|
30
22
|
const findDebugLevel = createFindDebugLevel(process.env.DEBUG);
|
|
31
23
|
|
|
32
24
|
export interface ConsoleHandlerOptions {
|
|
33
|
-
formatter?:
|
|
25
|
+
formatter?: NightingaleFormatter["format"];
|
|
34
26
|
output?: <T extends Metadata>(
|
|
35
27
|
param: string[] | string,
|
|
36
28
|
record: LogRecord<T>,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ANSIFormatter } from "../formatters/ANSIFormatter";
|
|
2
|
+
import { JSONFormatter } from "../formatters/JSONFormatter";
|
|
3
|
+
|
|
4
|
+
export const defaultFormatter =
|
|
5
|
+
!process.stdout.isTTY && process.env.NIGHTINGALE_CONSOLE_FORMATTER !== "ansi"
|
|
6
|
+
? JSONFormatter.format
|
|
7
|
+
: ANSIFormatter.format;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { LoggerCLIString } from "./LoggerCLI";
|
|
2
|
+
|
|
3
|
+
describe("LoggerCLI", () => {
|
|
4
|
+
test("LoggerCLIString", () => {
|
|
5
|
+
import.meta.jest.useFakeTimers({
|
|
6
|
+
now: new Date("2023-10-01T10:57:49.000Z"),
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
const consoleLogSpy = import.meta.jest
|
|
10
|
+
.spyOn(console, "log")
|
|
11
|
+
.mockImplementation(() => {});
|
|
12
|
+
const logger = new LoggerCLIString("test", { noColor: true });
|
|
13
|
+
logger.info("Test message", { key: "value" });
|
|
14
|
+
|
|
15
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
16
|
+
'test 10:57:49 → Test message { key: "value" }',
|
|
17
|
+
);
|
|
18
|
+
});
|
|
19
|
+
});
|
package/src/loggers/LoggerCLI.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface LoggerCLIOptions {
|
|
|
8
8
|
handlers?: Handler[];
|
|
9
9
|
processors?: Processor[];
|
|
10
10
|
json?: boolean;
|
|
11
|
+
noColor?: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
export class LoggerCLI extends Logger {
|
|
@@ -16,10 +17,10 @@ export class LoggerCLI extends Logger {
|
|
|
16
17
|
private json: boolean;
|
|
17
18
|
constructor(
|
|
18
19
|
key: string,
|
|
19
|
-
{ displayName, processors, json = false }: LoggerCLIOptions = {},
|
|
20
|
+
{ displayName, processors, json = false, noColor }: LoggerCLIOptions = {},
|
|
20
21
|
) {
|
|
21
22
|
super(key, displayName);
|
|
22
|
-
this.handlers = [new ConsoleCLIHandler(Level.INFO, { json })];
|
|
23
|
+
this.handlers = [new ConsoleCLIHandler(Level.INFO, { json, noColor })];
|
|
23
24
|
this.processors = processors ?? [];
|
|
24
25
|
this.json = json;
|
|
25
26
|
}
|
|
@@ -100,4 +101,23 @@ export class LoggerCLI extends Logger {
|
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
103
|
}
|
|
104
|
+
|
|
105
|
+
separator(): void {
|
|
106
|
+
console.log();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export class LoggerCLIString extends LoggerCLI {
|
|
111
|
+
constructor(
|
|
112
|
+
key: string,
|
|
113
|
+
{
|
|
114
|
+
displayName,
|
|
115
|
+
handlers,
|
|
116
|
+
processors,
|
|
117
|
+
json = false,
|
|
118
|
+
noColor = false,
|
|
119
|
+
}: LoggerCLIOptions = {},
|
|
120
|
+
) {
|
|
121
|
+
super(key, { displayName, handlers, processors, json, noColor });
|
|
122
|
+
}
|
|
103
123
|
}
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { Level } from "nightingale-levels";
|
|
3
3
|
import type { LogRecord, Metadata } from "nightingale-types";
|
|
4
|
-
import { POB_TARGET } from "pob-babel";
|
|
5
4
|
|
|
6
5
|
export function cliConsoleOutput<T extends Metadata>(
|
|
7
|
-
param: string[]
|
|
6
|
+
param: [string, ...string[]],
|
|
8
7
|
record: LogRecord<T>,
|
|
9
8
|
): void {
|
|
10
|
-
|
|
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
|
-
}
|
|
9
|
+
console[record.level >= Level.ERROR ? "error" : "log"](...param);
|
|
17
10
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Level } from "nightingale-levels";
|
|
2
|
+
import type { LogRecord, Metadata } from "nightingale-types";
|
|
3
|
+
|
|
4
|
+
export function consoleOutput<T extends Metadata>(
|
|
5
|
+
param: [string, ...string[]],
|
|
6
|
+
record: LogRecord<T>,
|
|
7
|
+
): void {
|
|
8
|
+
const outKey = record.level >= Level.ERROR ? "stderr" : "stdout";
|
|
9
|
+
process[outKey].write(`${param[0]}\n`);
|
|
10
|
+
}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import { Level } from "nightingale-levels";
|
|
3
3
|
import type { LogRecord, Metadata } from "nightingale-types";
|
|
4
|
-
import { POB_TARGET } from "pob-babel";
|
|
5
4
|
|
|
6
5
|
export function consoleOutput<T extends Metadata>(
|
|
7
|
-
param: string[]
|
|
6
|
+
param: [string, ...string[]],
|
|
8
7
|
record: LogRecord<T>,
|
|
9
8
|
): void {
|
|
10
|
-
|
|
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
|
-
}
|
|
9
|
+
console[record.level >= Level.ERROR ? "error" : "log"](...param);
|
|
18
10
|
}
|