-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLogger.ts
86 lines (69 loc) · 1.81 KB
/
CLogger.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
/**
* 2019
*
* Contributor(s):
*
* Anatoly Yuzefovich <iskhartakh@gmail.com>
*
* A module Verto lib
*
* @module CLogger
*/
/** Class representation a logger */
class CLogger {
private _label: string;
private _debug: boolean = true;
/**
* Create a logger
*
* @param {String} [label=default] - Prepend log messages text
* @param {String} [debug=true] - Debug level enable flag
*/
constructor(label = 'default', debug = true) {
this._label = label;
this._debug = debug;
}
public debug(...msg: any[]) {
if (this._debug) {
console.log(this._label, ...msg);
}
}
public warn(...msg: any[]) {
console.warn(this._label, ...msg);
}
public info(...msg: any[]) {
console.info(this._label, ...msg);
}
public error(...msg: any[]) {
console.error(this._label, ...msg);
}
/** Get instance label */
get label() {
return this._label;
}
/** Set instance label */
set label(label) {
this._label = label;
}
/**
* Add method label to original label and return new instance of CLogger
*
* @param {String} method - Method name or what we need to label
* @param {Boolean} debug - Debug flag
* @return {CLogger} new CLogger instance with new label
*/
method(method: string, debug: boolean) {
return new CLogger(`${this.label}:${method}`, debug);
}
/**
* Create new logger instance
*
* @param {String} [label=default] - Prepend log messages text
* @param {String} [debug=true] - Debug level enable flag
* @return {CLogger} new CLogger instance with new label
*/
new(label = 'default', debug = true) {
return new CLogger(label, debug);
}
}
export { CLogger };