@tomjs/logger 1.2.0 → 1.4.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/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +6 -2
- package/dist/index.mjs +6 -2
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,10 @@ interface LoggerOptions {
|
|
|
22
22
|
* @default 30
|
|
23
23
|
*/
|
|
24
24
|
cleanup?: number;
|
|
25
|
+
/**
|
|
26
|
+
* log file root directory,default is '~/.tomjs'
|
|
27
|
+
*/
|
|
28
|
+
root?: string;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* log tool
|
|
@@ -70,6 +74,10 @@ declare class Logger {
|
|
|
70
74
|
* add the specified yellow prefix or warning symbol before the log content
|
|
71
75
|
*/
|
|
72
76
|
warning(...args: any[]): void;
|
|
77
|
+
/**
|
|
78
|
+
* add the specified yellow prefix or warning symbol before the log content
|
|
79
|
+
*/
|
|
80
|
+
warn(...args: any[]): void;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
export { Logger, type LoggerOptions, Logger as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ interface LoggerOptions {
|
|
|
22
22
|
* @default 30
|
|
23
23
|
*/
|
|
24
24
|
cleanup?: number;
|
|
25
|
+
/**
|
|
26
|
+
* log file root directory,default is '~/.tomjs'
|
|
27
|
+
*/
|
|
28
|
+
root?: string;
|
|
25
29
|
}
|
|
26
30
|
/**
|
|
27
31
|
* log tool
|
|
@@ -70,6 +74,10 @@ declare class Logger {
|
|
|
70
74
|
* add the specified yellow prefix or warning symbol before the log content
|
|
71
75
|
*/
|
|
72
76
|
warning(...args: any[]): void;
|
|
77
|
+
/**
|
|
78
|
+
* add the specified yellow prefix or warning symbol before the log content
|
|
79
|
+
*/
|
|
80
|
+
warn(...args: any[]): void;
|
|
73
81
|
}
|
|
74
82
|
|
|
75
83
|
export { Logger, type LoggerOptions, Logger as default };
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,8 @@ var Logger = class {
|
|
|
34
34
|
if (!directory) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
const
|
|
37
|
+
const root = this._opts.root || _path2.default.join(_os2.default.homedir(), '.tomjs');
|
|
38
|
+
const logDir = _path2.default.join(root, directory);
|
|
38
39
|
this._logDir = logDir;
|
|
39
40
|
if (!_fs2.default.existsSync(logDir)) {
|
|
40
41
|
_fs2.default.mkdirSync(logDir, { recursive: true });
|
|
@@ -79,7 +80,7 @@ var Logger = class {
|
|
|
79
80
|
this._writeLog(...args);
|
|
80
81
|
let list = [...args];
|
|
81
82
|
if (this._opts.time) {
|
|
82
|
-
list = [_dayjs2.default.call(void 0).format('HH:mm:ss'), ...list];
|
|
83
|
+
list = [_chalk2.default.gray(_dayjs2.default.call(void 0).format('HH:mm:ss')), ...list];
|
|
83
84
|
}
|
|
84
85
|
console.log(list.map(s => (typeof s === 'object' ? '%o' : '%s')).join(' '), ...list);
|
|
85
86
|
}
|
|
@@ -124,6 +125,9 @@ var Logger = class {
|
|
|
124
125
|
const { prefix } = this._opts;
|
|
125
126
|
this._log(prefix ? _chalk2.default.yellow(prefix) : _logsymbols2.default.warning, ...args);
|
|
126
127
|
}
|
|
128
|
+
warn(...args) {
|
|
129
|
+
this.warning(...args);
|
|
130
|
+
}
|
|
127
131
|
};
|
|
128
132
|
var src_default = Logger;
|
|
129
133
|
exports.Logger = Logger;
|
package/dist/index.mjs
CHANGED
|
@@ -15,7 +15,8 @@ var Logger = class {
|
|
|
15
15
|
if (!directory) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const root = this._opts.root || path.join(os.homedir(), '.tomjs');
|
|
19
|
+
const logDir = path.join(root, directory);
|
|
19
20
|
this._logDir = logDir;
|
|
20
21
|
if (!fs.existsSync(logDir)) {
|
|
21
22
|
fs.mkdirSync(logDir, { recursive: true });
|
|
@@ -50,7 +51,7 @@ var Logger = class {
|
|
|
50
51
|
this._writeLog(...args);
|
|
51
52
|
let list = [...args];
|
|
52
53
|
if (this._opts.time) {
|
|
53
|
-
list = [dayjs().format('HH:mm:ss'), ...list];
|
|
54
|
+
list = [chalk.gray(dayjs().format('HH:mm:ss')), ...list];
|
|
54
55
|
}
|
|
55
56
|
console.log(list.map(s => (typeof s === 'object' ? '%o' : '%s')).join(' '), ...list);
|
|
56
57
|
}
|
|
@@ -95,6 +96,9 @@ var Logger = class {
|
|
|
95
96
|
const { prefix } = this._opts;
|
|
96
97
|
this._log(prefix ? chalk.yellow(prefix) : logSymbols.warning, ...args);
|
|
97
98
|
}
|
|
99
|
+
warn(...args) {
|
|
100
|
+
this.warning(...args);
|
|
101
|
+
}
|
|
98
102
|
};
|
|
99
103
|
var src_default = Logger;
|
|
100
104
|
export { Logger, src_default as default };
|