@n8io/baseline-logger 2.1.0 → 3.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/README.md +2 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,8 @@ pnpm add @n8io/baseline-logger
|
|
|
8
8
|
|
|
9
9
|
## Exports
|
|
10
10
|
|
|
11
|
-
- `logger`: the
|
|
11
|
+
- `logger`: the one logger, typed as the package's own `Logger` (`fatal`, `error`, `warn`, `info`, `debug`, `trace` and `level`), so the library behind it can change without touching a caller. Fields named like credentials (`authorization`, `cookie`, `password`, `token` and others) are logged as `[Redacted]`, also one level down and in headers.
|
|
12
|
+
- `Logger` and `LoggerMethod`: the types of `logger` and of one level's call, `(fields, message?)` or `(message)`. There is no `child`, no printf-style arguments and no way to set `level`; the level comes from `LOG_LEVEL`.
|
|
12
13
|
- `@n8io/baseline-logger/err-serialize`: `loggerErrSerialize(value)` and `LoggerErr`. An error leaves the process only as its class name, `code`, `constraint` and stack, down the `cause` chain; never its message, which can hold input text. `logger` uses it for every `err`.
|
|
13
14
|
|
|
14
15
|
## Example
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
export type LoggerMethod = {
|
|
2
|
+
(fields: unknown, message?: string): void;
|
|
3
|
+
(message: string): void;
|
|
4
|
+
};
|
|
5
|
+
export type Logger = {
|
|
6
|
+
readonly level: string;
|
|
7
|
+
fatal: LoggerMethod;
|
|
8
|
+
error: LoggerMethod;
|
|
9
|
+
warn: LoggerMethod;
|
|
10
|
+
info: LoggerMethod;
|
|
11
|
+
debug: LoggerMethod;
|
|
12
|
+
trace: LoggerMethod;
|
|
13
|
+
};
|
|
2
14
|
export declare const logger: Logger;
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const errFind = (first) => {
|
|
|
26
26
|
if (first instanceof Error) return first;
|
|
27
27
|
if (typeof first === "object" && first !== null && "err" in first && !("msg" in first)) return first.err;
|
|
28
28
|
};
|
|
29
|
-
const
|
|
29
|
+
const loggerOptionsCreate = (level) => ({
|
|
30
30
|
hooks: { logMethod(args, method) {
|
|
31
31
|
const [first, second] = args;
|
|
32
32
|
const err = errFind(first);
|
|
@@ -44,5 +44,5 @@ const loggerOptions = (level) => ({
|
|
|
44
44
|
serializers: { err: loggerErrSerialize }
|
|
45
45
|
});
|
|
46
46
|
// src/index.ts
|
|
47
|
-
const logger = pino(
|
|
47
|
+
const logger = pino(loggerOptionsCreate(process.env.LOG_LEVEL || "info"));
|
|
48
48
|
export { logger };
|