metalog 3.1.2 → 3.1.6

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/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  ## [Unreleased][unreleased]
4
4
 
5
+ ## [3.1.6][] - 2021-12-08
6
+
7
+ - Fix typings
8
+ - Remove useless code from tests
9
+ - Fix unlink file bug
10
+
11
+ ## [3.1.5][] - 2021-10-11
12
+
13
+ - Update dependencies and npm audit fix
14
+
15
+ ## [3.1.4][] - 2021-09-10
16
+
17
+ - Update dependencies
18
+
19
+ ## [3.1.3][] - 2021-07-22
20
+
21
+ - Improve code style
22
+ - Move types to package root
23
+
5
24
  ## [3.1.2][] - 2021-05-24
6
25
 
7
26
  - Package maintenance
@@ -39,7 +58,11 @@
39
58
 
40
59
  First generation of Metarhia Logger
41
60
 
42
- [unreleased]: https://github.com/metarhia/metalog/compare/v3.1.2...HEAD
61
+ [unreleased]: https://github.com/metarhia/metalog/compare/v3.1.6...HEAD
62
+ [3.1.6]: https://github.com/metarhia/metalog/compare/v3.1.5...v3.1.6
63
+ [3.1.5]: https://github.com/metarhia/metalog/compare/v3.1.4...v3.1.5
64
+ [3.1.4]: https://github.com/metarhia/metalog/compare/v3.1.3...v3.1.4
65
+ [3.1.3]: https://github.com/metarhia/metalog/compare/v3.1.2...v3.1.3
43
66
  [3.1.2]: https://github.com/metarhia/metalog/compare/v3.1.1...v3.1.2
44
67
  [3.1.1]: https://github.com/metarhia/metalog/compare/v3.1.0...v3.1.1
45
68
  [3.1.0]: https://github.com/metarhia/metalog/compare/v3.0.0...v3.1.0
package/README.md CHANGED
@@ -29,12 +29,8 @@ console.log('Test message');
29
29
  await logger.close();
30
30
  ```
31
31
 
32
- ## Contributors
32
+ ## License & Contributors
33
33
 
34
- - Timur Shemsedinov <timur.shemsedinov@gmail.com>
35
- - See github for full [contributors list](https://github.com/metarhia/metalog/graphs/contributors)
36
-
37
- ## License
38
-
39
- Copyright (c) 2017-2021 Metarhia contributors.
40
- Metalog is [MIT licensed](./LICENSE).
34
+ Copyright (c) 2017-2021 [Metarhia contributors](https://github.com/metarhia/metalog/graphs/contributors).
35
+ Metalog is [MIT licensed](./LICENSE).\
36
+ Metalog is a part of [Metarhia](https://github.com/metarhia) technology stack.
@@ -3,13 +3,13 @@ import EventEmitter = require('events');
3
3
  interface LoggerOptions {
4
4
  path: string;
5
5
  home: string;
6
- workerId: number;
7
- createStream: () => NodeJS.WritableStream;
6
+ workerId?: number;
7
+ createStream?: () => NodeJS.WritableStream;
8
8
  writeInterval: number;
9
9
  writeBuffer: number;
10
10
  keepDays: number;
11
- toFile: Array<string>;
12
- toStdout: Array<string>;
11
+ toFile?: Array<string>;
12
+ toStdout?: Array<string>;
13
13
  }
14
14
 
15
15
  export class Logger extends EventEmitter {
@@ -27,9 +27,9 @@ export class Logger extends EventEmitter {
27
27
  lock: boolean;
28
28
  buffer: Array<Buffer>;
29
29
  file: string;
30
- toFile: Array<string>;
30
+ toFile: Record<string, boolean>;
31
31
  fsEnabled: boolean;
32
- toStdout: Array<string>;
32
+ toStdout: Record<string, boolean>;
33
33
  console: Console;
34
34
  constructor(args: LoggerOptions);
35
35
  createLogDir(): Promise<void>;
package/metalog.js CHANGED
@@ -16,10 +16,14 @@ const DEFAULT_KEEP_DAYS = 1;
16
16
  const STACK_AT = ' at ';
17
17
  const TYPE_LENGTH = 6;
18
18
  const LINE_SEPARATOR = ';';
19
+ const INDENT = 2;
20
+ const DATE_LEN = 'YYYY-MM-DD'.length;
21
+ const TIME_START = DATE_LEN + 1;
22
+ const TIME_END = TIME_START + 'HH:MM:SS'.length;
19
23
 
20
- const LOG_TYPES = ['error', 'warn', 'info', 'debug', 'log'];
24
+ const LOG_TYPES = ['log', 'info', 'warn', 'debug', 'error'];
21
25
 
22
- const typeColor = concolor({
26
+ const TYPE_COLOR = concolor({
23
27
  log: 'b,black/white',
24
28
  info: 'b,white/blue',
25
29
  warn: 'b,black/yellow',
@@ -27,7 +31,7 @@ const typeColor = concolor({
27
31
  error: 'b,yellow/red',
28
32
  });
29
33
 
30
- const textColor = concolor({
34
+ const TEXT_COLOR = concolor({
31
35
  log: 'white',
32
36
  info: 'white',
33
37
  warn: 'b,yellow',
@@ -35,9 +39,16 @@ const textColor = concolor({
35
39
  error: 'red',
36
40
  });
37
41
 
38
- const logTypes = (types) => {
39
- types = types || LOG_TYPES;
40
- const flags = {};
42
+ const DEFAULT_FLAGS = {
43
+ log: false,
44
+ info: false,
45
+ warn: false,
46
+ debug: false,
47
+ error: false,
48
+ };
49
+
50
+ const logTypes = (types = LOG_TYPES) => {
51
+ const flags = { ...DEFAULT_FLAGS };
41
52
  for (const type of types) {
42
53
  flags[type] = true;
43
54
  }
@@ -54,7 +65,8 @@ const nowDays = () => {
54
65
  };
55
66
 
56
67
  const nameToDays = (fileName) => {
57
- const fileTime = new Date(fileName.substring(0, 10)).getTime();
68
+ const date = fileName.substring(0, DATE_LEN);
69
+ const fileTime = new Date(date).getTime();
58
70
  return Math.floor(fileTime / DAY_MILLISECONDS);
59
71
  };
60
72
 
@@ -114,7 +126,7 @@ class Console {
114
126
 
115
127
  group(...args) {
116
128
  if (args.length !== 0) this.log(...args);
117
- this._groupIndent = ' '.repeat(this._groupIndent.length + 2);
129
+ this._groupIndent = ' '.repeat(this._groupIndent.length + INDENT);
118
130
  }
119
131
 
120
132
  groupCollapsed(...args) {
@@ -123,7 +135,7 @@ class Console {
123
135
 
124
136
  groupEnd() {
125
137
  if (this._groupIndent.length === 0) return;
126
- this._groupIndent = ' '.repeat(this._groupIndent.length - 2);
138
+ this._groupIndent = ' '.repeat(this._groupIndent.length - INDENT);
127
139
  }
128
140
 
129
141
  info(...args) {
@@ -282,7 +294,7 @@ class Logger extends events.EventEmitter {
282
294
  resolve();
283
295
  fs.stat(fileName, (err, stats) => {
284
296
  if (!err && stats.size === 0) {
285
- fsp.unlink(this.file);
297
+ fsp.unlink(fileName).catch(() => {});
286
298
  }
287
299
  });
288
300
  });
@@ -315,9 +327,9 @@ class Logger extends events.EventEmitter {
315
327
  const normalize = type === 'error' || type === 'debug';
316
328
  const message = normalize ? this.normalizeStack(s) : s;
317
329
  if (this.toStdout[type]) {
318
- const normalColor = textColor[type];
319
- const markColor = typeColor[type];
320
- const time = normalColor(dateTime.substring(11, 19));
330
+ const normalColor = TEXT_COLOR[type];
331
+ const markColor = TYPE_COLOR[type];
332
+ const time = normalColor(dateTime.substring(TIME_START, TIME_END));
321
333
  const id = normalColor(this.workerId);
322
334
  const mark = markColor(' ' + type.padEnd(TYPE_LENGTH));
323
335
  const msg = normalColor(message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "metalog",
3
- "version": "3.1.2",
3
+ "version": "3.1.6",
4
4
  "author": "Timur Shemsedinov <timur.shemsedinov@gmail.com>",
5
5
  "description": "Logger for Metarhia",
6
6
  "license": "MIT",
@@ -36,14 +36,15 @@
36
36
  "url": "https://www.patreon.com/tshemsedinov"
37
37
  },
38
38
  "main": "metalog.js",
39
- "types": "types/metalog.d.ts",
39
+ "types": "metalog.d.ts",
40
40
  "readmeFilename": "README.md",
41
41
  "files": [
42
- "types/"
42
+ "types/",
43
+ "metalog.d.ts"
43
44
  ],
44
45
  "scripts": {
45
46
  "test": "npm run lint && npm run types && metatests test/",
46
- "types": "tsc -p types/tsconfig.json",
47
+ "types": "tsc -p tsconfig.json",
47
48
  "lint": "eslint . && prettier --check \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/.*rc\" \"**/*.ts\"",
48
49
  "fmt": "prettier --write \"**/*.js\" \"**/*.json\" \"**/*.md\" \"**/.*rc\" \"**/*.ts\""
49
50
  },
@@ -51,18 +52,18 @@
51
52
  "node": "^12.10 || 14 || 16"
52
53
  },
53
54
  "dependencies": {
54
- "concolor": "^1.0.1",
55
- "metautil": "^3.5.3"
55
+ "concolor": "^1.0.2",
56
+ "metautil": "^3.5.16"
56
57
  },
57
58
  "devDependencies": {
58
- "@types/node": "^15.6.0",
59
- "eslint": "^7.27.0",
59
+ "@types/node": "^16.10.3",
60
+ "eslint": "^7.32.0",
60
61
  "eslint-config-metarhia": "^7.0.0",
61
62
  "eslint-config-prettier": "^8.3.0",
62
- "eslint-plugin-import": "^2.23.3",
63
- "eslint-plugin-prettier": "^3.4.0",
63
+ "eslint-plugin-import": "^2.24.2",
64
+ "eslint-plugin-prettier": "^4.0.0",
64
65
  "metatests": "^0.7.2",
65
- "prettier": "^2.3.0",
66
- "typescript": "^4.2.4"
66
+ "prettier": "^2.4.1",
67
+ "typescript": "^4.4.3"
67
68
  }
68
69
  }
@@ -1,11 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ESNext",
4
- "moduleResolution": "node",
5
- "strict": true,
6
- "noEmit": true,
7
- "baseUrl": ".",
8
- "preserveWatchOutput": true
9
- },
10
- "include": ["*.d.ts"]
11
- }