ntlogger 2.10.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 +237 -2
- package/index.d.ts +192 -183
- package/lib/lifecycle.js +53 -0
- package/lib/logger.js +100 -57
- package/lib/pinoHooks.js +446 -0
- package/lib/processHandlers.js +305 -0
- package/lib/secretRedaction.js +675 -0
- package/lib/signalHandler.js +31 -48
- package/package.json +44 -18
- package/pino.d.ts +287 -0
- package/pino.js +434 -13
- package/plugins/README.md +129 -1
- package/plugins/discord.js +30 -48
- package/plugins/index.js +27 -12
- package/plugins/lib/httpDelivery.js +98 -0
- package/plugins/lib/syslogClient.js +18 -8
- package/plugins/mysql.js +73 -83
- package/plugins/openobserve.js +33 -207
- package/plugins/otel.js +5 -7
- package/plugins/postgres.js +69 -67
- package/plugins/sentry.js +36 -3
- package/plugins/syslog.js +6 -9
- package/plugins/teams.js +16 -67
- package/transports/pino.js +188 -12
package/lib/signalHandler.js
CHANGED
|
@@ -1,53 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function setupSignalHandlers(loggerInstances) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const { withTimeout } = require('./lifecycle');
|
|
4
|
+
|
|
5
|
+
// Explicit opt-in: importing a library must not install process exit handlers.
|
|
6
|
+
function setupSignalHandlers(loggerInstances, { timeout = 30000 } = {}) {
|
|
7
|
+
let shuttingDown;
|
|
8
|
+
const shutdown = (code, reason) => {
|
|
9
|
+
if (shuttingDown) return shuttingDown;
|
|
10
|
+
if (reason) console.error(reason);
|
|
11
|
+
shuttingDown = (async () => {
|
|
12
|
+
try {
|
|
13
|
+
const loggers = [...new Set(loggerInstances.values())];
|
|
14
|
+
await withTimeout(Promise.all(loggers.map(logger => logger.close())), timeout, 'Logger shutdown');
|
|
15
|
+
} catch (error) {
|
|
16
|
+
console.error('Logger shutdown failed:', error);
|
|
17
|
+
code = 1;
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
process.exit(code);
|
|
20
|
+
})();
|
|
21
|
+
return shuttingDown;
|
|
22
|
+
};
|
|
23
|
+
const handlers = {
|
|
24
|
+
SIGINT: () => shutdown(0),
|
|
25
|
+
SIGTERM: () => shutdown(0),
|
|
26
|
+
SIGQUIT: () => shutdown(0),
|
|
27
|
+
uncaughtException: error => shutdown(1, error),
|
|
28
|
+
unhandledRejection: reason => shutdown(1, reason),
|
|
29
|
+
};
|
|
30
|
+
for (const [event, handler] of Object.entries(handlers)) process.on(event, handler);
|
|
31
|
+
return () => {
|
|
32
|
+
for (const [event, handler] of Object.entries(handlers)) process.removeListener(event, handler);
|
|
20
33
|
};
|
|
21
|
-
|
|
22
|
-
process.on('SIGINT', () => {
|
|
23
|
-
console.log('Received SIGINT. Exiting...');
|
|
24
|
-
cleanup();
|
|
25
|
-
process.exit(0);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
process.on('SIGTERM', () => {
|
|
29
|
-
console.log('Received SIGTERM. Exiting...');
|
|
30
|
-
cleanup();
|
|
31
|
-
process.exit(0);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
process.on('SIGQUIT', () => {
|
|
35
|
-
console.log('Received SIGQUIT. Exiting...');
|
|
36
|
-
cleanup();
|
|
37
|
-
process.exit(0);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
process.on('uncaughtException', (err) => {
|
|
41
|
-
console.error('Uncaught Exception:', err);
|
|
42
|
-
cleanup();
|
|
43
|
-
process.exit(1);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
process.on('unhandledRejection', (reason, promise) => {
|
|
47
|
-
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
48
|
-
cleanup();
|
|
49
|
-
process.exit(1);
|
|
50
|
-
});
|
|
51
34
|
}
|
|
52
35
|
|
|
53
36
|
module.exports = { setupSignalHandlers };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ntlogger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A Custom Ready-To-Go Logging Wrapper Built on Winston",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"custom logger",
|
|
@@ -30,24 +30,32 @@
|
|
|
30
30
|
"url": "git+https://github.com/NightSquawk/NightTimeLogger.git"
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
|
-
".":
|
|
34
|
-
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./index.d.ts",
|
|
35
|
+
"default": "./index.js"
|
|
36
|
+
},
|
|
37
|
+
"./pino": {
|
|
38
|
+
"types": "./pino.d.ts",
|
|
39
|
+
"default": "./pino.js"
|
|
40
|
+
},
|
|
41
|
+
"./package.json": "./package.json"
|
|
35
42
|
},
|
|
43
|
+
"types": "./index.d.ts",
|
|
36
44
|
"files": [
|
|
37
45
|
"index.js",
|
|
38
46
|
"index.d.ts",
|
|
39
47
|
"pino.js",
|
|
48
|
+
"pino.d.ts",
|
|
40
49
|
"lib/*.js",
|
|
41
50
|
"plugins/**/*",
|
|
42
51
|
"transports/"
|
|
43
52
|
],
|
|
44
53
|
"scripts": {
|
|
45
|
-
"test": "jest"
|
|
54
|
+
"test": "jest",
|
|
55
|
+
"test:coverage": "jest --runInBand --coverage",
|
|
56
|
+
"test:unit": "jest --runInBand --testPathIgnorePatterns=tests/plugins/mysql.test.js tests/plugins/postgres.test.js"
|
|
46
57
|
},
|
|
47
58
|
"dependencies": {
|
|
48
|
-
"@sentry/node": "^10.48.0",
|
|
49
|
-
"mysql2": "^3.22.0",
|
|
50
|
-
"pg": "^8.17.1",
|
|
51
59
|
"winston": "^3.19.0",
|
|
52
60
|
"winston-transport": "^4.9.0"
|
|
53
61
|
},
|
|
@@ -56,17 +64,29 @@
|
|
|
56
64
|
},
|
|
57
65
|
"peerDependencies": {
|
|
58
66
|
"pino": ">=8.0.0",
|
|
67
|
+
"@sentry/node": "^10.74.0",
|
|
68
|
+
"mysql2": "^3.24.4",
|
|
69
|
+
"pg": "^8.23.0",
|
|
59
70
|
"@opentelemetry/api": ">=1.9.0",
|
|
60
|
-
"@opentelemetry/api-logs": "
|
|
61
|
-
"@opentelemetry/sdk-logs": "
|
|
62
|
-
"@opentelemetry/exporter-logs-otlp-http": "
|
|
63
|
-
"@opentelemetry/resources": "
|
|
71
|
+
"@opentelemetry/api-logs": "^0.222.0",
|
|
72
|
+
"@opentelemetry/sdk-logs": "^0.222.0",
|
|
73
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.222.0",
|
|
74
|
+
"@opentelemetry/resources": "^2.11.0",
|
|
64
75
|
"@opentelemetry/semantic-conventions": ">=1.20.0"
|
|
65
76
|
},
|
|
66
77
|
"peerDependenciesMeta": {
|
|
67
78
|
"pino": {
|
|
68
79
|
"optional": true
|
|
69
80
|
},
|
|
81
|
+
"@sentry/node": {
|
|
82
|
+
"optional": true
|
|
83
|
+
},
|
|
84
|
+
"mysql2": {
|
|
85
|
+
"optional": true
|
|
86
|
+
},
|
|
87
|
+
"pg": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
70
90
|
"@opentelemetry/api": {
|
|
71
91
|
"optional": true
|
|
72
92
|
},
|
|
@@ -87,14 +107,20 @@
|
|
|
87
107
|
}
|
|
88
108
|
},
|
|
89
109
|
"devDependencies": {
|
|
90
|
-
"@sentry/
|
|
91
|
-
"@
|
|
92
|
-
"
|
|
110
|
+
"@sentry/node": "^10.74.0",
|
|
111
|
+
"@sentry/profiling-node": "^10.74.0",
|
|
112
|
+
"mysql2": "^3.24.4",
|
|
113
|
+
"pg": "^8.23.0",
|
|
114
|
+
"@testcontainers/mysql": "^12.1.0",
|
|
115
|
+
"@testcontainers/postgresql": "^12.1.0",
|
|
93
116
|
"dotenv": "^17.4.2",
|
|
94
|
-
"jest": "^30.
|
|
95
|
-
"testcontainers": "^
|
|
117
|
+
"jest": "^30.5.1",
|
|
118
|
+
"testcontainers": "^12.1.0",
|
|
119
|
+
"pino": "^10.3.1",
|
|
120
|
+
"@opentelemetry/sdk-logs": "^0.222.0",
|
|
121
|
+
"@opentelemetry/exporter-logs-otlp-http": "^0.222.0"
|
|
96
122
|
},
|
|
97
|
-
"
|
|
98
|
-
"
|
|
123
|
+
"engines": {
|
|
124
|
+
"node": ">=22.22.2"
|
|
99
125
|
}
|
|
100
126
|
}
|
package/pino.d.ts
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript definitions for `ntlogger/pino`
|
|
3
|
+
* @file pino.d.ts
|
|
4
|
+
*
|
|
5
|
+
* The runtime module is CommonJS and its default export is the Pino transport
|
|
6
|
+
* factory itself (so `transport: { target: 'ntlogger/pino' }` keeps working),
|
|
7
|
+
* decorated with the `createLogger()` / process-handler helpers and the
|
|
8
|
+
* formatter internals. That shape maps onto `export =` plus a namespace merge.
|
|
9
|
+
*
|
|
10
|
+
* `pino` is an *optional* peer dependency of ntlogger. Only the type-level
|
|
11
|
+
* imports below depend on it, and every consumer that calls `createLogger()`
|
|
12
|
+
* necessarily has pino installed.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type {
|
|
16
|
+
Bindings,
|
|
17
|
+
ChildLoggerOptions,
|
|
18
|
+
DestinationStream,
|
|
19
|
+
Logger as PinoLogger,
|
|
20
|
+
} from 'pino';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Pino transport factory. Returns the split2 stream Pino's worker writes into.
|
|
24
|
+
*
|
|
25
|
+
* @param opts - Transport options.
|
|
26
|
+
*/
|
|
27
|
+
declare function ntlPinoTransport(opts?: ntlPinoTransport.PinoTransportOptions): NodeJS.ReadWriteStream;
|
|
28
|
+
|
|
29
|
+
declare namespace ntlPinoTransport {
|
|
30
|
+
/**
|
|
31
|
+
* NightTimeLogger log levels, lowest to highest priority.
|
|
32
|
+
* `internal` has no Pino numeric equivalent and is resolved by name.
|
|
33
|
+
*/
|
|
34
|
+
export type NtlLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'internal';
|
|
35
|
+
|
|
36
|
+
/** Options accepted by the transport factory (`transports/pino.js`). */
|
|
37
|
+
export interface PinoTransportOptions {
|
|
38
|
+
/** Label used when a log object carries no `module` / `location` / `name`. */
|
|
39
|
+
defaultModule?: string;
|
|
40
|
+
/** Set to `false` to strip every ANSI escape from the rendered line. */
|
|
41
|
+
colorize?: boolean;
|
|
42
|
+
/** Cap on remembered in-flight HTTP requests (default: 1000). */
|
|
43
|
+
maxInflightRequests?: number;
|
|
44
|
+
/** Max age of a remembered in-flight HTTP request in ms (default: 60000). */
|
|
45
|
+
inflightTtlMs?: number;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A request-start line remembered by the in-flight request tracker. */
|
|
49
|
+
export interface TrackedRequest {
|
|
50
|
+
method: string;
|
|
51
|
+
url: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Bounded, lazily-pruned map of in-flight HTTP requests, used to pair
|
|
56
|
+
* pino-http/Fastify request-start lines with their completion lines.
|
|
57
|
+
*/
|
|
58
|
+
export interface RequestTracker {
|
|
59
|
+
/** Remember an in-flight request. Re-tracking an id refreshes its position. */
|
|
60
|
+
track(id: string, method: string, url: string, now?: number): void;
|
|
61
|
+
/** Look up and forget a tracked request. */
|
|
62
|
+
take(id: string): TrackedRequest | null;
|
|
63
|
+
/** Drop expired entries and enforce the size cap. */
|
|
64
|
+
prune(now?: number): void;
|
|
65
|
+
/** Number of currently tracked requests. */
|
|
66
|
+
readonly size: number;
|
|
67
|
+
/** Resolved cap on tracked requests. */
|
|
68
|
+
readonly maxInflightRequests: number;
|
|
69
|
+
/** Resolved entry TTL in milliseconds. */
|
|
70
|
+
readonly inflightTtlMs: number;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Options for the secret redactor (`lib/secretRedaction.js`). */
|
|
74
|
+
export interface RedactionOptions {
|
|
75
|
+
/** Replace the default key list, or `false` to disable key matching. */
|
|
76
|
+
keys?: string[] | false;
|
|
77
|
+
/** Additional key names to redact, on top of `keys`. */
|
|
78
|
+
extraKeys?: string[];
|
|
79
|
+
/** Replace the default secret-shape patterns, or `false` to disable them. */
|
|
80
|
+
patterns?: RegExp[] | false;
|
|
81
|
+
/** Additional secret-shape patterns, on top of `patterns`. */
|
|
82
|
+
extraPatterns?: RegExp[];
|
|
83
|
+
/** Token substituted for redacted values (default: `'[REDACTED]'`). */
|
|
84
|
+
replacement?: string;
|
|
85
|
+
/** Depth beyond which containers collapse to `'[Object]'` (default: 8). */
|
|
86
|
+
maxDepth?: number;
|
|
87
|
+
/** Length beyond which strings are clipped (default: 16384). */
|
|
88
|
+
maxStringLength?: number;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** Per-level rate limit. `window` and `windowMs` are aliases (default: 60000). */
|
|
92
|
+
export interface RateLimitRule {
|
|
93
|
+
max: number;
|
|
94
|
+
window?: number;
|
|
95
|
+
windowMs?: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Duplicate-message collapsing configuration. */
|
|
99
|
+
export interface DeduplicationOptions {
|
|
100
|
+
/** Set to `false` to disable. Any other object shape enables it. */
|
|
101
|
+
enabled?: boolean;
|
|
102
|
+
/** Occurrences before duplicates are collapsed (default: 3). */
|
|
103
|
+
threshold?: number;
|
|
104
|
+
/** Window in ms. `window` and `windowMs` are aliases (default: 60000). */
|
|
105
|
+
window?: number;
|
|
106
|
+
windowMs?: number;
|
|
107
|
+
/** Restrict deduplication to these levels. */
|
|
108
|
+
levels?: NtlLevel[];
|
|
109
|
+
/** Opt `fatal` in; it is never deduplicated otherwise. */
|
|
110
|
+
fatal?: boolean;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Sampling/rate-limit counters, keyed by level name. */
|
|
114
|
+
export interface SamplingStats {
|
|
115
|
+
total: Record<string, number>;
|
|
116
|
+
sampled: Record<string, number>;
|
|
117
|
+
rateLimited: Record<string, number>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Deduplication counters. */
|
|
121
|
+
export interface DeduplicationStats {
|
|
122
|
+
totalDeduplicated: number;
|
|
123
|
+
uniqueMessages: number;
|
|
124
|
+
activeEntries: number;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Snapshot returned by `logger.getStats()`. Members are `null` when unconfigured. */
|
|
128
|
+
export interface NtlPinoStats {
|
|
129
|
+
sampling: SamplingStats | null;
|
|
130
|
+
deduplication: DeduplicationStats | null;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Result of a bounded logger drain. Never rejects. */
|
|
134
|
+
export interface DrainResult {
|
|
135
|
+
drained: boolean;
|
|
136
|
+
error?: Error | string;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Minimal `process` surface used by `installProcessHandlers`. The real
|
|
141
|
+
* `NodeJS.Process` satisfies it; tests can pass a stub.
|
|
142
|
+
*/
|
|
143
|
+
export interface ProcessLike {
|
|
144
|
+
on(event: string, listener: (...args: any[]) => void): unknown;
|
|
145
|
+
off?(event: string, listener: (...args: any[]) => void): unknown;
|
|
146
|
+
removeListener?(event: string, listener: (...args: any[]) => void): unknown;
|
|
147
|
+
exit?(code?: number): unknown;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Options for `installProcessHandlers()` (`lib/processHandlers.js`). */
|
|
151
|
+
export interface InstallProcessHandlersOptions {
|
|
152
|
+
/** Total shutdown budget in ms, covering the hook and the drain (default: 4000). */
|
|
153
|
+
timeout?: number;
|
|
154
|
+
/** Signals to trap (default: `['SIGTERM', 'SIGINT']`). */
|
|
155
|
+
signals?: string[];
|
|
156
|
+
/** Exit the process after a trapped signal (default: `true`). */
|
|
157
|
+
exitOnSignal?: boolean;
|
|
158
|
+
/** Exit code used for a trapped signal (default: 0). */
|
|
159
|
+
signalExitCode?: number;
|
|
160
|
+
/** Exit code used for `uncaughtException` (default: 1). */
|
|
161
|
+
uncaughtExitCode?: number;
|
|
162
|
+
/** Exit after an unhandled rejection (default: `false`). */
|
|
163
|
+
exitOnUnhandledRejection?: boolean;
|
|
164
|
+
/** Level used to log an unhandled rejection (default: `'error'`). */
|
|
165
|
+
unhandledRejectionLevel?: NtlLevel | (string & {});
|
|
166
|
+
/** User shutdown hook, run before the drain and bounded by `timeout`. */
|
|
167
|
+
onShutdown?: (reason: string) => void | Promise<void>;
|
|
168
|
+
/** Override `process.exit` (primarily for tests). */
|
|
169
|
+
exit?: (code: number) => void;
|
|
170
|
+
/** Override the process object (primarily for tests). */
|
|
171
|
+
proc?: ProcessLike;
|
|
172
|
+
/** Prefix prepended to every message this module logs. */
|
|
173
|
+
logPrefix?: string;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Options for `createLogger()`. */
|
|
177
|
+
export interface CreateLoggerOptions {
|
|
178
|
+
/** Pino level. Defaults to `LOG_LEVEL`, else `debug` in dev / `info` in production. */
|
|
179
|
+
level?: string;
|
|
180
|
+
/** Module label added to every line and used as the transport's default label. */
|
|
181
|
+
module?: string;
|
|
182
|
+
/** Transport label fallback when `module` is not set. */
|
|
183
|
+
defaultModule?: string;
|
|
184
|
+
/** Forwarded to the NTL transport. */
|
|
185
|
+
colorize?: boolean;
|
|
186
|
+
/** Constant top-level `service` field (log-contract core field). */
|
|
187
|
+
service?: string;
|
|
188
|
+
/** Static top-level fields merged into every line. */
|
|
189
|
+
context?: Record<string, unknown>;
|
|
190
|
+
/** Called per log call; its object result is merged at top level. */
|
|
191
|
+
contextProvider?: () => Record<string, unknown> | null | undefined;
|
|
192
|
+
/** When set, only these keys are taken from the provider result. */
|
|
193
|
+
contextKeys?: string[];
|
|
194
|
+
/** Secret redaction. Defaults to on; `false` disables it entirely. */
|
|
195
|
+
redact?: false | string[] | RedactionOptions;
|
|
196
|
+
/** Per-level sampling rates, 0.0 - 1.0. */
|
|
197
|
+
sampling?: Partial<Record<NtlLevel, number>>;
|
|
198
|
+
/** Per-level rate limits. */
|
|
199
|
+
rateLimit?: Partial<Record<NtlLevel, RateLimitRule>>;
|
|
200
|
+
/** Duplicate-message collapsing. `true` enables the defaults. */
|
|
201
|
+
deduplication?: boolean | DeduplicationOptions;
|
|
202
|
+
/** Force silent mode on/off; see `isSilent()`. */
|
|
203
|
+
silent?: boolean;
|
|
204
|
+
/** Opt in to crash/signal handlers. `true` uses the defaults. */
|
|
205
|
+
processHandlers?: boolean | InstallProcessHandlersOptions;
|
|
206
|
+
/** Advanced/tests: a Pino destination. Replaces the NTL transport. */
|
|
207
|
+
destination?: DestinationStream | NodeJS.WritableStream;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* A real Pino logger plus ntlogger's additive API.
|
|
212
|
+
*
|
|
213
|
+
* `getStats` / `resetStats` / `close` / `child` are non-enumerable own
|
|
214
|
+
* properties, so children inherit them through the prototype chain.
|
|
215
|
+
*/
|
|
216
|
+
export interface NtlPinoExtras {
|
|
217
|
+
/** Sampling and deduplication counters. */
|
|
218
|
+
getStats(): NtlPinoStats;
|
|
219
|
+
/** Zero the sampling and deduplication counters. */
|
|
220
|
+
resetStats(): void;
|
|
221
|
+
/**
|
|
222
|
+
* Release sampler/deduplicator timers, then drain the destination.
|
|
223
|
+
* Calling this on a child tears down state shared with its parent.
|
|
224
|
+
*/
|
|
225
|
+
close(timeout?: number): Promise<DrainResult>;
|
|
226
|
+
/** Present only when `processHandlers` was enabled. */
|
|
227
|
+
uninstallProcessHandlers?: () => void;
|
|
228
|
+
/** Child logger with redacted bindings; keeps the ntlogger additions. */
|
|
229
|
+
child(bindings: Bindings, options?: ChildLoggerOptions): NtlPinoLogger;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* The extras are listed first so `child()` resolves to the ntlogger-aware
|
|
234
|
+
* overload; the intersection keeps the value assignable to `pino.Logger`
|
|
235
|
+
* (Fastify's `loggerInstance`, `pino-http`, ...).
|
|
236
|
+
*/
|
|
237
|
+
export type NtlPinoLogger = NtlPinoExtras & PinoLogger;
|
|
238
|
+
|
|
239
|
+
/** Create a pre-configured Pino logger that follows NightTimeLogger conventions. */
|
|
240
|
+
export function createLogger(opts?: CreateLoggerOptions): NtlPinoLogger;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Resolve silent mode: `opts.silent` -> `NTLOGGER_SILENT` -> `NODE_ENV === 'test'`.
|
|
244
|
+
*/
|
|
245
|
+
export function isSilent(opts?: { silent?: boolean }): boolean;
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Install uncaughtException / unhandledRejection / signal handlers.
|
|
249
|
+
* Installing twice for the same logger returns the first uninstall function.
|
|
250
|
+
*
|
|
251
|
+
* @returns Idempotent uninstall function.
|
|
252
|
+
*/
|
|
253
|
+
export function installProcessHandlers(
|
|
254
|
+
logger: object,
|
|
255
|
+
options?: InstallProcessHandlersOptions,
|
|
256
|
+
): () => void;
|
|
257
|
+
|
|
258
|
+
/** Flush whatever the logger supports, bounded by `timeout` ms (default: 5000). Never rejects. */
|
|
259
|
+
export function drainLogger(logger: object, timeout?: number): Promise<DrainResult>;
|
|
260
|
+
|
|
261
|
+
/** Format a single Pino log object into an NTL-style line. */
|
|
262
|
+
export function formatLine(
|
|
263
|
+
obj: Record<string, any>,
|
|
264
|
+
opts?: PinoTransportOptions,
|
|
265
|
+
tracker?: RequestTracker | null,
|
|
266
|
+
): string;
|
|
267
|
+
|
|
268
|
+
/** Format a timestamp as `YYYY-MM-DD HH:mm:ss`. */
|
|
269
|
+
export function formatTimestamp(epoch: number | string | Date): string;
|
|
270
|
+
|
|
271
|
+
/** Pad a level name to 8 characters. */
|
|
272
|
+
export function padLevel(name: string): string;
|
|
273
|
+
|
|
274
|
+
/** Render the `{k=v ...}` structured-context suffix, or `''`. */
|
|
275
|
+
export function formatContext(obj: Record<string, any>): string;
|
|
276
|
+
|
|
277
|
+
/** Create a bounded in-flight HTTP request tracker. */
|
|
278
|
+
export function createRequestTracker(opts?: {
|
|
279
|
+
maxInflightRequests?: number;
|
|
280
|
+
inflightTtlMs?: number;
|
|
281
|
+
}): RequestTracker;
|
|
282
|
+
|
|
283
|
+
/** Context field names rendered by `formatContext()`, in render order. */
|
|
284
|
+
export const CONTEXT_KEYS: readonly string[];
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
export = ntlPinoTransport;
|