@n8io/baseline-logger 2.0.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/LICENSE +21 -0
- package/README.md +29 -0
- package/dist/index.d.ts +13 -1
- package/dist/index.js +2 -2
- package/package.json +4 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Nate Clark
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# @n8io/baseline-logger
|
|
2
|
+
|
|
3
|
+
The one [pino](https://getpino.io) logger every app and package logs through: JSON to stdout, with credentials redacted and errors reduced to a safe shape.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @n8io/baseline-logger
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## Exports
|
|
10
|
+
|
|
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`.
|
|
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`.
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { logger } from "@n8io/baseline-logger";
|
|
19
|
+
|
|
20
|
+
logger.info({ port }, "Server listening");
|
|
21
|
+
logger.error({ err: error }, "Postgres idle client error");
|
|
22
|
+
// An err with no message logs its class name as msg, never error.message.
|
|
23
|
+
logger.error({ err: error });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Needs
|
|
27
|
+
|
|
28
|
+
- Env: `LOG_LEVEL` (`fatal`, `error`, `warn`, `info`, `debug`, `trace` or `silent`; default `info`).
|
|
29
|
+
- With `@n8io/baseline-telemetry` preloaded, each record also goes out as an OTLP log with the active trace id.
|
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 };
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n8io/baseline-logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "The one pino logger every baseline app and package logs through.",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/n8io/baseline.git",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"node": ">=26"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
|
-
"dist"
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
17
18
|
],
|
|
18
19
|
"exports": {
|
|
19
20
|
".": {
|