@tomjs/logger 1.1.4 → 1.3.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 CHANGED
@@ -29,8 +29,7 @@ interface LoggerOptions {
29
29
  declare class Logger {
30
30
  private _opts;
31
31
  private _logDir?;
32
- private _debug;
33
- constructor(opts?: LoggerOptions);
32
+ constructor(options?: LoggerOptions);
34
33
  private initLogDir;
35
34
  private format;
36
35
  private _writeLog;
@@ -39,6 +38,10 @@ declare class Logger {
39
38
  * set debug mode or not
40
39
  */
41
40
  enableDebug(debug: boolean): void;
41
+ /**
42
+ * set debug mode or not
43
+ */
44
+ setOptions(options: LoggerOptions): void;
42
45
  /**
43
46
  * like console.log
44
47
  */
@@ -67,6 +70,10 @@ declare class Logger {
67
70
  * add the specified yellow prefix or warning symbol before the log content
68
71
  */
69
72
  warning(...args: any[]): void;
73
+ /**
74
+ * add the specified yellow prefix or warning symbol before the log content
75
+ */
76
+ warn(...args: any[]): void;
70
77
  }
71
78
 
72
79
  export { Logger, type LoggerOptions, Logger as default };
package/dist/index.d.ts CHANGED
@@ -29,8 +29,7 @@ interface LoggerOptions {
29
29
  declare class Logger {
30
30
  private _opts;
31
31
  private _logDir?;
32
- private _debug;
33
- constructor(opts?: LoggerOptions);
32
+ constructor(options?: LoggerOptions);
34
33
  private initLogDir;
35
34
  private format;
36
35
  private _writeLog;
@@ -39,6 +38,10 @@ declare class Logger {
39
38
  * set debug mode or not
40
39
  */
41
40
  enableDebug(debug: boolean): void;
41
+ /**
42
+ * set debug mode or not
43
+ */
44
+ setOptions(options: LoggerOptions): void;
42
45
  /**
43
46
  * like console.log
44
47
  */
@@ -67,6 +70,10 @@ declare class Logger {
67
70
  * add the specified yellow prefix or warning symbol before the log content
68
71
  */
69
72
  warning(...args: any[]): void;
73
+ /**
74
+ * add the specified yellow prefix or warning symbol before the log content
75
+ */
76
+ warn(...args: any[]): void;
70
77
  }
71
78
 
72
79
  export { Logger, type LoggerOptions, Logger as default };
package/dist/index.js CHANGED
@@ -25,11 +25,9 @@ var _logsymbols2 = _interopRequireDefault(_logsymbols);
25
25
  var _stripansi = require('strip-ansi');
26
26
  var _stripansi2 = _interopRequireDefault(_stripansi);
27
27
  var Logger = class {
28
- constructor(opts) {
28
+ constructor(options) {
29
29
  this._opts = {};
30
- this._debug = false;
31
- this._opts = Object.assign({}, opts);
32
- this.initLogDir();
30
+ this.setOptions(Object.assign({}, options));
33
31
  }
34
32
  initLogDir() {
35
33
  const { directory, cleanup } = this._opts;
@@ -86,7 +84,11 @@ var Logger = class {
86
84
  console.log(list.map(s => (typeof s === 'object' ? '%o' : '%s')).join(' '), ...list);
87
85
  }
88
86
  enableDebug(debug) {
89
- this._debug = !!debug;
87
+ this._opts.debug = !!debug;
88
+ }
89
+ setOptions(options) {
90
+ this._opts = Object.assign({}, options);
91
+ this.initLogDir();
90
92
  }
91
93
  log(...args) {
92
94
  this._log(...args);
@@ -95,7 +97,7 @@ var Logger = class {
95
97
  this._writeLog(...args);
96
98
  }
97
99
  debug(...args) {
98
- if (this._debug) {
100
+ if (this._opts.debug) {
99
101
  this._log(
100
102
  ...args.map(s => {
101
103
  if (typeof s !== 'object') {
@@ -122,6 +124,9 @@ var Logger = class {
122
124
  const { prefix } = this._opts;
123
125
  this._log(prefix ? _chalk2.default.yellow(prefix) : _logsymbols2.default.warning, ...args);
124
126
  }
127
+ warn(...args) {
128
+ this.warning(...args);
129
+ }
125
130
  };
126
131
  var src_default = Logger;
127
132
  exports.Logger = Logger;
package/dist/index.mjs CHANGED
@@ -6,11 +6,9 @@ import dayjs from 'dayjs';
6
6
  import logSymbols from 'log-symbols';
7
7
  import stripAnsi from 'strip-ansi';
8
8
  var Logger = class {
9
- constructor(opts) {
9
+ constructor(options) {
10
10
  this._opts = {};
11
- this._debug = false;
12
- this._opts = Object.assign({}, opts);
13
- this.initLogDir();
11
+ this.setOptions(Object.assign({}, options));
14
12
  }
15
13
  initLogDir() {
16
14
  const { directory, cleanup } = this._opts;
@@ -57,7 +55,11 @@ var Logger = class {
57
55
  console.log(list.map(s => (typeof s === 'object' ? '%o' : '%s')).join(' '), ...list);
58
56
  }
59
57
  enableDebug(debug) {
60
- this._debug = !!debug;
58
+ this._opts.debug = !!debug;
59
+ }
60
+ setOptions(options) {
61
+ this._opts = Object.assign({}, options);
62
+ this.initLogDir();
61
63
  }
62
64
  log(...args) {
63
65
  this._log(...args);
@@ -66,7 +68,7 @@ var Logger = class {
66
68
  this._writeLog(...args);
67
69
  }
68
70
  debug(...args) {
69
- if (this._debug) {
71
+ if (this._opts.debug) {
70
72
  this._log(
71
73
  ...args.map(s => {
72
74
  if (typeof s !== 'object') {
@@ -93,6 +95,9 @@ var Logger = class {
93
95
  const { prefix } = this._opts;
94
96
  this._log(prefix ? chalk.yellow(prefix) : logSymbols.warning, ...args);
95
97
  }
98
+ warn(...args) {
99
+ this.warning(...args);
100
+ }
96
101
  };
97
102
  var src_default = Logger;
98
103
  export { Logger, src_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomjs/logger",
3
- "version": "1.1.4",
3
+ "version": "1.3.0",
4
4
  "description": "logger for `node.js`",
5
5
  "keywords": [
6
6
  "node",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "chalk": "^4.1.2",
46
- "dayjs": "^1.11.11",
46
+ "dayjs": "^1.11.13",
47
47
  "log-symbols": "^4.1.0",
48
48
  "strip-ansi": "^6.0.1"
49
49
  },