1 | // Type definitions for log4js
|
---|
2 |
|
---|
3 | type Format = string | ((req: any, res: any, formatter: ((str: string) => string)) => string);
|
---|
4 |
|
---|
5 | export interface Log4js {
|
---|
6 | getLogger(category?: string): Logger;
|
---|
7 | configure(filename: string): Log4js;
|
---|
8 | configure(config: Configuration): Log4js;
|
---|
9 | addLayout(name: string, config: (a: any) => (logEvent: LoggingEvent) => string): void;
|
---|
10 | connectLogger(logger: Logger, options: { format?: Format; level?: string; nolog?: any; }): any; // express.Handler;
|
---|
11 | levels: Levels;
|
---|
12 | shutdown(cb: (error: Error) => void): void | null;
|
---|
13 | }
|
---|
14 |
|
---|
15 | export function getLogger(category?: string): Logger;
|
---|
16 |
|
---|
17 | export function configure(filename: string): Log4js;
|
---|
18 | export function configure(config: Configuration): Log4js;
|
---|
19 |
|
---|
20 | export function addLayout(name: string, config: (a: any) => (logEvent: LoggingEvent) => any): void;
|
---|
21 |
|
---|
22 | export function connectLogger(logger: Logger, options: { format?: Format; level?: string; nolog?: any; statusRules?: any[], context?: boolean }): any; // express.Handler;
|
---|
23 |
|
---|
24 | export const levels: Levels;
|
---|
25 |
|
---|
26 | export function shutdown(cb?: (error: Error) => void): void | null;
|
---|
27 |
|
---|
28 | export interface BaseLayout {
|
---|
29 | type: 'basic';
|
---|
30 | }
|
---|
31 |
|
---|
32 | export interface ColoredLayout {
|
---|
33 | type: 'colored' | 'coloured';
|
---|
34 | }
|
---|
35 |
|
---|
36 | export interface MessagePassThroughLayout {
|
---|
37 | type: 'messagePassThrough';
|
---|
38 | }
|
---|
39 |
|
---|
40 | export interface DummyLayout {
|
---|
41 | type: 'dummy';
|
---|
42 | }
|
---|
43 |
|
---|
44 | export interface Level {
|
---|
45 | isEqualTo(other: string): boolean;
|
---|
46 | isEqualTo(otherLevel: Level): boolean;
|
---|
47 | isLessThanOrEqualTo(other: string): boolean;
|
---|
48 | isLessThanOrEqualTo(otherLevel: Level): boolean;
|
---|
49 | isGreaterThanOrEqualTo(other: string): boolean;
|
---|
50 | isGreaterThanOrEqualTo(otherLevel: Level): boolean;
|
---|
51 | colour: string;
|
---|
52 | level: number;
|
---|
53 | levelStr: string;
|
---|
54 | }
|
---|
55 |
|
---|
56 | export interface LoggingEvent {
|
---|
57 | categoryName: string; // name of category
|
---|
58 | level: Level; // level of message
|
---|
59 | data: any[]; // objects to log
|
---|
60 | startTime: Date;
|
---|
61 | pid: number;
|
---|
62 | context: any;
|
---|
63 | cluster?: {
|
---|
64 | workerId: number;
|
---|
65 | worker: number;
|
---|
66 | };
|
---|
67 | }
|
---|
68 |
|
---|
69 | export type Token = ((logEvent: LoggingEvent) => string) | string;
|
---|
70 |
|
---|
71 | export interface PatternLayout {
|
---|
72 | type: 'pattern';
|
---|
73 | // specifier for the output format, using placeholders as described below
|
---|
74 | pattern: string;
|
---|
75 | // user-defined tokens to be used in the pattern
|
---|
76 | tokens?: { [name: string]: Token };
|
---|
77 | }
|
---|
78 |
|
---|
79 | export interface CustomLayout {
|
---|
80 | [key: string]: any;
|
---|
81 | type: string;
|
---|
82 | }
|
---|
83 |
|
---|
84 | export type Layout = BaseLayout | ColoredLayout | MessagePassThroughLayout | DummyLayout | PatternLayout | CustomLayout;
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Category Filter
|
---|
88 | *
|
---|
89 | * @see https://log4js-node.github.io/log4js-node/categoryFilter.html
|
---|
90 | */
|
---|
91 | export interface CategoryFilterAppender {
|
---|
92 | type: "categoryFilter";
|
---|
93 | // the category (or categories if you provide an array of values) that will be excluded from the appender.
|
---|
94 | exclude?: string | string[];
|
---|
95 | // the name of the appender to filter. see https://log4js-node.github.io/log4js-node/layouts.html
|
---|
96 | appender?: string;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * No Log Filter
|
---|
101 | *
|
---|
102 | * @see https://log4js-node.github.io/log4js-node/noLogFilter.html
|
---|
103 | */
|
---|
104 | export interface NoLogFilterAppender {
|
---|
105 | type: "noLogFilter";
|
---|
106 | // the regular expression (or the regular expressions if you provide an array of values)
|
---|
107 | // will be used for evaluating the events to pass to the appender.
|
---|
108 | // The events, which will match the regular expression, will be excluded and so not logged.
|
---|
109 | exclude: string | string[];
|
---|
110 | // the name of an appender, defined in the same configuration, that you want to filter.
|
---|
111 | appender: string;
|
---|
112 | }
|
---|
113 |
|
---|
114 | /**
|
---|
115 | * Console Appender
|
---|
116 | *
|
---|
117 | * @see https://log4js-node.github.io/log4js-node/console.html
|
---|
118 | */
|
---|
119 | export interface ConsoleAppender {
|
---|
120 | type: 'console';
|
---|
121 | // defaults to colouredLayout
|
---|
122 | layout?: Layout;
|
---|
123 | }
|
---|
124 |
|
---|
125 | export interface FileAppender {
|
---|
126 | type: 'file';
|
---|
127 | // the path of the file where you want your logs written.
|
---|
128 | filename: string;
|
---|
129 | // the maximum size (in bytes) for the log file. If not specified, then no log rolling will happen.
|
---|
130 | maxLogSize?: number | string;
|
---|
131 | // (default value = 5) - the number of old log files to keep during log rolling.
|
---|
132 | backups?: number;
|
---|
133 | // defaults to basic layout
|
---|
134 | layout?: Layout;
|
---|
135 | numBackups?: number;
|
---|
136 | compress?: boolean; // compress the backups
|
---|
137 | // keep the file extension when rotating logs
|
---|
138 | keepFileExt?: boolean;
|
---|
139 | encoding?: string;
|
---|
140 | mode?: number;
|
---|
141 | flags?: string;
|
---|
142 | }
|
---|
143 |
|
---|
144 | export interface SyncfileAppender {
|
---|
145 | type: 'fileSync';
|
---|
146 | // the path of the file where you want your logs written.
|
---|
147 | filename: string;
|
---|
148 | // the maximum size (in bytes) for the log file. If not specified, then no log rolling will happen.
|
---|
149 | maxLogSize?: number | string;
|
---|
150 | // (default value = 5) - the number of old log files to keep during log rolling.
|
---|
151 | backups?: number;
|
---|
152 | // defaults to basic layout
|
---|
153 | layout?: Layout;
|
---|
154 | }
|
---|
155 |
|
---|
156 | export interface DateFileAppender {
|
---|
157 | type: 'dateFile';
|
---|
158 | // the path of the file where you want your logs written.
|
---|
159 | filename: string;
|
---|
160 | // defaults to basic layout
|
---|
161 | layout?: Layout;
|
---|
162 | // defaults to .yyyy-MM-dd - the pattern to use to determine when to roll the logs.
|
---|
163 | /**
|
---|
164 | * The following strings are recognised in the pattern:
|
---|
165 | * - yyyy : the full year, use yy for just the last two digits
|
---|
166 | * - MM : the month
|
---|
167 | * - dd : the day of the month
|
---|
168 | * - hh : the hour of the day (24-hour clock)
|
---|
169 | * - mm : the minute of the hour
|
---|
170 | * - ss : seconds
|
---|
171 | * - SSS : milliseconds (although I'm not sure you'd want to roll your logs every millisecond)
|
---|
172 | * - O : timezone (capital letter o)
|
---|
173 | */
|
---|
174 | pattern?: string;
|
---|
175 | // default “utf-8”
|
---|
176 | encoding?: string;
|
---|
177 | // default 0644
|
---|
178 | mode?: number;
|
---|
179 | // default ‘a’
|
---|
180 | flags?: string;
|
---|
181 | // compress the backup files during rolling (backup files will have .gz extension)(default false)
|
---|
182 | compress?: boolean;
|
---|
183 | // include the pattern in the name of the current log file as well as the backups.(default false)
|
---|
184 | alwaysIncludePattern?: boolean;
|
---|
185 | // keep the file extension when rotating logs
|
---|
186 | keepFileExt?: boolean;
|
---|
187 | // if this value is greater than zero, then files older than that many days will be deleted during log rolling.(default 0)
|
---|
188 | daysToKeep?: number;
|
---|
189 | }
|
---|
190 |
|
---|
191 | export interface LogLevelFilterAppender {
|
---|
192 | type: 'logLevelFilter';
|
---|
193 | // the name of an appender, defined in the same configuration, that you want to filter
|
---|
194 | appender: string;
|
---|
195 | // the minimum level of event to allow through the filter
|
---|
196 | level: string;
|
---|
197 | // (defaults to FATAL) - the maximum level of event to allow through the filter
|
---|
198 | maxLevel?: string;
|
---|
199 | }
|
---|
200 |
|
---|
201 | export interface MultiFileAppender {
|
---|
202 | type: 'multiFile';
|
---|
203 | // the base part of the generated log filename
|
---|
204 | base: string;
|
---|
205 | // the value to use to split files (see below).
|
---|
206 | property: string;
|
---|
207 | // the suffix for the generated log filename.
|
---|
208 | extension: string;
|
---|
209 | }
|
---|
210 |
|
---|
211 | export interface MultiprocessAppender {
|
---|
212 | type: 'multiprocess';
|
---|
213 | // controls whether the appender listens for log events sent over the network, or is responsible for serialising events and sending them to a server.
|
---|
214 | mode: 'master' | 'worker';
|
---|
215 | // (only needed if mode == master)- the name of the appender to send the log events to
|
---|
216 | appender?: string;
|
---|
217 | // (defaults to 5000) - the port to listen on, or send to
|
---|
218 | loggerPort?: number;
|
---|
219 | // (defaults to localhost) - the host/IP address to listen on, or send to
|
---|
220 | loggerHost?: string;
|
---|
221 | }
|
---|
222 |
|
---|
223 | export interface RecordingAppender {
|
---|
224 | type: 'recording';
|
---|
225 | }
|
---|
226 |
|
---|
227 | export interface StandardErrorAppender {
|
---|
228 | type: 'stderr';
|
---|
229 | // (defaults to colouredLayout)
|
---|
230 | layout?: Layout;
|
---|
231 | }
|
---|
232 |
|
---|
233 | export interface StandardOutputAppender {
|
---|
234 | type: 'stdout';
|
---|
235 | // (defaults to colouredLayout)
|
---|
236 | layout?: Layout;
|
---|
237 | }
|
---|
238 |
|
---|
239 | export interface CustomAppender {
|
---|
240 | type: string | AppenderModule;
|
---|
241 | [key: string]: any;
|
---|
242 | }
|
---|
243 |
|
---|
244 | export interface AppenderModule {
|
---|
245 | configure: Function
|
---|
246 | }
|
---|
247 |
|
---|
248 | export type Appender = CategoryFilterAppender
|
---|
249 | | ConsoleAppender
|
---|
250 | | FileAppender
|
---|
251 | | SyncfileAppender
|
---|
252 | | DateFileAppender
|
---|
253 | | LogLevelFilterAppender
|
---|
254 | | NoLogFilterAppender
|
---|
255 | | MultiFileAppender
|
---|
256 | | MultiprocessAppender
|
---|
257 | | RecordingAppender
|
---|
258 | | StandardErrorAppender
|
---|
259 | | StandardOutputAppender
|
---|
260 | | CustomAppender;
|
---|
261 |
|
---|
262 | export interface Levels {
|
---|
263 | ALL: Level;
|
---|
264 | MARK: Level;
|
---|
265 | TRACE: Level;
|
---|
266 | DEBUG: Level;
|
---|
267 | INFO: Level;
|
---|
268 | WARN: Level;
|
---|
269 | ERROR: Level;
|
---|
270 | FATAL: Level;
|
---|
271 | OFF: Level;
|
---|
272 | levels: Level[];
|
---|
273 | getLevel(level: string): Level;
|
---|
274 | addLevels(customLevels: object): void;
|
---|
275 | }
|
---|
276 |
|
---|
277 | export interface Configuration {
|
---|
278 | appenders: { [name: string]: Appender; };
|
---|
279 | categories: { [name: string]: { appenders: string[]; level: string; enableCallStack?: boolean; } };
|
---|
280 | pm2?: boolean;
|
---|
281 | pm2InstanceVar?: string;
|
---|
282 | levels?: Levels;
|
---|
283 | disableClustering?: boolean;
|
---|
284 | }
|
---|
285 |
|
---|
286 | export class Logger {
|
---|
287 | new(dispatch: Function, name: string): Logger;
|
---|
288 |
|
---|
289 | readonly category: string;
|
---|
290 | level: string;
|
---|
291 |
|
---|
292 | log(...args: any[]): void;
|
---|
293 |
|
---|
294 | isLevelEnabled(level?: string): boolean;
|
---|
295 |
|
---|
296 | isTraceEnabled(): boolean;
|
---|
297 | isDebugEnabled(): boolean;
|
---|
298 | isInfoEnabled(): boolean;
|
---|
299 | isWarnEnabled(): boolean;
|
---|
300 | isErrorEnabled(): boolean;
|
---|
301 | isFatalEnabled(): boolean;
|
---|
302 |
|
---|
303 | _log(level: string, data: any): void;
|
---|
304 |
|
---|
305 | addContext(key: string, value: any): void;
|
---|
306 |
|
---|
307 | removeContext(key: string): void;
|
---|
308 |
|
---|
309 | clearContext(): void;
|
---|
310 |
|
---|
311 | setParseCallStackFunction(parseFunction: Function): void;
|
---|
312 |
|
---|
313 | trace(message: any, ...args: any[]): void;
|
---|
314 |
|
---|
315 | debug(message: any, ...args: any[]): void;
|
---|
316 |
|
---|
317 | info(message: any, ...args: any[]): void;
|
---|
318 |
|
---|
319 | warn(message: any, ...args: any[]): void;
|
---|
320 |
|
---|
321 | error(message: any, ...args: any[]): void;
|
---|
322 |
|
---|
323 | fatal(message: any, ...args: any[]): void;
|
---|
324 |
|
---|
325 | mark(message: any, ...args: any[]): void;
|
---|
326 | }
|
---|