-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Yolog.d.ts
228 lines (225 loc) · 7.62 KB
/
Yolog.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
/** @abstract */
declare class YologPlugin {
/**
* Method called when a log message is intercepted and the plugin is listening to the given tag.
*
* @param tag Tag which was used when logging the message.
* @param timestamp Timestamp (in ms) when the log was intercepted by the Yolog instance.
* @param message Message that is passed to the plugin.
* @param error Error generated in the logger to be possible to use for call stack or for other reasons.
* @abstract
*/
public log(tag: string, timestamp: number, message: string, error: Error): Promise<void>;
/**
* Set state of a given tag for the plugin.
* If value is omitted, the state will be toggled.
*
* @param tag Tag to change the state of.
* @param state State to set the tag to.
* @return Self.
*/
public set(tag: string, state?: boolean): YologPlugin;
/**
* Get state of given tag for the plugin.
*
* @param tag Tag to check state on.
* @return State of the tag.
*/
public get(tag: string): boolean;
/**
* Getter to fetch a list of all available tags.
*
* @return List of available tags.
*/
public readonly available: string[];
/**
* Getter to fetch what tags that the plugin is listening to.
*
* @return List of active tags.
*/
public readonly active: string[];
/**
* Disable internal error passing to the underlying plugin or event handler.
* If tag name/s are omitted, the setting will be global.
*
* @param [tag] Optional tags to toggle.
* @return self
*/
public disableError(...tag: string[]): this;
/**
* Enable internal error passing to the underlying plugin or event handler.
* If tag name/s are omitted, the setting will be global.
*
* @param [tag] Optional tags to toggle.
* @return self
*/
public enableError(...tag: string[]): this;
}
/**
* Tags states, true means active, false means inactive.
*/
declare interface Tags {
debug: { enabled: boolean, error: boolean };
info: { enabled: boolean, error: boolean };
warning: { enabled: boolean, error: boolean };
error: { enabled: boolean, error: boolean };
critical: { enabled: boolean, error: boolean };
alert: { enabled: boolean, error: boolean };
emergency: { enabled: boolean, error: boolean };
}
/**
* Yolog logging handler.
*/
declare class Yolog {
public constructor(plugins?: any[], tags?: Tags);
/**
* Use the logger as an event handler and add a callback that will fire on a specific tag.
*
* @param tag Tag to listen for.
* @param handler Handler to call.
* @param priority Priority for the event handlers internal sorting.
* @return Handler id, can be used to turn the handler off if the callback is not available.
*/
public on(tag: string, handler: Function, priority: number): number;
/**
* Remove a listener from a given tag.
*
* @param {String} tag Tag to remove the specific handler from.
* @param handler Handler as callback or ID.
*/
public off(tag: string, handler: number | Function): boolean;
/**
* Use the logger as an event handler and add a callback that will fire one time on a specific tag.
*
* @param tag Tag to listen for.
* @param handler Handler to call.
* @param priority Priority for the event handlers internal sorting.
* @return Handler id, can be used to turn the handler off if the callback is not available.
*/
public once(tag: string, handler: Function, priority?: number): number;
/**
* Change the currently used timestamp method.
* Defaults to `() => { return (new Date()).getTime() };`
*
* @param func Function to use.
* @return Self.
*/
public setTimestampFunction(func: () => number): Yolog;
/**
* Disable internal error passing to the underlying plugin or event handler.
* If tag name/s are omitted, the setting will be global.
*
* @param [tag] Optional tags to toggle.
* @return Self.
*/
public disableError (...tag: string[]): Yolog;
/**
* Enable internal error passing to the underlying plugin or event handler.
* If tag name/s are omitted, the setting will be global.
*
* @param [tag] Optional tags to toggle.
* @return Self.
*/
public enableError (...tag: string[]): Yolog;
/**
* Get a list of tags that are active.
*
* @return List of active tags.
*/
public readonly active: string[];
/**
* Get all available tags.
*
* @return List of available tags.
*/
public readonly available: string[];
/**
* Set a tag state to active or not active in the Yolog instance.
* If state is omitted, the tag will be toggled to the negative of the current state.
*
* @param tag Tag name.
* @param state State to set the tag to.
* @return Self
*/
public set(tag: string, state?: boolean): Yolog;
/**
* Get state of a specific tag in the Yolog instance.
*
* @param tag Tag to check.
* @return Current state of the tag.
*/
public get(tag: string): boolean;
/**
* Add a plugin to the current Yolog instance.
*
* @param plugin Plugin to add.
* @return Self
*/
public addPlugin(plugin: YologPlugin): Yolog;
/**
* Remove a plugin from current Yolog instance.
*
* @param plugin Plugin to remove.
* @return Self
*/
public removePlugin(plugin: YologPlugin): Yolog;
/**
* Call a custom tag not already defined.
*
* @param tag Tag name.
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public custom(tag: string, message: string, ...args: any[]): Promise<void>;
/**
* Log a debug message.
*
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public debug(message: string, ...args: any[]): Promise<void>;
/**
* Log a info message.
*
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public info(message: string, ...args: any[]): Promise<void>;
/**
* Log a warning message.
*
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public warning(message: string, ...args: any[]): Promise<void>;
/**
* Log an error message.
*
* @param message
* @param args Argument list to pass to plugins for formatting.
*/
public error(message: string, ...args: any[]): Promise<void>;
/**
* Log a critical message.
*
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public critical(message: string, ...args: any[]): Promise<void>;
/**
* Log an alert message.
*
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public alert(message: string, ...args: any[]): Promise<void>;
/**
* Log an emergency message.
*
* @param message Message to log.
* @param args Argument list to pass to plugins for formatting.
*/
public emergency(message: string, ...args: any[]): Promise<void>;
}
export default Yolog;
export { Yolog, YologPlugin, YologPlugin as Plugin };