metalog 3.1.11 → 3.1.12

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.
Files changed (3) hide show
  1. package/metalog.d.ts +1 -1
  2. package/metalog.js +36 -42
  3. package/package.json +8 -8
package/metalog.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import EventEmitter = require('node:events');
1
+ import { EventEmitter } from 'node:events';
2
2
 
3
3
  interface LoggerOptions {
4
4
  path: string;
package/metalog.js CHANGED
@@ -77,74 +77,74 @@ const getNextReopen = () => {
77
77
  return nextDate - curTime + DAY_MILLISECONDS;
78
78
  };
79
79
 
80
- const isError = (val) =>
81
- Object.prototype.toString.call(val) === '[object Error]';
82
-
83
80
  class Console {
81
+ #write;
82
+ #groupIndent = 0;
83
+ #counts = new Map();
84
+ #times = new Map();
85
+ #readline = readline;
86
+
84
87
  constructor(write) {
85
- this._write = write;
86
- this._groupIndent = 0;
87
- this._counts = new Map();
88
- this._times = new Map();
88
+ this.#write = write;
89
89
  }
90
90
 
91
91
  assert(assertion, ...args) {
92
92
  try {
93
93
  console.assert(assertion, ...args);
94
94
  } catch (err) {
95
- this._write('error', this._groupIndent, err.stack);
95
+ this.#write('error', this.#groupIndent, err.stack);
96
96
  }
97
97
  }
98
98
 
99
99
  clear() {
100
- readline.cursorTo(process.stdout, 0, 0);
101
- readline.clearScreenDown(process.stdout);
100
+ this.#readline.cursorTo(process.stdout, 0, 0);
101
+ this.#readline.clearScreenDown(process.stdout);
102
102
  }
103
103
 
104
104
  count(label = 'default') {
105
- let cnt = this._counts.get(label) || 0;
105
+ let cnt = this.#counts.get(label) || 0;
106
106
  cnt++;
107
- this._counts.set(label, cnt);
108
- this._write('debug', this._groupIndent, `${label}: ${cnt}`);
107
+ this.#counts.set(label, cnt);
108
+ this.#write('debug', this.#groupIndent, `${label}: ${cnt}`);
109
109
  }
110
110
 
111
111
  countReset(label = 'default') {
112
- this._counts.delete(label);
112
+ this.#counts.delete(label);
113
113
  }
114
114
 
115
115
  debug(...args) {
116
- this._write('debug', this._groupIndent, ...args);
116
+ this.#write('debug', this.#groupIndent, ...args);
117
117
  }
118
118
 
119
119
  dir(...args) {
120
- this._write('debug', this._groupIndent, ...args);
120
+ this.#write('debug', this.#groupIndent, ...args);
121
121
  }
122
122
 
123
123
  trace(...args) {
124
124
  const msg = util.format(...args);
125
125
  const err = new Error(msg);
126
- this._write('debug', this._groupIndent, `Trace${err.stack}`);
126
+ this.#write('debug', this.#groupIndent, `Trace${err.stack}`);
127
127
  }
128
128
 
129
129
  info(...args) {
130
- this._write('info', this._groupIndent, ...args);
130
+ this.#write('info', this.#groupIndent, ...args);
131
131
  }
132
132
 
133
133
  log(...args) {
134
- this._write('log', this._groupIndent, ...args);
134
+ this.#write('log', this.#groupIndent, ...args);
135
135
  }
136
136
 
137
137
  warn(...args) {
138
- this._write('warn', this._groupIndent, ...args);
138
+ this.#write('warn', this.#groupIndent, ...args);
139
139
  }
140
140
 
141
141
  error(...args) {
142
- this._write('error', this._groupIndent, ...args);
142
+ this.#write('error', this.#groupIndent, ...args);
143
143
  }
144
144
 
145
145
  group(...args) {
146
146
  if (args.length !== 0) this.log(...args);
147
- this._groupIndent += INDENT;
147
+ this.#groupIndent += INDENT;
148
148
  }
149
149
 
150
150
  groupCollapsed(...args) {
@@ -152,34 +152,34 @@ class Console {
152
152
  }
153
153
 
154
154
  groupEnd() {
155
- if (this._groupIndent.length === 0) return;
156
- this._groupIndent -= INDENT;
155
+ if (this.#groupIndent.length === 0) return;
156
+ this.#groupIndent -= INDENT;
157
157
  }
158
158
 
159
159
  table(tabularData) {
160
- this._write('log', 0, JSON.stringify(tabularData));
160
+ this.#write('log', 0, JSON.stringify(tabularData));
161
161
  }
162
162
 
163
163
  time(label = 'default') {
164
- this._times.set(label, process.hrtime());
164
+ this.#times.set(label, process.hrtime());
165
165
  }
166
166
 
167
167
  timeEnd(label = 'default') {
168
- const startTime = this._times.get(label);
168
+ const startTime = this.#times.get(label);
169
169
  const totalTime = process.hrtime(startTime);
170
170
  const totalTimeMs = totalTime[0] * 1e3 + totalTime[1] / 1e6;
171
171
  this.timeLog(label, `${label}: ${totalTimeMs}ms`);
172
- this._times.delete(label);
172
+ this.#times.delete(label);
173
173
  }
174
174
 
175
175
  timeLog(label, ...args) {
176
- const startTime = this._times.get(label);
176
+ const startTime = this.#times.get(label);
177
177
  if (startTime === undefined) {
178
178
  const msg = `Warning: No such label '${label}'`;
179
- this._write('warn', this._groupIndent, msg);
179
+ this.#write('warn', this.#groupIndent, msg);
180
180
  return;
181
181
  }
182
- this._write('debug', this._groupIndent, ...args);
182
+ this.#write('debug', this.#groupIndent, ...args);
183
183
  }
184
184
  }
185
185
 
@@ -216,10 +216,7 @@ class Logger extends events.EventEmitter {
216
216
  fs.access(this.path, (err) => {
217
217
  if (!err) resolve();
218
218
  fs.mkdir(this.path, (err) => {
219
- if (!err || err.code === 'EEXIST') {
220
- resolve();
221
- return;
222
- }
219
+ if (!err || err.code === 'EEXIST') return void resolve();
223
220
  const error = new Error(`Can not create directory: ${this.path}\n`);
224
221
  this.emit('error', error);
225
222
  reject();
@@ -277,10 +274,7 @@ class Logger extends events.EventEmitter {
277
274
  }
278
275
  return new Promise((resolve, reject) => {
279
276
  this.flush((err) => {
280
- if (err) {
281
- reject(err);
282
- return;
283
- }
277
+ if (err) return void reject(err);
284
278
  this.active = false;
285
279
  stream.end(() => {
286
280
  clearInterval(this.flushTimer);
@@ -351,13 +345,13 @@ class Logger extends events.EventEmitter {
351
345
  level: type,
352
346
  message: null,
353
347
  };
354
- if (isError(args[0])) {
348
+ if (metautil.isError(args[0])) {
355
349
  log.err = this.expandError(args[0]);
356
350
  args = args.slice(1);
357
351
  } else if (typeof args[0] === 'object') {
358
352
  Object.assign(log, args[0]);
359
- if (isError(log.err)) log.err = this.expandError(log.err);
360
- if (isError(log.error)) log.error = this.expandError(log.error);
353
+ if (metautil.isError(log.err)) log.err = this.expandError(log.err);
354
+ if (metautil.isError(log.error)) log.error = this.expandError(log.error);
361
355
  args = args.slice(1);
362
356
  }
363
357
  log.message = util.format(...args);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metalog",
3
- "version": "3.1.11",
3
+ "version": "3.1.12",
4
4
  "author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",
5
5
  "description": "Logger for Metarhia",
6
6
  "license": "MIT",
@@ -50,17 +50,17 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "concolor": "^1.0.6",
53
- "metautil": "^3.7.2"
53
+ "metautil": "^3.10.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@types/node": "^18.16.1",
57
- "eslint": "^8.36.0",
58
- "eslint-config-metarhia": "^8.1.0",
56
+ "@types/node": "^20.4.1",
57
+ "eslint": "^8.44.0",
58
+ "eslint-config-metarhia": "^8.2.0",
59
59
  "eslint-config-prettier": "^8.7.0",
60
60
  "eslint-plugin-import": "^2.27.5",
61
- "eslint-plugin-prettier": "^4.0.0",
61
+ "eslint-plugin-prettier": "^5.0.0-alpha.2",
62
62
  "metatests": "^0.8.2",
63
- "prettier": "^2.8.4",
64
- "typescript": "^5.0.4"
63
+ "prettier": "^3.0.0",
64
+ "typescript": "^5.1.6"
65
65
  }
66
66
  }