-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathinterfaces.ts
302 lines (269 loc) · 6.77 KB
/
interfaces.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
import { Chalk } from "chalk";
import { InspectOptions } from "util";
/**
* All possible log levels
* @public
*/
export interface ILogLevel {
0: "silly";
1: "trace";
2: "debug";
3: "info";
4: "warn";
5: "error";
6: "fatal";
}
/**
* Log level IDs (0 - 6)
* @public
*/
export type TLogLevelId = keyof ILogLevel;
/**
* Log level names (sill - fatal)
* @public
*/
export type TLogLevelName = ILogLevel[TLogLevelId];
/**
* Hex colors of different log levels
* @public
*/
export type TLogLevelColor = {
[key in TLogLevelId]: string;
};
/**
* Constructor: logger settings
* all values are optional and will be pre-filled with default values
* @public
*/
export interface ISettingsParam {
/** Name of the instance name, default: host name */
instanceName?: string;
/** Display instanceName or not, default: false */
displayInstanceName?: boolean;
/** Optional name of the logger instance, default: undefined */
name?: string;
/** Use the name of the caller type as the name of the logger, default: false */
setCallerAsLoggerName?: boolean;
/** Minimum output log level (e.g. debug), default: silly */
minLevel?: TLogLevelName;
/** Print log as stringified json instead of pretty, default: false */
logAsJson?: boolean;
/** Expose stack with EVERY log message, default: false */
exposeStack?: boolean;
/** Get Code Frame of an Error and expose it, default: true */
exposeErrorCodeFrame?: boolean;
/** Capture lines before and after a code frame, default: 5 */
exposeErrorCodeFrameLinesBeforeAndAfter?: number;
/** Suppress any log output to std out / std err */
suppressStdOutput?: boolean;
/** Catch logs going to console (e.g. console.log). Last instantiated Log instance wins */
overwriteConsole?: boolean;
/** Overwrite colors of log messages of different log levels */
logLevelsColors?: TLogLevelColor;
/** Overwrite colors json highlighting */
prettyInspectHighlightStyles?: IHighlightStyles;
/** Options to be set for utils.inspect when output is set to pretty (default setting) */
prettyInspectOptions?: InspectOptions;
/** Options to be set for utils.inspect when output is set to json (\{ logAsJson: true \}) */
jsonInspectOptions?: InspectOptions;
/** Overwrite default std out */
stdOut?: IStd;
/** Overwrite default std err */
stdErr?: IStd;
}
/**
* The actual settings object
* Based on ISettingsParam, however pre-filled with defaults in case no value was provided.
* @public
*/
export interface ISettings extends ISettingsParam {
instanceName?: string;
displayInstanceName?: boolean;
name?: string;
setCallerAsLoggerName: boolean;
minLevel: TLogLevelName;
logAsJson: boolean;
exposeStack: boolean;
exposeErrorCodeFrame: boolean;
exposeErrorCodeFrameLinesBeforeAndAfter: number;
suppressStdOutput: boolean;
overwriteConsole: boolean;
logLevelsColors: TLogLevelColor;
prettyInspectHighlightStyles: IHighlightStyles;
prettyInspectOptions: InspectOptions;
jsonInspectOptions: InspectOptions;
stdOut: IStd;
stdErr: IStd;
}
/**
* StdOut and StdErr have to implement a write function (e.g. Stream)
* @public
*/
export interface IStd {
/** stream.Writable */
write: Function;
}
/**
* All relevant information about a log message
* @public
*/
export interface IStackFrame {
/** Relative path based on the main folder */
filePath: string;
/** Full path */
fullFilePath: string;
/** Name of the file */
fileName: string;
/** Line number */
/** Line number */
lineNumber: number | null;
/** Column Name */
columnNumber: number | null;
/** Called from constructor */
isConstructor: boolean | null;
/** Name of the function */
functionName: string | null;
/** Name of the class */
typeName: string | null;
/** Name of the Method */
methodName: string | null;
}
/**
* All relevant information about a log message.
* @public
*/
export interface ILogObject extends IStackFrame {
/** Optional name of the instance this application is running on. */
instanceName?: string;
/** Optional name of the logger or empty string. */
loggerName?: string;
/** Timestamp */
date: Date;
/** Log level name (e.g. debug) */
logLevel: TLogLevelName;
/** Log level ID (e.g. 3) */
logLevelId: TLogLevelId;
/** Log arguments */
argumentsArray: (IErrorObject | unknown)[];
/** Optional Log stack trace */
stack?: IStackFrame[];
}
export interface ILogObjectStringifiable extends ILogObject {
argumentsArray: string[];
}
/**
* Object representing an error with a stack trace
* @public
*/
export interface IErrorObject {
/** native Error object */
nativeError: Error;
/** Is this object an error? */
isError: true;
/** Name of the error*/
name: string;
/** Error message */
message: string;
/** Stack trace of the error */
stack: IStackFrame[];
/** Code frame of the error */
codeFrame?: ICodeFrame;
}
/**
* List of attached transport logger with their respective min log level.
* @public
*/
export type TTransportLogger<T> = {
[key in TLogLevelName]: T;
};
export interface ITransportProvider {
minLevel: TLogLevelName;
transportLogger: TTransportLogger<(message: ILogObject) => void>;
}
/**
* Style and color options for utils.inspect.style
* @public
*/
export type TUtilsInspectColors =
| "reset"
| "bold"
| "dim"
| "italic"
| "underline"
| "blink"
| "inverse"
| "hidden"
| "strikethrough"
| "doubleunderline"
| "black"
| "red"
| "green"
| "yellow"
| "blue"
| "magenta"
| "cyan"
| "white"
| "bgBlack"
| "bgRed"
| "bgGreen"
| "bgYellow"
| "bgBlue"
| "bgMagenta"
| "bgCyan"
| "bgWhite"
| "framed"
| "overlined"
| "gray"
| "redBright"
| "greenBright"
| "yellowBright"
| "blueBright"
| "magentaBright"
| "cyanBright"
| "whiteBright"
| "bgGray"
| "bgRedBright"
| "bgGreenBright"
| "bgYellowBright"
| "bgBlueBright"
| "bgMagentaBright"
| "bgCyanBright"
| "bgWhiteBright";
/**
* Possible style settings of utils.inspect.styles
* Official Node.js typedefs are missing this interface.
* @public
*/
export interface IHighlightStyles {
name?: TUtilsInspectColors;
special?: TUtilsInspectColors;
number?: TUtilsInspectColors;
bigint?: TUtilsInspectColors;
boolean?: TUtilsInspectColors;
undefined?: TUtilsInspectColors;
null?: TUtilsInspectColors;
string?: TUtilsInspectColors;
symbol?: TUtilsInspectColors;
date?: TUtilsInspectColors;
regexp?: TUtilsInspectColors;
module?: TUtilsInspectColors;
}
export interface IJsonHighlightColorsChalk {
number: Chalk;
key: Chalk;
string: Chalk;
boolean: Chalk;
null: Chalk;
}
/**
* Code frame of an error
* @public
* */
export interface ICodeFrame {
firstLineNumber: number;
lineNumber: number;
columnNumber: number | null;
linesBefore: string[];
relevantLine: string;
linesAfter: string[];
}