forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log4js.d.ts
318 lines (269 loc) · 8.74 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
// Type definitions for log4js
// Project: https://github.com/nomiddlename/log4js-node
// Definitions by: Kentaro Okuno <http://github.com/armorik83>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
declare module "log4js" {
import express = require('express');
/**
* Replaces the console
* @param logger
* @returns void
*/
export function replaceConsole(logger?: Logger): void;
/**
* Restores the console
* @returns void
*/
export function restoreConsole(): void;
/**
* Get a logger instance. Instance is cached on categoryName level.
*
* @param {String} [categoryName] name of category to log to.
* @returns {Logger} instance of logger for the category
* @static
*/
export function getLogger(categoryName?: string): Logger;
export function getBufferedLogger(categoryName?: string): Logger;
/**
* Has a logger instance cached on categoryName.
*
* @param {String} [categoryName] name of category to log to.
* @returns {boolean} contains logger for the category
* @static
*/
export function hasLogger(categoryName: string): boolean;
/**
* Get the default logger instance.
*
* @returns {Logger} instance of default logger
* @static
*/
export function getDefaultLogger(): Logger;
/**
* args are appender, then zero or more categories
*
* @param {*[]} appenders
* @returns {void}
* @static
*/
export function addAppender(...appenders: any[]): void;
/**
* Load appender
*
* @param {string} appender type
* @param {AppenderModule} the appender module. by default, require('./appenders/' + appender)
* @returns {void}
* @static
*/
export function loadAppender(appenderType: string, appenderModule?: AppenderModule): void;
/**
* Claer configured appenders
*
* @returns {void}
* @static
*/
export function clearAppenders(): void;
/**
* Shutdown all log appenders. This will first disable all writing to appenders
* and then call the shutdown function each appender.
*
* @params {Function} cb - The callback to be invoked once all appenders have
* shutdown. If an error occurs, the callback will be given the error object
* as the first argument.
* @returns {void}
*/
export function shutdown(cb: Function): void;
export function configure(filename: string, options?: any): void;
export function configure(config: IConfig, options?: any): void;
export function setGlobalLogLevel(level: string): void;
export function setGlobalLogLevel(level: Level): void;
/**
* Create logger for connect middleware.
*
*
* @returns {express.Handler} Instance of middleware.
* @static
*/
export function connectLogger(logger: Logger, options: { format?: string; level?: string; nolog?: any; }): express.Handler;
export function connectLogger(logger: Logger, options: { format?: string; level?: Level; nolog?: any; }): express.Handler;
export var layouts: {
basicLayout: Layout,
messagePassThroughLayout: Layout,
patternLayout: Layout,
colouredLayout: Layout,
coloredLayout: Layout,
dummyLayout: Layout,
/**
* Register your custom layout generator
*/
addLayout: (name: string, serializerGenerator: (config?: LayoutConfig) => Layout) => void,
/**
* Get layout. Available predified layout names:
* messagePassThrough, basic, colored, coloured, pattern, dummy
*
*/
layout: (name: string, config: LayoutConfig) => Layout
}
export var appenders: any;
export var levels: {
ALL: Level;
TRACE: Level;
DEBUG: Level;
INFO: Level;
WARN: Level;
ERROR: Level;
FATAL: Level;
OFF: Level;
toLevel(level: string, defaultLevel?: Level): Level;
toLevel(level: Level, defaultLevel?: Level): Level;
};
export interface Logger {
setLevel(level: string): void;
setLevel(level: Level): void;
isLevelEnabled(level: Level): boolean;
isTraceEnabled(): boolean;
isDebugEnabled(): boolean;
isInfoEnabled(): boolean;
isWarnEnabled(): boolean;
isErrorEnabled(): boolean;
isFatalEnabled(): boolean;
trace(message: string, ...args: any[]): void;
debug(message: string, ...args: any[]): void;
info(message: string, ...args: any[]): void;
warn(message: string, ...args: any[]): void;
error(message: string, ...args: any[]): void;
fatal(message: string, ...args: any[]): void;
}
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;
}
export interface IConfig {
appenders: AppenderConfig[];
levels?: { [category: string]: string };
replaceConsole?: boolean;
}
export interface AppenderConfigBase {
type: string;
category?: string;
layout?: { type: string;[key: string]: any }
}
export interface ConsoleAppenderConfig extends AppenderConfigBase {}
export interface FileAppenderConfig extends AppenderConfigBase {
filename: string;
}
export interface DateFileAppenderConfig extends FileAppenderConfig {
/**
* 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;
alwaysIncludePattern: boolean;
}
export interface SmtpAppenderConfig extends AppenderConfigBase {
/** Comma separated list of email recipients */
recipients: string;
/** Sender of all emails (defaults to transport user) */
sender: string;
/** Subject of all email messages (defaults to first event's message)*/
subject: string;
/**
* The time in seconds between sending attempts (defaults to 0).
* All events are buffered and sent in one email during this time.
* If 0 then every event sends an email
*/
sendInterval: number;
SMTP: {
host: string;
secure: boolean;
port: number;
auth: {
user: string;
pass: string;
}
}
}
export interface HookIoAppenderConfig extends FileAppenderConfig {
maxLogSize: number;
backup: number;
pollInterval: number;
}
export interface GelfAppenderConfig extends AppenderConfigBase {
host: string;
hostname: string;
port: string;
facility: string;
}
export interface MultiprocessAppenderConfig extends AppenderConfigBase {
mode: string;
loggerPort: number;
loggerHost: string;
facility: string;
appender?: AppenderConfig;
}
export interface LogglyAppenderConfig extends AppenderConfigBase {
/** Loggly customer token - https://www.loggly.com/docs/api-sending-data/ */
token: string;
/** Loggly customer subdomain (use 'abc' for abc.loggly.com) */
subdomain: string;
/** an array of strings to help segment your data & narrow down search results in Loggly */
tags: string[];
/** Enable JSON logging by setting to 'true' */
json: boolean;
}
export interface ClusteredAppenderConfig extends AppenderConfigBase {
appenders?: AppenderConfig[];
}
type CoreAppenderConfig = ConsoleAppenderConfig
| FileAppenderConfig
| DateFileAppenderConfig
| SmtpAppenderConfig
| HookIoAppenderConfig
| GelfAppenderConfig
| MultiprocessAppenderConfig
| LogglyAppenderConfig
| ClusteredAppenderConfig
interface CustomAppenderConfig extends AppenderConfigBase {
[prop: string]: any;
}
type AppenderConfig = CoreAppenderConfig | CustomAppenderConfig;
export interface LogEvent {
/**
* new Date()
*/
startTime: number;
categoryName: string;
data: any[];
level: Level;
logger: Logger;
}
export interface Appender {
(event: LogEvent): void;
}
export interface AppenderModule {
appender: (...args: any[]) => Appender;
shutdown?: (cb: (error: Error) => void) => void;
configure: (config: CustomAppenderConfig, options?: { [key: string]: any }) => Appender;
}
export interface LayoutConfig {
[key: string]: any;
}
export interface LayoutGenerator {
(config?: LayoutConfig): Layout
}
export interface Layout {
(event: LogEvent): string;
}
}