/
log4js.d.ts
450 lines (389 loc) · 12.2 KB
/
log4js.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
// Type definitions for log4js
type Format =
| string
| ((req: any, res: any, formatter: (str: string) => string) => string);
export interface Log4js {
getLogger(category?: string): Logger;
configure(filename: string): Log4js;
configure(config: Configuration): Log4js;
addLayout(
name: string,
config: (a: any) => (logEvent: LoggingEvent) => string
): void;
connectLogger(
logger: Logger,
options: { format?: Format; level?: string; nolog?: any }
): any; // express.Handler;
levels: Levels;
shutdown(cb: (error: Error) => void): void | null;
}
export function getLogger(category?: string): Logger;
export function configure(filename: string): Log4js;
export function configure(config: Configuration): Log4js;
export function addLayout(
name: string,
config: (a: any) => (logEvent: LoggingEvent) => any
): void;
export function connectLogger(
logger: Logger,
options: {
format?: Format;
level?: string;
nolog?: any;
statusRules?: any[];
context?: boolean;
}
): any; // express.Handler;
export function recording(): Recording;
export const levels: Levels;
export function shutdown(cb?: (error: Error) => void): void | null;
export interface BasicLayout {
type: 'basic';
}
export interface ColoredLayout {
type: 'colored' | 'coloured';
}
export interface MessagePassThroughLayout {
type: 'messagePassThrough';
}
export interface DummyLayout {
type: 'dummy';
}
export interface Level {
isEqualTo(other: string): boolean;
isEqualTo(otherLevel: Level): boolean;
isLessThanOrEqualTo(other: string): boolean;
isLessThanOrEqualTo(otherLevel: Level): boolean;
isGreaterThanOrEqualTo(other: string): boolean;
isGreaterThanOrEqualTo(otherLevel: Level): boolean;
colour: string;
level: number;
levelStr: string;
}
export interface LoggingEvent {
categoryName: string; // name of category
level: Level; // level of message
data: any[]; // objects to log
startTime: Date;
pid: number;
context: any;
cluster?: {
workerId: number;
worker: number;
};
functionName?: string;
fileName?: string;
lineNumber?: number;
columnNumber?: number;
callStack?: string;
serialise(): string;
}
export type Token = ((logEvent: LoggingEvent) => string) | string;
export interface PatternLayout {
type: 'pattern';
// specifier for the output format, using placeholders as described below
pattern: string;
// user-defined tokens to be used in the pattern
tokens?: { [name: string]: Token };
}
export interface CustomLayout {
[key: string]: any;
type: string;
}
export type Layout =
| BasicLayout
| ColoredLayout
| MessagePassThroughLayout
| DummyLayout
| PatternLayout
| CustomLayout;
/**
* Category Filter
*
* @see https://log4js-node.github.io/log4js-node/categoryFilter.html
*/
export interface CategoryFilterAppender {
type: 'categoryFilter';
// the category (or categories if you provide an array of values) that will be excluded from the appender.
exclude?: string | string[];
// the name of the appender to filter. see https://log4js-node.github.io/log4js-node/layouts.html
appender?: string;
}
/**
* No Log Filter
*
* @see https://log4js-node.github.io/log4js-node/noLogFilter.html
*/
export interface NoLogFilterAppender {
type: 'noLogFilter';
// the regular expression (or the regular expressions if you provide an array of values)
// will be used for evaluating the events to pass to the appender.
// The events, which will match the regular expression, will be excluded and so not logged.
exclude: string | string[];
// the name of an appender, defined in the same configuration, that you want to filter.
appender: string;
}
/**
* Console Appender
*
* @see https://log4js-node.github.io/log4js-node/console.html
*/
export interface ConsoleAppender {
type: 'console';
// (defaults to ColoredLayout)
layout?: Layout;
}
export interface FileAppender {
type: 'file';
// the path of the file where you want your logs written.
filename: string;
// (defaults to undefined) the maximum size (in bytes) for the log file. If not specified or 0, then no log rolling will happen.
maxLogSize?: number | string;
// (defaults to 5) the number of old log files to keep (excluding the hot file).
backups?: number;
// (defaults to BasicLayout)
layout?: Layout;
// (defaults to utf-8)
encoding?: string;
// (defaults to 0o600)
mode?: number;
// (defaults to a)
flags?: string;
// (defaults to false) compress the backup files using gzip (backup files will have .gz extension)
compress?: boolean;
// (defaults to false) preserve the file extension when rotating log files (`file.log` becomes `file.1.log` instead of `file.log.1`).
keepFileExt?: boolean;
// (defaults to .) the filename separator when rolling. e.g.: abc.log`.`1 or abc`.`1.log (keepFileExt)
fileNameSep?: string;
}
export interface SyncfileAppender {
type: 'fileSync';
// the path of the file where you want your logs written.
filename: string;
// (defaults to undefined) the maximum size (in bytes) for the log file. If not specified or 0, then no log rolling will happen.
maxLogSize?: number | string;
// (defaults to 5) the number of old log files to keep (excluding the hot file).
backups?: number;
// (defaults to BasicLayout)
layout?: Layout;
// (defaults to utf-8)
encoding?: string;
// (defaults to 0o600)
mode?: number;
// (defaults to a)
flags?: string;
}
export interface DateFileAppender {
type: 'dateFile';
// the path of the file where you want your logs written.
filename: string;
// (defaults to yyyy-MM-dd) the pattern to use to determine when to roll the logs.
/**
* The following strings are recognised in the pattern:
* - yyyy : the full year, use yy for just the last two digits
* - MM : the month
* - dd : the day of the month
* - hh : the hour of the day (24-hour clock)
* - mm : the minute of the hour
* - ss : seconds
* - SSS : milliseconds (although I'm not sure you'd want to roll your logs every millisecond)
* - O : timezone (capital letter o)
*/
pattern?: string;
// (defaults to BasicLayout)
layout?: Layout;
// (defaults to utf-8)
encoding?: string;
// (defaults to 0o600)
mode?: number;
// (defaults to a)
flags?: string;
// (defaults to false) compress the backup files using gzip (backup files will have .gz extension)
compress?: boolean;
// (defaults to false) preserve the file extension when rotating log files (`file.log` becomes `file.2017-05-30.log` instead of `file.log.2017-05-30`).
keepFileExt?: boolean;
// (defaults to .) the filename separator when rolling. e.g.: abc.log`.`2013-08-30 or abc`.`2013-08-30.log (keepFileExt)
fileNameSep?: string;
// (defaults to false) include the pattern in the name of the current log file.
alwaysIncludePattern?: boolean;
// (defaults to 1) the number of old files that matches the pattern to keep (excluding the hot file).
numBackups?: number;
}
export interface LogLevelFilterAppender {
type: 'logLevelFilter';
// the name of an appender, defined in the same configuration, that you want to filter
appender: string;
// the minimum level of event to allow through the filter
level: string;
// (defaults to FATAL) the maximum level of event to allow through the filter
maxLevel?: string;
}
export interface MultiFileAppender {
type: 'multiFile';
// the base part of the generated log filename
base: string;
// the value to use to split files (see below).
property: string;
// the suffix for the generated log filename.
extension: string;
}
export interface MultiprocessAppender {
type: 'multiprocess';
// controls whether the appender listens for log events sent over the network, or is responsible for serialising events and sending them to a server.
mode: 'master' | 'worker';
// (only needed if mode == master) the name of the appender to send the log events to
appender?: string;
// (defaults to 5000) the port to listen on, or send to
loggerPort?: number;
// (defaults to localhost) the host/IP address to listen on, or send to
loggerHost?: string;
}
export interface RecordingAppender {
type: 'recording';
}
export interface StandardErrorAppender {
type: 'stderr';
// (defaults to ColoredLayout)
layout?: Layout;
}
export interface StandardOutputAppender {
type: 'stdout';
// (defaults to ColoredLayout)
layout?: Layout;
}
/**
* TCP Appender
*
* @see https://log4js-node.github.io/log4js-node/tcp.html
*/
export interface TCPAppender {
type: 'tcp';
// (defaults to 5000)
port?: number;
// (defaults to localhost)
host?: string;
// (defaults to __LOG4JS__)
endMsg?: string;
// (defaults to a serialized log event)
layout?: Layout;
}
export interface CustomAppender {
type: string | AppenderModule;
[key: string]: any;
}
/**
* Mapping of all Appenders to allow for declaration merging
* @example
* declare module 'log4js' {
* interface Appenders {
* StorageTestAppender: {
* type: 'storageTest';
* storageMedium: 'dvd' | 'usb' | 'hdd';
* };
* }
* }
*/
export interface Appenders {
CategoryFilterAppender: CategoryFilterAppender;
ConsoleAppender: ConsoleAppender;
FileAppender: FileAppender;
SyncfileAppender: SyncfileAppender;
DateFileAppender: DateFileAppender;
LogLevelFilterAppender: LogLevelFilterAppender;
NoLogFilterAppender: NoLogFilterAppender;
MultiFileAppender: MultiFileAppender;
MultiprocessAppender: MultiprocessAppender;
RecordingAppender: RecordingAppender;
StandardErrorAppender: StandardErrorAppender;
StandardOutputAppender: StandardOutputAppender;
TCPAppender: TCPAppender;
CustomAppender: CustomAppender;
}
export interface AppenderModule {
configure: (
config?: Config,
layouts?: LayoutsParam,
findAppender?: () => AppenderFunction,
levels?: Levels
) => AppenderFunction;
}
export type AppenderFunction = (loggingEvent: LoggingEvent) => void;
// TODO: Actually add types here...
// It's supposed to be the full config element
export type Config = any;
export interface LayoutsParam {
basicLayout: LayoutFunction;
messagePassThroughLayout: LayoutFunction;
patternLayout: LayoutFunction;
colouredLayout: LayoutFunction;
coloredLayout: LayoutFunction;
dummyLayout: LayoutFunction;
addLayout: (name: string, serializerGenerator: LayoutFunction) => void;
layout: (name: string, config: PatternToken) => LayoutFunction;
}
export interface PatternToken {
pattern: string; // TODO type this to enforce good pattern...
tokens: { [tokenName: string]: () => any };
}
export type LayoutFunction = (loggingEvent: LoggingEvent) => string;
export type Appender = Appenders[keyof Appenders];
export interface Levels {
ALL: Level;
MARK: Level;
TRACE: Level;
DEBUG: Level;
INFO: Level;
WARN: Level;
ERROR: Level;
FATAL: Level;
OFF: Level;
levels: Level[];
getLevel(level: Level | string, defaultLevel?: Level): Level;
addLevels(customLevels: object): void;
}
export interface Configuration {
appenders: { [name: string]: Appender };
categories: {
[name: string]: {
appenders: string[];
level: string;
enableCallStack?: boolean;
};
};
pm2?: boolean;
pm2InstanceVar?: string;
levels?: Levels;
disableClustering?: boolean;
}
export interface Recording {
configure(): AppenderFunction;
replay(): LoggingEvent[];
playback(): LoggingEvent[];
reset(): void;
erase(): void;
}
export interface Logger {
new (name: string): Logger;
readonly category: string;
level: Level | string;
log(level: Level | string, ...args: any[]): void;
isLevelEnabled(level?: string): boolean;
isTraceEnabled(): boolean;
isDebugEnabled(): boolean;
isInfoEnabled(): boolean;
isWarnEnabled(): boolean;
isErrorEnabled(): boolean;
isFatalEnabled(): boolean;
_log(level: Level, data: any): void;
addContext(key: string, value: any): void;
removeContext(key: string): void;
clearContext(): void;
setParseCallStackFunction(parseFunction: Function): void;
trace(message: any, ...args: any[]): void;
debug(message: any, ...args: any[]): void;
info(message: any, ...args: any[]): void;
warn(message: any, ...args: any[]): void;
error(message: any, ...args: any[]): void;
fatal(message: any, ...args: any[]): void;
mark(message: any, ...args: any[]): void;
}