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