@skax/logger 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/index.js +110 -136
- package/index.umd.js +110 -136
- package/package.json +3 -3
- package/types/index.d.ts +47 -28
package/README.md
CHANGED
|
@@ -11,5 +11,11 @@ yarn add @skax/logger
|
|
|
11
11
|
```ts
|
|
12
12
|
import Logger from '@skax/logger';
|
|
13
13
|
|
|
14
|
-
Logger
|
|
14
|
+
const logger = new Logger();
|
|
15
|
+
|
|
16
|
+
logger.d('console.log print'); // debug
|
|
17
|
+
logger.v('console.log print'); // log
|
|
18
|
+
logger.i('console.log print'); // info
|
|
19
|
+
logger.w('console.log print'); // warn
|
|
20
|
+
logger.e('console.log print'); // error
|
|
15
21
|
```
|
package/index.js
CHANGED
|
@@ -1,165 +1,114 @@
|
|
|
1
1
|
/*
|
|
2
2
|
*
|
|
3
|
-
* @skax/logger.js
|
|
4
|
-
* Copyright (c) 2023-
|
|
3
|
+
* @skax/logger.js v1.0.0
|
|
4
|
+
* Copyright (c) 2023-9-19 ShineShao <xiaoshaoqq@gmail.com>
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
8
|
'use strict';
|
|
9
9
|
|
|
10
|
-
function __spreadArray(to, from, pack) {
|
|
11
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
12
|
-
if (ar || !(i in from)) {
|
|
13
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
14
|
-
ar[i] = from[i];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
18
|
-
}
|
|
19
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
20
|
-
var e = new Error(message);
|
|
21
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
10
|
/**
|
|
25
|
-
* @class Logger
|
|
11
|
+
* @class Logger
|
|
26
12
|
* @classdesc Provide multiple log printing methods
|
|
13
|
+
* @example
|
|
14
|
+
* const logger = new Logger({})
|
|
15
|
+
* logger.v("verbose log")
|
|
27
16
|
*/
|
|
28
17
|
var Logger = /** @class */ (function () {
|
|
29
|
-
function Logger() {
|
|
18
|
+
function Logger(options) {
|
|
19
|
+
if (options === void 0) { options = {}; }
|
|
20
|
+
this._options = {};
|
|
21
|
+
this._levelNum = 0;
|
|
22
|
+
/**
|
|
23
|
+
* @description Method used to print error logs
|
|
24
|
+
* @static
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* logger.e("error message") // error message
|
|
28
|
+
*
|
|
29
|
+
* @param {...any[]} args error messages
|
|
30
|
+
* @returns {void}
|
|
31
|
+
*/
|
|
32
|
+
this.e = this._loggerFactory('error', this._levelNum <= 4);
|
|
33
|
+
/**
|
|
34
|
+
* @description Method used to print warn logs
|
|
35
|
+
* @static
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* logger.w("warn message") // warn message
|
|
39
|
+
*
|
|
40
|
+
* @param {...any[]} args warn messages
|
|
41
|
+
* @returns {void}
|
|
42
|
+
*/
|
|
43
|
+
this.w = this._loggerFactory('warn', this._levelNum <= 3);
|
|
44
|
+
/**
|
|
45
|
+
* @description Method used to print info logs
|
|
46
|
+
* @static
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* logger.i("info message") // info message
|
|
50
|
+
*
|
|
51
|
+
* @param {...any[]} args info messages
|
|
52
|
+
* @returns {void}
|
|
53
|
+
*/
|
|
54
|
+
this.i = this._loggerFactory('info', this._levelNum <= 2);
|
|
55
|
+
/**
|
|
56
|
+
* @description Method used to print verbose logs
|
|
57
|
+
* @static
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* logger.v("verbose message") // verbose message
|
|
61
|
+
*
|
|
62
|
+
* @param {...any[]} args verbose messages
|
|
63
|
+
* @returns {void}
|
|
64
|
+
*/
|
|
65
|
+
this.v = this._loggerFactory('log', this._levelNum <= 1);
|
|
66
|
+
/**
|
|
67
|
+
* @description Method used to print debug logs
|
|
68
|
+
* @static
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* logger.d("debug message") // debug message
|
|
72
|
+
*
|
|
73
|
+
* @param {...any[]} msg debug messages
|
|
74
|
+
* @returns {void}
|
|
75
|
+
*/
|
|
76
|
+
this.d = this._loggerFactory('debug', this._levelNum < 1);
|
|
77
|
+
this.setOptions(options);
|
|
30
78
|
}
|
|
31
79
|
/**
|
|
32
|
-
* @description
|
|
33
|
-
* @static
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* Logger.e("error message") // [LOGGER ERROR] > error message
|
|
37
|
-
*
|
|
38
|
-
* @param {...any[]} args error messages
|
|
39
|
-
* @returns {void}
|
|
40
|
-
*/
|
|
41
|
-
Logger.e = function () {
|
|
42
|
-
var arguments$1 = arguments;
|
|
43
|
-
|
|
44
|
-
var args = [];
|
|
45
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
46
|
-
args[_i] = arguments$1[_i];
|
|
47
|
-
}
|
|
48
|
-
if (Logger.LOGGER_LEVEL <= 4)
|
|
49
|
-
{ Logger.HIDE_TAG
|
|
50
|
-
? console.error.apply(console, args) : console.error.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " ERROR]"), 'background: red; color: #fff'], args, false)); }
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* @description Static method used to print warn logs
|
|
54
|
-
* @static
|
|
55
|
-
*
|
|
56
|
-
* @example
|
|
57
|
-
* Logger.w("warn message") // [LOGGER WARN] > warn message
|
|
58
|
-
*
|
|
59
|
-
* @param {...any[]} args warn messages
|
|
60
|
-
* @returns {void}
|
|
61
|
-
*/
|
|
62
|
-
Logger.w = function () {
|
|
63
|
-
var arguments$1 = arguments;
|
|
64
|
-
|
|
65
|
-
var args = [];
|
|
66
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
67
|
-
args[_i] = arguments$1[_i];
|
|
68
|
-
}
|
|
69
|
-
if (Logger.LOGGER_LEVEL <= 3)
|
|
70
|
-
{ Logger.HIDE_TAG
|
|
71
|
-
? console.warn.apply(console, args) : console.warn.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " WARN]"), 'background: #faad14; color: #fff'], args, false)); }
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* @description Static method used to print info logs
|
|
75
|
-
* @static
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* Logger.i("info message") // [LOGGER INFO] > info message
|
|
79
|
-
*
|
|
80
|
-
* @param {...any[]} args info messages
|
|
81
|
-
* @returns {void}
|
|
82
|
-
*/
|
|
83
|
-
Logger.i = function () {
|
|
84
|
-
var arguments$1 = arguments;
|
|
85
|
-
|
|
86
|
-
var args = [];
|
|
87
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
88
|
-
args[_i] = arguments$1[_i];
|
|
89
|
-
}
|
|
90
|
-
if (Logger.LOGGER_LEVEL <= 2)
|
|
91
|
-
{ Logger.HIDE_TAG
|
|
92
|
-
? console.info.apply(console, args) : console.info.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " INFO]"), 'background: #ffe58f; color: #fff'], args, false)); }
|
|
93
|
-
};
|
|
94
|
-
/**
|
|
95
|
-
* @description Static method used to print verbose logs
|
|
96
|
-
* @static
|
|
97
|
-
*
|
|
98
|
-
* @example
|
|
99
|
-
* Logger.v("verbose message") // [LOGGER VERBOSE] > verbose message
|
|
100
|
-
*
|
|
101
|
-
* @param {...any[]} args verbose messages
|
|
102
|
-
* @returns {void}
|
|
103
|
-
*/
|
|
104
|
-
Logger.v = function () {
|
|
105
|
-
var arguments$1 = arguments;
|
|
106
|
-
|
|
107
|
-
var args = [];
|
|
108
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
109
|
-
args[_i] = arguments$1[_i];
|
|
110
|
-
}
|
|
111
|
-
if (Logger.LOGGER_LEVEL <= 1)
|
|
112
|
-
{ Logger.HIDE_TAG ? console.log.apply(console, args) : console.log.apply(console, __spreadArray(["[".concat(Logger.TAG, " VERBOSE]")], args, false)); }
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* @description Static method used to print debug logs
|
|
116
|
-
* @static
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* Logger.d("debug message") // [LOGGER DEBUG] > debug message
|
|
120
|
-
* Logger.d("debug message", "DEBUG") // [DEBUG] > debug message
|
|
121
|
-
*
|
|
122
|
-
* @param {...any[]} msg debug messages
|
|
123
|
-
* @returns {void}
|
|
124
|
-
*/
|
|
125
|
-
Logger.d = function () {
|
|
126
|
-
var arguments$1 = arguments;
|
|
127
|
-
|
|
128
|
-
var args = [];
|
|
129
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
130
|
-
args[_i] = arguments$1[_i];
|
|
131
|
-
}
|
|
132
|
-
if (Logger.LOGGER_LEVEL < 1) {
|
|
133
|
-
Logger.HIDE_TAG
|
|
134
|
-
? console.log.apply(console, args) : console.log.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " DEBUG]"), 'background: #1677ff; color: #fff'], args, false));
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* @description Static method used to set logger option
|
|
80
|
+
* @description Method used to set logger option and change logger level
|
|
139
81
|
* @static
|
|
140
82
|
*
|
|
141
83
|
* @example
|
|
142
|
-
*
|
|
84
|
+
* logger.setOptions({level: 'INFO'}) // set logger level
|
|
143
85
|
*
|
|
144
86
|
* @param {LoggerOptions} options logger options
|
|
145
87
|
* @return {void}
|
|
146
88
|
*/
|
|
147
|
-
Logger.setOptions = function (options) {
|
|
148
|
-
|
|
149
|
-
|
|
89
|
+
Logger.prototype.setOptions = function (options) {
|
|
90
|
+
this._options = options;
|
|
91
|
+
this._levelNum = this._matchLevel(options.level || 'DEBUG');
|
|
92
|
+
if (this._levelNum !== 0) {
|
|
93
|
+
this.e = this._loggerFactory('error', this._levelNum <= 4);
|
|
94
|
+
this.w = this._loggerFactory('warn', this._levelNum <= 3);
|
|
95
|
+
this.i = this._loggerFactory('info', this._levelNum <= 2);
|
|
96
|
+
this.v = this._loggerFactory('warn', this._levelNum <= 1);
|
|
97
|
+
this.d = this._loggerFactory('warn', this._levelNum < 1);
|
|
98
|
+
}
|
|
150
99
|
};
|
|
151
100
|
/**
|
|
152
|
-
* @description
|
|
101
|
+
* @description Private method used to match logger level
|
|
153
102
|
* @static
|
|
154
103
|
* @private
|
|
155
104
|
*
|
|
156
105
|
* @example
|
|
157
|
-
*
|
|
106
|
+
* this._matchLevel("DEBUG") // 0
|
|
158
107
|
*
|
|
159
108
|
* @param {LoggerLevel} level logger level
|
|
160
109
|
* @return {number}
|
|
161
110
|
*/
|
|
162
|
-
Logger._matchLevel = function (level) {
|
|
111
|
+
Logger.prototype._matchLevel = function (level) {
|
|
163
112
|
var logLevel = 0;
|
|
164
113
|
switch (level) {
|
|
165
114
|
case 'DEBUG':
|
|
@@ -180,10 +129,35 @@ var Logger = /** @class */ (function () {
|
|
|
180
129
|
}
|
|
181
130
|
return logLevel;
|
|
182
131
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
132
|
+
/**
|
|
133
|
+
* @private
|
|
134
|
+
* @description Logger factory
|
|
135
|
+
* @param type
|
|
136
|
+
* @param bool
|
|
137
|
+
* @returns
|
|
138
|
+
*/
|
|
139
|
+
Logger.prototype._loggerFactory = function (type, bool) {
|
|
140
|
+
var func = console[type];
|
|
141
|
+
if (bool && func) {
|
|
142
|
+
return func.bind(console, "[".concat(type.toLocaleUpperCase(), "]"));
|
|
143
|
+
}
|
|
144
|
+
return Logger.noop;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* @description Get options
|
|
148
|
+
* @returns {LoggerOptions}
|
|
149
|
+
*/
|
|
150
|
+
Logger.prototype.getOptions = function () {
|
|
151
|
+
return this._options;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* @description Get version
|
|
155
|
+
* @returns {string}
|
|
156
|
+
*/
|
|
157
|
+
Logger.prototype.version = function () {
|
|
158
|
+
return '1.0.0';
|
|
159
|
+
};
|
|
160
|
+
Logger.noop = function () { };
|
|
187
161
|
return Logger;
|
|
188
162
|
}());
|
|
189
163
|
|
package/index.umd.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
*
|
|
3
|
-
* @skax/logger.js
|
|
4
|
-
* Copyright (c) 2023-
|
|
3
|
+
* @skax/logger.js v1.0.0
|
|
4
|
+
* Copyright (c) 2023-9-19 ShineShao <xiaoshaoqq@gmail.com>
|
|
5
5
|
* Released under the MIT License.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
@@ -11,159 +11,108 @@
|
|
|
11
11
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Logger = factory());
|
|
12
12
|
})(this, (function () { 'use strict';
|
|
13
13
|
|
|
14
|
-
function __spreadArray(to, from, pack) {
|
|
15
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
16
|
-
if (ar || !(i in from)) {
|
|
17
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
18
|
-
ar[i] = from[i];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
22
|
-
}
|
|
23
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
24
|
-
var e = new Error(message);
|
|
25
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
14
|
/**
|
|
29
|
-
* @class Logger
|
|
15
|
+
* @class Logger
|
|
30
16
|
* @classdesc Provide multiple log printing methods
|
|
17
|
+
* @example
|
|
18
|
+
* const logger = new Logger({})
|
|
19
|
+
* logger.v("verbose log")
|
|
31
20
|
*/
|
|
32
21
|
var Logger = /** @class */ (function () {
|
|
33
|
-
function Logger() {
|
|
22
|
+
function Logger(options) {
|
|
23
|
+
if (options === void 0) { options = {}; }
|
|
24
|
+
this._options = {};
|
|
25
|
+
this._levelNum = 0;
|
|
26
|
+
/**
|
|
27
|
+
* @description Method used to print error logs
|
|
28
|
+
* @static
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* logger.e("error message") // error message
|
|
32
|
+
*
|
|
33
|
+
* @param {...any[]} args error messages
|
|
34
|
+
* @returns {void}
|
|
35
|
+
*/
|
|
36
|
+
this.e = this._loggerFactory('error', this._levelNum <= 4);
|
|
37
|
+
/**
|
|
38
|
+
* @description Method used to print warn logs
|
|
39
|
+
* @static
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* logger.w("warn message") // warn message
|
|
43
|
+
*
|
|
44
|
+
* @param {...any[]} args warn messages
|
|
45
|
+
* @returns {void}
|
|
46
|
+
*/
|
|
47
|
+
this.w = this._loggerFactory('warn', this._levelNum <= 3);
|
|
48
|
+
/**
|
|
49
|
+
* @description Method used to print info logs
|
|
50
|
+
* @static
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* logger.i("info message") // info message
|
|
54
|
+
*
|
|
55
|
+
* @param {...any[]} args info messages
|
|
56
|
+
* @returns {void}
|
|
57
|
+
*/
|
|
58
|
+
this.i = this._loggerFactory('info', this._levelNum <= 2);
|
|
59
|
+
/**
|
|
60
|
+
* @description Method used to print verbose logs
|
|
61
|
+
* @static
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* logger.v("verbose message") // verbose message
|
|
65
|
+
*
|
|
66
|
+
* @param {...any[]} args verbose messages
|
|
67
|
+
* @returns {void}
|
|
68
|
+
*/
|
|
69
|
+
this.v = this._loggerFactory('log', this._levelNum <= 1);
|
|
70
|
+
/**
|
|
71
|
+
* @description Method used to print debug logs
|
|
72
|
+
* @static
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* logger.d("debug message") // debug message
|
|
76
|
+
*
|
|
77
|
+
* @param {...any[]} msg debug messages
|
|
78
|
+
* @returns {void}
|
|
79
|
+
*/
|
|
80
|
+
this.d = this._loggerFactory('debug', this._levelNum < 1);
|
|
81
|
+
this.setOptions(options);
|
|
34
82
|
}
|
|
35
83
|
/**
|
|
36
|
-
* @description
|
|
37
|
-
* @static
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* Logger.e("error message") // [LOGGER ERROR] > error message
|
|
41
|
-
*
|
|
42
|
-
* @param {...any[]} args error messages
|
|
43
|
-
* @returns {void}
|
|
44
|
-
*/
|
|
45
|
-
Logger.e = function () {
|
|
46
|
-
var arguments$1 = arguments;
|
|
47
|
-
|
|
48
|
-
var args = [];
|
|
49
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
50
|
-
args[_i] = arguments$1[_i];
|
|
51
|
-
}
|
|
52
|
-
if (Logger.LOGGER_LEVEL <= 4)
|
|
53
|
-
{ Logger.HIDE_TAG
|
|
54
|
-
? console.error.apply(console, args) : console.error.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " ERROR]"), 'background: red; color: #fff'], args, false)); }
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* @description Static method used to print warn logs
|
|
58
|
-
* @static
|
|
59
|
-
*
|
|
60
|
-
* @example
|
|
61
|
-
* Logger.w("warn message") // [LOGGER WARN] > warn message
|
|
62
|
-
*
|
|
63
|
-
* @param {...any[]} args warn messages
|
|
64
|
-
* @returns {void}
|
|
65
|
-
*/
|
|
66
|
-
Logger.w = function () {
|
|
67
|
-
var arguments$1 = arguments;
|
|
68
|
-
|
|
69
|
-
var args = [];
|
|
70
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
71
|
-
args[_i] = arguments$1[_i];
|
|
72
|
-
}
|
|
73
|
-
if (Logger.LOGGER_LEVEL <= 3)
|
|
74
|
-
{ Logger.HIDE_TAG
|
|
75
|
-
? console.warn.apply(console, args) : console.warn.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " WARN]"), 'background: #faad14; color: #fff'], args, false)); }
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* @description Static method used to print info logs
|
|
79
|
-
* @static
|
|
80
|
-
*
|
|
81
|
-
* @example
|
|
82
|
-
* Logger.i("info message") // [LOGGER INFO] > info message
|
|
83
|
-
*
|
|
84
|
-
* @param {...any[]} args info messages
|
|
85
|
-
* @returns {void}
|
|
86
|
-
*/
|
|
87
|
-
Logger.i = function () {
|
|
88
|
-
var arguments$1 = arguments;
|
|
89
|
-
|
|
90
|
-
var args = [];
|
|
91
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
92
|
-
args[_i] = arguments$1[_i];
|
|
93
|
-
}
|
|
94
|
-
if (Logger.LOGGER_LEVEL <= 2)
|
|
95
|
-
{ Logger.HIDE_TAG
|
|
96
|
-
? console.info.apply(console, args) : console.info.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " INFO]"), 'background: #ffe58f; color: #fff'], args, false)); }
|
|
97
|
-
};
|
|
98
|
-
/**
|
|
99
|
-
* @description Static method used to print verbose logs
|
|
100
|
-
* @static
|
|
101
|
-
*
|
|
102
|
-
* @example
|
|
103
|
-
* Logger.v("verbose message") // [LOGGER VERBOSE] > verbose message
|
|
104
|
-
*
|
|
105
|
-
* @param {...any[]} args verbose messages
|
|
106
|
-
* @returns {void}
|
|
107
|
-
*/
|
|
108
|
-
Logger.v = function () {
|
|
109
|
-
var arguments$1 = arguments;
|
|
110
|
-
|
|
111
|
-
var args = [];
|
|
112
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
113
|
-
args[_i] = arguments$1[_i];
|
|
114
|
-
}
|
|
115
|
-
if (Logger.LOGGER_LEVEL <= 1)
|
|
116
|
-
{ Logger.HIDE_TAG ? console.log.apply(console, args) : console.log.apply(console, __spreadArray(["[".concat(Logger.TAG, " VERBOSE]")], args, false)); }
|
|
117
|
-
};
|
|
118
|
-
/**
|
|
119
|
-
* @description Static method used to print debug logs
|
|
120
|
-
* @static
|
|
121
|
-
*
|
|
122
|
-
* @example
|
|
123
|
-
* Logger.d("debug message") // [LOGGER DEBUG] > debug message
|
|
124
|
-
* Logger.d("debug message", "DEBUG") // [DEBUG] > debug message
|
|
125
|
-
*
|
|
126
|
-
* @param {...any[]} msg debug messages
|
|
127
|
-
* @returns {void}
|
|
128
|
-
*/
|
|
129
|
-
Logger.d = function () {
|
|
130
|
-
var arguments$1 = arguments;
|
|
131
|
-
|
|
132
|
-
var args = [];
|
|
133
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
134
|
-
args[_i] = arguments$1[_i];
|
|
135
|
-
}
|
|
136
|
-
if (Logger.LOGGER_LEVEL < 1) {
|
|
137
|
-
Logger.HIDE_TAG
|
|
138
|
-
? console.log.apply(console, args) : console.log.apply(console, __spreadArray(["%c[".concat(Logger.TAG, " DEBUG]"), 'background: #1677ff; color: #fff'], args, false));
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
/**
|
|
142
|
-
* @description Static method used to set logger option
|
|
84
|
+
* @description Method used to set logger option and change logger level
|
|
143
85
|
* @static
|
|
144
86
|
*
|
|
145
87
|
* @example
|
|
146
|
-
*
|
|
88
|
+
* logger.setOptions({level: 'INFO'}) // set logger level
|
|
147
89
|
*
|
|
148
90
|
* @param {LoggerOptions} options logger options
|
|
149
91
|
* @return {void}
|
|
150
92
|
*/
|
|
151
|
-
Logger.setOptions = function (options) {
|
|
152
|
-
|
|
153
|
-
|
|
93
|
+
Logger.prototype.setOptions = function (options) {
|
|
94
|
+
this._options = options;
|
|
95
|
+
this._levelNum = this._matchLevel(options.level || 'DEBUG');
|
|
96
|
+
if (this._levelNum !== 0) {
|
|
97
|
+
this.e = this._loggerFactory('error', this._levelNum <= 4);
|
|
98
|
+
this.w = this._loggerFactory('warn', this._levelNum <= 3);
|
|
99
|
+
this.i = this._loggerFactory('info', this._levelNum <= 2);
|
|
100
|
+
this.v = this._loggerFactory('warn', this._levelNum <= 1);
|
|
101
|
+
this.d = this._loggerFactory('warn', this._levelNum < 1);
|
|
102
|
+
}
|
|
154
103
|
};
|
|
155
104
|
/**
|
|
156
|
-
* @description
|
|
105
|
+
* @description Private method used to match logger level
|
|
157
106
|
* @static
|
|
158
107
|
* @private
|
|
159
108
|
*
|
|
160
109
|
* @example
|
|
161
|
-
*
|
|
110
|
+
* this._matchLevel("DEBUG") // 0
|
|
162
111
|
*
|
|
163
112
|
* @param {LoggerLevel} level logger level
|
|
164
113
|
* @return {number}
|
|
165
114
|
*/
|
|
166
|
-
Logger._matchLevel = function (level) {
|
|
115
|
+
Logger.prototype._matchLevel = function (level) {
|
|
167
116
|
var logLevel = 0;
|
|
168
117
|
switch (level) {
|
|
169
118
|
case 'DEBUG':
|
|
@@ -184,10 +133,35 @@
|
|
|
184
133
|
}
|
|
185
134
|
return logLevel;
|
|
186
135
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
136
|
+
/**
|
|
137
|
+
* @private
|
|
138
|
+
* @description Logger factory
|
|
139
|
+
* @param type
|
|
140
|
+
* @param bool
|
|
141
|
+
* @returns
|
|
142
|
+
*/
|
|
143
|
+
Logger.prototype._loggerFactory = function (type, bool) {
|
|
144
|
+
var func = console[type];
|
|
145
|
+
if (bool && func) {
|
|
146
|
+
return func.bind(console, "[".concat(type.toLocaleUpperCase(), "]"));
|
|
147
|
+
}
|
|
148
|
+
return Logger.noop;
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* @description Get options
|
|
152
|
+
* @returns {LoggerOptions}
|
|
153
|
+
*/
|
|
154
|
+
Logger.prototype.getOptions = function () {
|
|
155
|
+
return this._options;
|
|
156
|
+
};
|
|
157
|
+
/**
|
|
158
|
+
* @description Get version
|
|
159
|
+
* @returns {string}
|
|
160
|
+
*/
|
|
161
|
+
Logger.prototype.version = function () {
|
|
162
|
+
return '1.0.0';
|
|
163
|
+
};
|
|
164
|
+
Logger.noop = function () { };
|
|
191
165
|
return Logger;
|
|
192
166
|
}());
|
|
193
167
|
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skax/logger",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "console logger",
|
|
5
5
|
"main": "index.js",
|
|
6
|
-
"umd": "
|
|
6
|
+
"umd": "index.umd.js",
|
|
7
7
|
"types": "types/index.d.ts",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
},
|
|
21
21
|
"homepage": "https://github.com/freeshineit/skax-logger#readme",
|
|
22
22
|
"engines": {
|
|
23
|
-
"node": ">=
|
|
23
|
+
"node": ">=16"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -4,95 +4,114 @@ export type LoggerLevel = 'DEBUG' | 'VERBOSE' | 'INFO' | 'WARN' | 'ERROR';
|
|
|
4
4
|
export interface LoggerOptions {
|
|
5
5
|
/** logger level */
|
|
6
6
|
level?: LoggerLevel;
|
|
7
|
-
/** hidden tag prefix */
|
|
8
|
-
hideTag?: boolean;
|
|
9
7
|
}
|
|
10
8
|
/**
|
|
11
|
-
* @class Logger
|
|
9
|
+
* @class Logger
|
|
12
10
|
* @classdesc Provide multiple log printing methods
|
|
11
|
+
* @example
|
|
12
|
+
* const logger = new Logger({})
|
|
13
|
+
* logger.v("verbose log")
|
|
13
14
|
*/
|
|
14
15
|
declare class Logger {
|
|
15
|
-
private static readonly
|
|
16
|
-
private
|
|
17
|
-
private
|
|
16
|
+
private static readonly noop;
|
|
17
|
+
private _options;
|
|
18
|
+
private _levelNum;
|
|
19
|
+
constructor(options?: LoggerOptions);
|
|
18
20
|
/**
|
|
19
|
-
* @description
|
|
21
|
+
* @description Method used to print error logs
|
|
20
22
|
* @static
|
|
21
23
|
*
|
|
22
24
|
* @example
|
|
23
|
-
*
|
|
25
|
+
* logger.e("error message") // error message
|
|
24
26
|
*
|
|
25
27
|
* @param {...any[]} args error messages
|
|
26
28
|
* @returns {void}
|
|
27
29
|
*/
|
|
28
|
-
|
|
30
|
+
e: any;
|
|
29
31
|
/**
|
|
30
|
-
* @description
|
|
32
|
+
* @description Method used to print warn logs
|
|
31
33
|
* @static
|
|
32
34
|
*
|
|
33
35
|
* @example
|
|
34
|
-
*
|
|
36
|
+
* logger.w("warn message") // warn message
|
|
35
37
|
*
|
|
36
38
|
* @param {...any[]} args warn messages
|
|
37
39
|
* @returns {void}
|
|
38
40
|
*/
|
|
39
|
-
|
|
41
|
+
w: any;
|
|
40
42
|
/**
|
|
41
|
-
* @description
|
|
43
|
+
* @description Method used to print info logs
|
|
42
44
|
* @static
|
|
43
45
|
*
|
|
44
46
|
* @example
|
|
45
|
-
*
|
|
47
|
+
* logger.i("info message") // info message
|
|
46
48
|
*
|
|
47
49
|
* @param {...any[]} args info messages
|
|
48
50
|
* @returns {void}
|
|
49
51
|
*/
|
|
50
|
-
|
|
52
|
+
i: any;
|
|
51
53
|
/**
|
|
52
|
-
* @description
|
|
54
|
+
* @description Method used to print verbose logs
|
|
53
55
|
* @static
|
|
54
56
|
*
|
|
55
57
|
* @example
|
|
56
|
-
*
|
|
58
|
+
* logger.v("verbose message") // verbose message
|
|
57
59
|
*
|
|
58
60
|
* @param {...any[]} args verbose messages
|
|
59
61
|
* @returns {void}
|
|
60
62
|
*/
|
|
61
|
-
|
|
63
|
+
v: any;
|
|
62
64
|
/**
|
|
63
|
-
* @description
|
|
65
|
+
* @description Method used to print debug logs
|
|
64
66
|
* @static
|
|
65
67
|
*
|
|
66
68
|
* @example
|
|
67
|
-
*
|
|
68
|
-
* Logger.d("debug message", "DEBUG") // [DEBUG] > debug message
|
|
69
|
+
* logger.d("debug message") // debug message
|
|
69
70
|
*
|
|
70
71
|
* @param {...any[]} msg debug messages
|
|
71
72
|
* @returns {void}
|
|
72
73
|
*/
|
|
73
|
-
|
|
74
|
+
d: any;
|
|
74
75
|
/**
|
|
75
|
-
* @description
|
|
76
|
+
* @description Method used to set logger option and change logger level
|
|
76
77
|
* @static
|
|
77
78
|
*
|
|
78
79
|
* @example
|
|
79
|
-
*
|
|
80
|
+
* logger.setOptions({level: 'INFO'}) // set logger level
|
|
80
81
|
*
|
|
81
82
|
* @param {LoggerOptions} options logger options
|
|
82
83
|
* @return {void}
|
|
83
84
|
*/
|
|
84
|
-
|
|
85
|
+
setOptions(options: Partial<LoggerOptions>): void;
|
|
85
86
|
/**
|
|
86
|
-
* @description
|
|
87
|
+
* @description Private method used to match logger level
|
|
87
88
|
* @static
|
|
88
89
|
* @private
|
|
89
90
|
*
|
|
90
91
|
* @example
|
|
91
|
-
*
|
|
92
|
+
* this._matchLevel("DEBUG") // 0
|
|
92
93
|
*
|
|
93
94
|
* @param {LoggerLevel} level logger level
|
|
94
95
|
* @return {number}
|
|
95
96
|
*/
|
|
96
|
-
private
|
|
97
|
+
private _matchLevel;
|
|
98
|
+
/**
|
|
99
|
+
* @private
|
|
100
|
+
* @description Logger factory
|
|
101
|
+
* @param type
|
|
102
|
+
* @param bool
|
|
103
|
+
* @returns
|
|
104
|
+
*/
|
|
105
|
+
private _loggerFactory;
|
|
106
|
+
/**
|
|
107
|
+
* @description Get options
|
|
108
|
+
* @returns {LoggerOptions}
|
|
109
|
+
*/
|
|
110
|
+
getOptions(): Partial<LoggerOptions>;
|
|
111
|
+
/**
|
|
112
|
+
* @description Get version
|
|
113
|
+
* @returns {string}
|
|
114
|
+
*/
|
|
115
|
+
version(): string;
|
|
97
116
|
}
|
|
98
117
|
export default Logger;
|