larvitutils 5.0.16 → 5.1.2

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,4 +1,4 @@
1
- Copyright 2019 LARV IT AB
1
+ Copyright 2022 LARV IT AB
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
4
4
 
package/README.md CHANGED
@@ -175,7 +175,7 @@ This is ment as a very simple replacement for winston
175
175
  import { Log } from 'larvitutils';
176
176
  const log = new Log();
177
177
 
178
- log.info('Hello'); // prints to stdout "2018-08-08T20:02:34Z [inf] Hello
178
+ log.info('Hello', { foo: 'bar' }); // prints to stdout "2018-08-08T20:02:34Z [inf] Hello {"foo":"bar}
179
179
  log.error('Hello'); // prints to stderr "2018-08-08T20:02:48Z [err] Hello
180
180
  ```
181
181
 
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import { KeyValues, LogInstance, LogLevel, LogOptions, UniqueKeyValues, UtilsOptions } from './models';
2
+ import { KeyValues, LogInstance, LogLevel, LogOptions, Metadata, UniqueKeyValues, UtilsOptions } from './models';
3
3
  declare class Log {
4
4
  private readonly validLogLevels;
5
5
  private options;
@@ -10,14 +10,15 @@ declare class Log {
10
10
  * @param options.level[=process.env.NODE_LOG_LVL] - log level
11
11
  */
12
12
  constructor(options?: LogOptions | LogLevel);
13
- stdout(lvl: string, msg: string): void;
14
- stderr(lvl: string, msg: string): void;
15
- silly(msg: string): void;
16
- debug(msg: string): void;
17
- verbose(msg: string): void;
18
- info(msg: string): void;
19
- warn(msg: string): void;
20
- error(msg: string): void;
13
+ private frmtStr;
14
+ stdout(lvl: string, msg: string, metadata?: Metadata): void;
15
+ stderr(lvl: string, msg: string, metadata?: Metadata): void;
16
+ silly(msg: string, metadata?: Metadata): void;
17
+ debug(msg: string, metadata?: Metadata): void;
18
+ verbose(msg: string, metadata?: Metadata): void;
19
+ info(msg: string, metadata?: Metadata): void;
20
+ warn(msg: string, metadata?: Metadata): void;
21
+ error(msg: string, metadata?: Metadata): void;
21
22
  private getDefaultLogLevel;
22
23
  private optionsIsLogOptions;
23
24
  private isLogLevel;
package/dist/index.js CHANGED
@@ -27,42 +27,49 @@ class Log {
27
27
  this.options = { level: defaultLogLevel };
28
28
  }
29
29
  }
30
- stdout(lvl, msg) {
30
+ frmtStr(lvl, msg, metadata) {
31
+ let str = `${(new Date()).toISOString().substring(0, 19)}Z [${lvl}] ${msg}`;
32
+ if (metadata) {
33
+ str += ` ${JSON.stringify(metadata)}`;
34
+ }
35
+ return str;
36
+ }
37
+ stdout(lvl, msg, metadata) {
31
38
  // tslint:disable-next-line:no-console
32
- console.log((new Date()).toISOString().substring(0, 19) + 'Z [' + lvl + '] ' + msg);
39
+ console.log(this.frmtStr(lvl, msg, metadata));
33
40
  }
34
- stderr(lvl, msg) {
41
+ stderr(lvl, msg, metadata) {
35
42
  // tslint:disable-next-line:no-console
36
- console.error((new Date()).toISOString().substring(0, 19) + 'Z [' + lvl + '] ' + msg);
43
+ console.error(this.frmtStr(lvl, msg, metadata));
37
44
  }
38
- silly(msg) {
45
+ silly(msg, metadata) {
39
46
  if (this.options.level === 'silly') {
40
- this.stdout('\x1b[1;37msil\x1b[0m', msg);
47
+ this.stdout('\x1b[1;37msil\x1b[0m', msg, metadata);
41
48
  }
42
49
  }
43
- debug(msg) {
50
+ debug(msg, metadata) {
44
51
  if (['silly', 'debug'].includes(this.options.level)) {
45
- this.stdout('\x1b[1;35mdeb\x1b[0m', msg);
52
+ this.stdout('\x1b[1;35mdeb\x1b[0m', msg, metadata);
46
53
  }
47
54
  }
48
- verbose(msg) {
55
+ verbose(msg, metadata) {
49
56
  if (['silly', 'debug', 'verbose'].includes(this.options.level)) {
50
- this.stdout('\x1b[1;34mver\x1b[0m', msg);
57
+ this.stdout('\x1b[1;34mver\x1b[0m', msg, metadata);
51
58
  }
52
59
  }
53
- info(msg) {
60
+ info(msg, metadata) {
54
61
  if (['silly', 'debug', 'verbose', 'info'].includes(this.options.level)) {
55
- this.stdout('\x1b[1;32minf\x1b[0m', msg);
62
+ this.stdout('\x1b[1;32minf\x1b[0m', msg, metadata);
56
63
  }
57
64
  }
58
- warn(msg) {
65
+ warn(msg, metadata) {
59
66
  if (['silly', 'debug', 'verbose', 'info', 'warn'].includes(this.options.level)) {
60
- this.stderr('\x1b[1;33mwar\x1b[0m', msg);
67
+ this.stderr('\x1b[1;33mwar\x1b[0m', msg, metadata);
61
68
  }
62
69
  }
63
- error(msg) {
70
+ error(msg, metadata) {
64
71
  if (['silly', 'debug', 'verbose', 'info', 'warn', 'error'].includes(this.options.level)) {
65
- this.stderr('\x1b[1;31merr\x1b[0m', msg);
72
+ this.stderr('\x1b[1;31merr\x1b[0m', msg, metadata);
66
73
  }
67
74
  }
68
75
  getDefaultLogLevel() {
package/dist/models.d.ts CHANGED
@@ -21,6 +21,10 @@ type LogOptions = {
21
21
  level: LogLevel | undefined;
22
22
  };
23
23
 
24
+ type Metadata = {
25
+ [key: string]: string | number | boolean
26
+ }
27
+
24
28
  type UniqueKeyValues = {
25
29
  [key: string]: string;
26
30
  };
@@ -29,4 +33,4 @@ type UtilsOptions = {
29
33
  log?: LogInstance;
30
34
  };
31
35
 
32
- export { InternalLogOptions, KeyValues, LogInstance, LogLevel, LogOptions, UniqueKeyValues, UtilsOptions };
36
+ export { InternalLogOptions, KeyValues, LogInstance, LogLevel, LogOptions, Metadata, UniqueKeyValues, UtilsOptions };
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "larvitutils",
3
- "version": "5.0.16",
3
+ "version": "5.1.2",
4
4
  "description": "Misc utils",
5
5
  "main": "./dist/index.js",
6
6
  "files": [
7
7
  "/dist"
8
8
  ],
9
9
  "devDependencies": {
10
- "@types/node": "16.11.45",
10
+ "@types/node": "18.0.6",
11
11
  "@types/tape": "4.13.2",
12
- "@typescript-eslint/eslint-plugin": "5.30.6",
13
- "@typescript-eslint/parser": "5.30.6",
14
- "eslint": "8.20.0",
12
+ "@typescript-eslint/eslint-plugin": "5.32.0",
13
+ "@typescript-eslint/parser": "5.32.0",
14
+ "eslint": "8.21.0",
15
15
  "nyc": "15.1.0",
16
16
  "tape": "5.5.3",
17
17
  "ts-node": "10.9.1",