metalog 3.1.9 → 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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2022 Metarhia
3
+ Copyright (c) 2017-2023 Metarhia
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -31,6 +31,6 @@ await logger.close();
31
31
 
32
32
  ## License & Contributors
33
33
 
34
- Copyright (c) 2017-2022 [Metarhia contributors](https://github.com/metarhia/metalog/graphs/contributors).
34
+ Copyright (c) 2017-2023 [Metarhia contributors](https://github.com/metarhia/metalog/graphs/contributors).
35
35
  Metalog is [MIT licensed](./LICENSE).\
36
36
  Metalog is a part of [Metarhia](https://github.com/metarhia) technology stack.
package/metalog.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import EventEmitter = require('events');
1
+ import { EventEmitter } from 'node:events';
2
2
 
3
3
  interface LoggerOptions {
4
4
  path: string;
package/metalog.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
- const fs = require('fs');
3
+ const fs = require('node:fs');
4
4
  const fsp = fs.promises;
5
- const path = require('path');
6
- const util = require('util');
7
- const events = require('events');
8
- const readline = require('readline');
5
+ const path = require('node:path');
6
+ const util = require('node:util');
7
+ const events = require('node:events');
8
+ const readline = require('node:readline');
9
9
  const metautil = require('metautil');
10
10
  const concolor = require('concolor');
11
11
 
@@ -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
 
@@ -188,7 +188,7 @@ class Logger extends events.EventEmitter {
188
188
  super();
189
189
  const { workerId = 0, createStream = fs.createWriteStream } = args;
190
190
  const { writeInterval, writeBuffer, keepDays, home, json } = args;
191
- const { toFile, toStdout } = args;
191
+ const { toFile = [], toStdout = [] } = args;
192
192
  this.active = false;
193
193
  this.path = args.path;
194
194
  this.workerId = `W${workerId}`;
@@ -205,7 +205,7 @@ class Logger extends events.EventEmitter {
205
205
  this.buffer = [];
206
206
  this.file = '';
207
207
  this.toFile = logTypes(toFile);
208
- this.fsEnabled = Object.keys(this.toFile).length !== 0;
208
+ this.fsEnabled = toFile.length !== 0;
209
209
  this.toStdout = logTypes(toStdout);
210
210
  this.console = new Console((...args) => this.write(...args));
211
211
  return this.open();
@@ -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.9",
3
+ "version": "3.1.12",
4
4
  "author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",
5
5
  "description": "Logger for Metarhia",
6
6
  "license": "MIT",
@@ -38,10 +38,7 @@
38
38
  "main": "metalog.js",
39
39
  "types": "metalog.d.ts",
40
40
  "readmeFilename": "README.md",
41
- "files": [
42
- "types/",
43
- "metalog.d.ts"
44
- ],
41
+ "files": ["types/", "metalog.d.ts"],
45
42
  "scripts": {
46
43
  "test": "npm run lint && npm run types && metatests test/",
47
44
  "types": "tsc -p tsconfig.json",
@@ -49,21 +46,21 @@
49
46
  "fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/.*rc\" \"**/*.ts\""
50
47
  },
51
48
  "engines": {
52
- "node": "14 || 16 || 18"
49
+ "node": "16 || 18 || 19 || 20"
53
50
  },
54
51
  "dependencies": {
55
- "concolor": "^1.0.3",
56
- "metautil": "^3.5.21"
52
+ "concolor": "^1.0.6",
53
+ "metautil": "^3.10.0"
57
54
  },
58
55
  "devDependencies": {
59
- "@types/node": "^18.0.3",
60
- "eslint": "^8.19.0",
61
- "eslint-config-metarhia": "^8.1.0",
62
- "eslint-config-prettier": "^8.5.0",
63
- "eslint-plugin-import": "^2.25.4",
64
- "eslint-plugin-prettier": "^4.0.0",
56
+ "@types/node": "^20.4.1",
57
+ "eslint": "^8.44.0",
58
+ "eslint-config-metarhia": "^8.2.0",
59
+ "eslint-config-prettier": "^8.7.0",
60
+ "eslint-plugin-import": "^2.27.5",
61
+ "eslint-plugin-prettier": "^5.0.0-alpha.2",
65
62
  "metatests": "^0.8.2",
66
- "prettier": "^2.6.0",
67
- "typescript": "^4.6.2"
63
+ "prettier": "^3.0.0",
64
+ "typescript": "^5.1.6"
68
65
  }
69
66
  }
package/CHANGELOG.md DELETED
@@ -1,88 +0,0 @@
1
- # Changelog
2
-
3
- ## [Unreleased][unreleased]
4
-
5
- ## [3.1.9][] - 2022-07-07
6
-
7
- - Package maintenance
8
-
9
- ## [3.1.8][] - 2022-03-30
10
-
11
- - Add support for json-only logs
12
-
13
- ## [3.1.7][] - 2022-03-17
14
-
15
- - Fix unlink empty files
16
- - Improve error handling
17
- - Update dependencies and package maintenance
18
-
19
- ## [3.1.6][] - 2021-12-08
20
-
21
- - Fix typings
22
- - Remove useless code from tests
23
- - Fix unlink file bug
24
-
25
- ## [3.1.5][] - 2021-10-11
26
-
27
- - Update dependencies and npm audit fix
28
-
29
- ## [3.1.4][] - 2021-09-10
30
-
31
- - Update dependencies
32
-
33
- ## [3.1.3][] - 2021-07-22
34
-
35
- - Improve code style
36
- - Move types to package root
37
-
38
- ## [3.1.2][] - 2021-05-24
39
-
40
- - Package maintenance
41
-
42
- ## [3.1.1][] - 2021-01-15
43
-
44
- - Remove code duplication: use metautil.replace
45
- - Remove unneeded code and comments
46
- - Add examples to README.md
47
- - Add .d.ts typings
48
-
49
- ## [3.1.0][] - 2021-01-07
50
-
51
- - Use metautil instead of metarhia/common
52
- - Use writable factory instead of constructor
53
- - Use fs.createWriteStream instead of metastreams
54
-
55
- ## [3.0.0][] - 2020-12-16
56
-
57
- - Change Logger interface, use async/await
58
- - Console interface implementation
59
- - Create log folder if not exists
60
- - Support windows
61
-
62
- ## [2.x][]
63
-
64
- - New Logger class extends EventEmitter
65
- - Refactor module to use new ES2020 syntax and features
66
- - Rewrite code using async/await
67
- - Truncate paths in stack traces to minimize log files
68
- - Use metarhia eslint config
69
- - Fix multiple bugs and optimize performance
70
-
71
- ## [1.x][]
72
-
73
- First generation of Metarhia Logger
74
-
75
- [unreleased]: https://github.com/metarhia/metalog/compare/v3.1.9...HEAD
76
- [3.1.9]: https://github.com/metarhia/metalog/compare/v3.1.8...v3.1.9
77
- [3.1.8]: https://github.com/metarhia/metalog/compare/v3.1.7...v3.1.8
78
- [3.1.7]: https://github.com/metarhia/metalog/compare/v3.1.6...v3.1.7
79
- [3.1.6]: https://github.com/metarhia/metalog/compare/v3.1.5...v3.1.6
80
- [3.1.5]: https://github.com/metarhia/metalog/compare/v3.1.4...v3.1.5
81
- [3.1.4]: https://github.com/metarhia/metalog/compare/v3.1.3...v3.1.4
82
- [3.1.3]: https://github.com/metarhia/metalog/compare/v3.1.2...v3.1.3
83
- [3.1.2]: https://github.com/metarhia/metalog/compare/v3.1.1...v3.1.2
84
- [3.1.1]: https://github.com/metarhia/metalog/compare/v3.1.0...v3.1.1
85
- [3.1.0]: https://github.com/metarhia/metalog/compare/v3.0.0...v3.1.0
86
- [3.0.0]: https://github.com/metarhia/metalog/compare/v2.x...v3.0.0
87
- [2.x]: https://github.com/metarhia/metalog/compare/v1.x...v2.x
88
- [1.x]: https://github.com/metarhia/metalog/tree/v1.x