-
Notifications
You must be signed in to change notification settings - Fork 38
/
index.d.ts
296 lines (253 loc) · 7.61 KB
/
index.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
///<reference lib="ES2015"/>
///<reference types="moment"/>
import moment = require("moment");
type STANDARD_LEVELS = SimpleLogger.STANDARD_LEVELS;
type Logger = SimpleLogger.Logger;
type IConsoleAppenderOptions = SimpleLogger.IConsoleAppenderOptions;
type ConsoleAppender = SimpleLogger.appenders.ConsoleAppender;
type IFileAppenderOptions = SimpleLogger.IFileAppenderOptions;
type FileAppender = SimpleLogger.appenders.FileAppender;
type IRollingFileAppenderOptions = SimpleLogger.IRollingFileAppenderOptions;
type RollingFileAppender = SimpleLogger.appenders.RollingFileAppender;
type AbstractAppender = SimpleLogger.AbstractAppender;
type ISimpleLoggerOptions = SimpleLogger.ISimpleLoggerOptions;
declare class SimpleLogger
{
constructor(opts?: ISimpleLoggerOptions);
createLogger(options?: SimpleLogger.ILoggerOptions): Logger;
createLogger(category?: string, level?: STANDARD_LEVELS): Logger;
createConsoleAppender(opts?: IConsoleAppenderOptions): ConsoleAppender;
createFileAppender(opts?: IFileAppenderOptions): FileAppender;
createRollingFileAppender(opts?: IRollingFileAppenderOptions): RollingFileAppender;
addAppender<T extends AbstractAppender>(appender: AbstractAppender): T;
getAppenders(): AbstractAppender[];
getLoggers(): Logger[];
startRefreshThread(): void;
setAllLoggerLevels(level: STANDARD_LEVELS): void;
readConfig(completeCallback?: (err?: any) => void): void;
}
declare namespace SimpleLogger
{
export type STANDARD_LEVELS = 'all' | 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
interface IEntry
{
ts: moment.MomentInput;
pid: number;
domain?: string;
category?: string;
level: STANDARD_LEVELS;
msg: any | any[];
}
interface ISimpleLoggerOptions
{
domain?: string;
loggers?: Logger[];
level?: STANDARD_LEVELS;
loggerConfigFile?: string;
refresh?: number;
fs?: any;
createInterval?: typeof setInterval;
minRefresh?: number;
errorEventName?: string;
}
export interface ILoggerOptions
{
pid?: number;
errorEventName?: string;
domain?: string;
category?: string;
level?: STANDARD_LEVELS;
levels?: STANDARD_LEVELS[];
appenders?: AbstractAppender[]
}
export namespace Logger
{
var STANDARD_LEVELS: STANDARD_LEVELS[];
var DEFAULT_LEVEL: STANDARD_LEVELS;
}
export class Logger
{
constructor(options?: ILoggerOptions);
/**
* log the statement message
*
* @param level the level of this message (label, i.e, info, warn, etc)
* @param msg
*/
log(level: STANDARD_LEVELS, msg: any[] | any): void;
/**
* set the level
*
* @param lvl one of the recognized logger levels
*/
setLevel(lvl: STANDARD_LEVELS): void;
/**
* return the current level string
*/
getLevel(): STANDARD_LEVELS;
/**
* set the list of appenders
* @param appenderList
*/
setAppenders(appenderList: AbstractAppender[]): void;
/**
* add an appender to the list
*
* @param appender - implements write method
*/
addAppender<T extends AbstractAppender>(appender: T): T;
/**
* remove the appender using the type name
*/
removeAppender(typeName: string): void;
getAppenders(): AbstractAppender[];
isDebug(): boolean;
isInfo(): boolean;
/**
* return the status map with log counts for each level
*/
getStats(): Map<STANDARD_LEVELS, number>;
getCategory(): string | undefined;
getDomain(): string | undefined;
all(...arr: any[]): void;
trace(...arr: any[]): void;
debug(...arr: any[]): void;
info(...arr: any[]): void;
warn(...arr: any[]): void;
error(...arr: any[]): void;
fatal(...arr: any[]): void;
}
export interface IAbstractAppenderOptions
{
typeName?: string;
timestampFormat?: string;
prettyPrint?: boolean;
separator?: string;
level?: STANDARD_LEVELS;
levels?: STANDARD_LEVELS[];
}
export interface IConsoleAppenderOptions extends IAbstractAppenderOptions
{
typeName?: string;
writer?: Function;
}
export interface IFileAppenderOptions extends IAbstractAppenderOptions
{
typeName?: string;
fs?: any;
autoOpen?: boolean;
logFilePath: string;
writer?: any;
}
export interface IRollingFileAppenderOptions extends IAbstractAppenderOptions
{
typeName?: string;
fs?: any;
autoOpen?: boolean;
logDirectory: string;
fileNamePattern: string;
dateFormat?: string;
currentFile?: string;
createInterval?: typeof setInterval;
}
export abstract class AbstractAppender
{
constructor(options?: IAbstractAppenderOptions);
/**
* format the entry and return the field list
*
* @param entry the log entry
* @param thisArg - use this to override the base object
*
* @returns field array
*/
formatEntry(entry: any, thisArg?: AbstractAppender): string[];
/**
* format the message
*
* @param msg the log message
* @param thisArg - use this to override the base object
*
* @returns field array
*/
formatMessage(msg: any | any[], thisArg?: AbstractAppender): string;
formatDate(value: Date): string;
formatObject(value: any): string;
formatLevel(level: STANDARD_LEVELS): string;
formatTimestamp(ts: moment.MomentInput): string;
getTypeName(): string;
//formatter(entry: any): string;
abstract write(entry: IEntry): void;
abstract setLevel(level: STANDARD_LEVELS): void;
__protected(): any;
}
//export type IConsoleAppenderOptions = appenders.IConsoleAppenderOptions;
//export type IFileAppenderOptions = appenders.IFileAppenderOptions;
//export type IRollingFileAppenderOptions = appenders.IRollingFileAppenderOptions;
export namespace appenders
{
export class ConsoleAppender extends AbstractAppender
{
constructor(options: IAbstractAppenderOptions & IConsoleAppenderOptions);
formatter(entry: IEntry): string;
write(entry: IEntry): void;
setLevel(level: STANDARD_LEVELS): void;
}
export class FileAppender extends AbstractAppender
{
constructor(options?: IFileAppenderOptions);
formatter(entry: IEntry): string;
write(entry: IEntry): void;
setLevel(level: STANDARD_LEVELS): void;
}
export class RollingFileAppender extends AbstractAppender
{
constructor(options?: IRollingFileAppenderOptions);
formatter(entry: IEntry): string;
write(entry: IEntry): void;
setLevel(level: STANDARD_LEVELS): void;
checkForRoll(now?: moment.Moment): boolean;
createFileName(now?: moment.Moment): string;
}
}
/**
* static convenience method to create a file logger (no console logging);
*
* @param options - if string then it's the logFilePath, else options with the logFilePath
* @returns Logger
*/
export function createSimpleLogger(): Logger;
export function createSimpleLogger(logFilePath: string): Logger;
export function createSimpleLogger(options: ISimpleLoggerOptions &
Partial<IConsoleAppenderOptions> &
Partial<IFileAppenderOptions>): Logger;
/**
* create a rolling file logger by passing options to SimpleLogger and Logger. this enables setting
* of domain, category, etc.
*
* @param options
* @returns rolling logger
*/
export function createSimpleFileLogger(logFilePath: string): Logger;
export function createSimpleFileLogger(options: ISimpleLoggerOptions &
IFileAppenderOptions): Logger;
/**
* create a rolling file appender and add it to the appender list
*
* @param options
* @returns the appender
*/
export function createRollingFileLogger(options: ISimpleLoggerOptions &
IRollingFileAppenderOptions &
{ readLoggerConfig?: Function }): Logger;
/**
* create a log manager
*
* @param options - file or rolling file specs;
*/
export function createLogManager(options?: ISimpleLoggerOptions &
Partial<IRollingFileAppenderOptions> &
Partial<IConsoleAppenderOptions> &
{ readLoggerConfig?: Function }): SimpleLogger;
}
export = SimpleLogger;