1 |
|
2 |
|
3 | import { EventEmitter } from "events";
|
4 |
|
5 | declare class Logger extends EventEmitter {
|
6 | constructor(options: Logger.LoggerOptions);
|
7 | addStream(stream: Logger.Stream): void;
|
8 | addSerializers(serializers: Logger.Serializers): void;
|
9 | child(options: Object, simple?: boolean): Logger;
|
10 | reopenFileStreams(): void;
|
11 |
|
12 | level(): number;
|
13 | level(value: Logger.LogLevel): void;
|
14 | levels(): number[];
|
15 | levels(name: number | string): number;
|
16 | levels(name: number | string, value: Logger.LogLevel): void;
|
17 |
|
18 | fields: any;
|
19 | src: boolean;
|
20 |
|
21 | /**
|
22 | * Returns a boolean: is the `trace` level enabled?
|
23 | *
|
24 | * This is equivalent to `log.isTraceEnabled()` or `log.isEnabledFor(TRACE)` in log4j.
|
25 | */
|
26 | trace(): boolean;
|
27 |
|
28 | /**
|
29 | * Special case to log an `Error` instance to the record.
|
30 | * This adds an `err` field with exception details
|
31 | * (including the stack) and sets `msg` to the exception
|
32 | * message or you can specify the `msg`.
|
33 | */
|
34 | trace(error: Error, ...params: any[]): void;
|
35 |
|
36 | /**
|
37 | * The first field can optionally be a "fields" object, which
|
38 | * is merged into the log record.
|
39 | *
|
40 | * To pass in an Error *and* other fields, use the `err`
|
41 | * field name for the Error instance.
|
42 | */
|
43 | trace(obj: Object, ...params: any[]): void;
|
44 |
|
45 | /**
|
46 | * Uses `util.format` for msg formatting.
|
47 | */
|
48 | trace(format: any, ...params: any[]): void;
|
49 |
|
50 | /**
|
51 | * Returns a boolean: is the `debug` level enabled?
|
52 | *
|
53 | * This is equivalent to `log.isDebugEnabled()` or `log.isEnabledFor(DEBUG)` in log4j.
|
54 | */
|
55 | debug(): boolean;
|
56 |
|
57 | /**
|
58 | * Special case to log an `Error` instance to the record.
|
59 | * This adds an `err` field with exception details
|
60 | * (including the stack) and sets `msg` to the exception
|
61 | * message or you can specify the `msg`.
|
62 | */
|
63 | debug(error: Error, ...params: any[]): void;
|
64 |
|
65 | /**
|
66 | * The first field can optionally be a "fields" object, which
|
67 | * is merged into the log record.
|
68 | *
|
69 | * To pass in an Error *and* other fields, use the `err`
|
70 | * field name for the Error instance.
|
71 | */
|
72 | debug(obj: Object, ...params: any[]): void;
|
73 |
|
74 | /**
|
75 | * Uses `util.format` for msg formatting.
|
76 | */
|
77 | debug(format: any, ...params: any[]): void;
|
78 |
|
79 | /**
|
80 | * Returns a boolean: is the `info` level enabled?
|
81 | *
|
82 | * This is equivalent to `log.isInfoEnabled()` or `log.isEnabledFor(INFO)` in log4j.
|
83 | */
|
84 | info(): boolean;
|
85 |
|
86 | /**
|
87 | * Special case to log an `Error` instance to the record.
|
88 | * This adds an `err` field with exception details
|
89 | * (including the stack) and sets `msg` to the exception
|
90 | * message or you can specify the `msg`.
|
91 | */
|
92 | info(error: Error, ...params: any[]): void;
|
93 |
|
94 | /**
|
95 | * The first field can optionally be a "fields" object, which
|
96 | * is merged into the log record.
|
97 | *
|
98 | * To pass in an Error *and* other fields, use the `err`
|
99 | * field name for the Error instance.
|
100 | */
|
101 | info(obj: Object, ...params: any[]): void;
|
102 |
|
103 | /**
|
104 | * Uses `util.format` for msg formatting.
|
105 | */
|
106 | info(format: any, ...params: any[]): void;
|
107 |
|
108 | /**
|
109 | * Returns a boolean: is the `warn` level enabled?
|
110 | *
|
111 | * This is equivalent to `log.isWarnEnabled()` or `log.isEnabledFor(WARN)` in log4j.
|
112 | */
|
113 | warn(): boolean;
|
114 |
|
115 | /**
|
116 | * Special case to log an `Error` instance to the record.
|
117 | * This adds an `err` field with exception details
|
118 | * (including the stack) and sets `msg` to the exception
|
119 | * message or you can specify the `msg`.
|
120 | */
|
121 | warn(error: Error, ...params: any[]): void;
|
122 |
|
123 | /**
|
124 | * The first field can optionally be a "fields" object, which
|
125 | * is merged into the log record.
|
126 | *
|
127 | * To pass in an Error *and* other fields, use the `err`
|
128 | * field name for the Error instance.
|
129 | */
|
130 | warn(obj: Object, ...params: any[]): void;
|
131 |
|
132 | /**
|
133 | * Uses `util.format` for msg formatting.
|
134 | */
|
135 | warn(format: any, ...params: any[]): void;
|
136 |
|
137 | /**
|
138 | * Returns a boolean: is the `error` level enabled?
|
139 | *
|
140 | * This is equivalent to `log.isErrorEnabled()` or `log.isEnabledFor(ERROR)` in log4j.
|
141 | */
|
142 | error(): boolean;
|
143 |
|
144 | /**
|
145 | * Special case to log an `Error` instance to the record.
|
146 | * This adds an `err` field with exception details
|
147 | * (including the stack) and sets `msg` to the exception
|
148 | * message or you can specify the `msg`.
|
149 | */
|
150 | error(error: Error, ...params: any[]): void;
|
151 |
|
152 | /**
|
153 | * The first field can optionally be a "fields" object, which
|
154 | * is merged into the log record.
|
155 | *
|
156 | * To pass in an Error *and* other fields, use the `err`
|
157 | * field name for the Error instance.
|
158 | */
|
159 | error(obj: Object, ...params: any[]): void;
|
160 |
|
161 | /**
|
162 | * Uses `util.format` for msg formatting.
|
163 | */
|
164 | error(format: any, ...params: any[]): void;
|
165 |
|
166 | /**
|
167 | * Returns a boolean: is the `fatal` level enabled?
|
168 | *
|
169 | * This is equivalent to `log.isFatalEnabled()` or `log.isEnabledFor(FATAL)` in log4j.
|
170 | */
|
171 | fatal(): boolean;
|
172 |
|
173 | /**
|
174 | * Special case to log an `Error` instance to the record.
|
175 | * This adds an `err` field with exception details
|
176 | * (including the stack) and sets `msg` to the exception
|
177 | * message or you can specify the `msg`.
|
178 | */
|
179 | fatal(error: Error, ...params: any[]): void;
|
180 |
|
181 | /**
|
182 | * The first field can optionally be a "fields" object, which
|
183 | * is merged into the log record.
|
184 | *
|
185 | * To pass in an Error *and* other fields, use the `err`
|
186 | * field name for the Error instance.
|
187 | */
|
188 | fatal(obj: Object, ...params: any[]): void;
|
189 |
|
190 | /**
|
191 | * Uses `util.format` for msg formatting.
|
192 | */
|
193 | fatal(format: any, ...params: any[]): void;
|
194 | }
|
195 |
|
196 | declare namespace Logger {
|
197 | const TRACE: number;
|
198 | const DEBUG: number;
|
199 | const INFO: number;
|
200 | const WARN: number;
|
201 | const ERROR: number;
|
202 | const FATAL: number;
|
203 |
|
204 | type LogLevelString = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
205 | type LogLevel = LogLevelString | number;
|
206 |
|
207 | const levelFromName: { [name in LogLevelString]: number };
|
208 | const nameFromLevel: { [level: number]: string };
|
209 |
|
210 | const stdSerializers: StdSerializers;
|
211 |
|
212 | function createLogger(options: LoggerOptions): Logger;
|
213 |
|
214 | function safeCycles(): (key: string, value: any) => any;
|
215 |
|
216 | function resolveLevel(value: LogLevel): number;
|
217 |
|
218 | interface WriteFn {
|
219 | write: (object: Object) => void;
|
220 | }
|
221 |
|
222 | interface Stream {
|
223 | type?: string | undefined;
|
224 | level?: LogLevel | undefined;
|
225 | path?: string | undefined;
|
226 | stream?: NodeJS.WritableStream | WriteFn | undefined;
|
227 | closeOnExit?: boolean | undefined;
|
228 | period?: string | undefined;
|
229 | count?: number | undefined;
|
230 | name?: string | undefined;
|
231 | reemitErrorEvents?: boolean | undefined;
|
232 | }
|
233 |
|
234 | interface LoggerOptions {
|
235 | name: string;
|
236 | streams?: Stream[] | undefined;
|
237 | level?: LogLevel | undefined;
|
238 | stream?: NodeJS.WritableStream | undefined;
|
239 | serializers?: Serializers | undefined;
|
240 | src?: boolean | undefined;
|
241 | [custom: string]: any;
|
242 | }
|
243 |
|
244 | type Serializer = (input: any) => any;
|
245 |
|
246 | interface Serializers {
|
247 | [key: string]: Serializer;
|
248 | }
|
249 |
|
250 | interface StdSerializers extends Serializers {
|
251 | err: Serializer;
|
252 | res: Serializer;
|
253 | req: Serializer;
|
254 | }
|
255 |
|
256 | interface RingBufferOptions {
|
257 | limit?: number | undefined;
|
258 | }
|
259 |
|
260 | class RingBuffer extends EventEmitter {
|
261 | constructor(options: RingBufferOptions);
|
262 |
|
263 | writable: boolean;
|
264 | records: any[];
|
265 |
|
266 | write(record: any): boolean;
|
267 | end(record?: any): void;
|
268 | destroy(): void;
|
269 | destroySoon(): void;
|
270 | }
|
271 |
|
272 | interface RotatingFileStreamOptions {
|
273 | path: string;
|
274 | count?: number | undefined;
|
275 | period?: string | undefined;
|
276 | }
|
277 |
|
278 | class RotatingFileStream extends EventEmitter {
|
279 | constructor(options: RotatingFileStreamOptions);
|
280 |
|
281 | writable: boolean;
|
282 | periodNum: number;
|
283 | periodScope: string;
|
284 | stream: any;
|
285 | rotQueue: any[];
|
286 | rotating: boolean;
|
287 |
|
288 | write(record: any): boolean;
|
289 | end(record?: any): void;
|
290 | destroy(): void;
|
291 | destroySoon(): void;
|
292 | rotate(): void;
|
293 | }
|
294 | }
|
295 |
|
296 | export = Logger;
|