@4players/odin-common 2.4.9 → 2.4.10

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.
@@ -1,36 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Logger = exports.log = exports.OdinError = void 0;
4
+ function createLogHeader(options) {
5
+ let header = '';
6
+ const date = new Date();
7
+ const hours = date.getHours();
8
+ const minutes = date.getMinutes();
9
+ const seconds = date.getSeconds();
10
+ header = `ODIN at ${hours}:${minutes}:${seconds} in ${options === null || options === void 0 ? void 0 : options.project}\n`;
11
+ header += 'Tags: ';
12
+ for (const tag of options.tags) {
13
+ header += `${tag} `;
14
+ }
15
+ header += '\n';
16
+ return header;
17
+ }
4
18
  class OdinError extends Error {
5
19
  constructor(message = '', options) {
6
20
  super(message);
7
21
  this.message = message;
8
22
  this.name = 'OdinError';
9
- const date = new Date();
10
- const hours = date.getHours();
11
- const minutes = date.getMinutes();
12
- const seconds = date.getSeconds();
13
- if (options === null || options === void 0 ? void 0 : options.project) {
14
- this.message = `ODIN ${options === null || options === void 0 ? void 0 : options.project} | ${options === null || options === void 0 ? void 0 : options.kind}`;
23
+ if (options) {
24
+ this.message += createLogHeader(options);
15
25
  }
16
- this.message += ` at ${options === null || options === void 0 ? void 0 : options.project} ${hours}:${minutes}:${seconds}\n`;
17
26
  this.message += `${message}\n`;
18
27
  }
19
28
  }
20
29
  exports.OdinError = OdinError;
21
- function log(options, filters = { filters: [] }, args) {
22
- if (filters.filters.includes(options.kind)) {
23
- let logMessage = '';
24
- const date = new Date();
25
- const hours = date.getHours();
26
- const minutes = date.getMinutes();
27
- const seconds = date.getSeconds();
28
- if (options === null || options === void 0 ? void 0 : options.project) {
29
- logMessage = `ODIN at ${hours}:${minutes}:${seconds} in ${options === null || options === void 0 ? void 0 : options.project}(${options === null || options === void 0 ? void 0 : options.kind})\n`;
30
- }
31
- if (options.type) {
32
- console[options.type](logMessage, ...args);
33
- }
30
+ function log(options, args) {
31
+ let message = '';
32
+ message += createLogHeader(options);
33
+ if (options.type) {
34
+ console[options.type](message, ...args);
34
35
  }
35
36
  }
36
37
  exports.log = log;
@@ -39,20 +40,38 @@ class Logger {
39
40
  this.project = project;
40
41
  this.filters = filters;
41
42
  }
42
- log(kind, ...args) {
43
- log({ project: this.project, kind, type: 'log' }, this.filters, args);
43
+ log(tags, ...args) {
44
+ if (this._filterByTag(tags)) {
45
+ log({ project: this.project, tags, type: 'log' }, args);
46
+ }
44
47
  }
45
- info(kind, ...args) {
46
- log({ project: this.project, kind, type: 'info' }, this.filters, args);
48
+ info(tags, ...args) {
49
+ if (this._filterByTag(tags)) {
50
+ log({ project: this.project, tags, type: 'info' }, args);
51
+ }
47
52
  }
48
- error(kind, ...args) {
49
- log({ project: this.project, kind, type: 'error' }, this.filters, args);
53
+ error(tags, ...args) {
54
+ if (this._filterByTag(tags)) {
55
+ log({ project: this.project, tags, type: 'error' }, args);
56
+ }
50
57
  }
51
- warn(kind, ...args) {
52
- log({ project: this.project, kind, type: 'warn' }, this.filters, args);
58
+ warn(tags, ...args) {
59
+ if (this._filterByTag(tags)) {
60
+ log({ project: this.project, tags, type: 'warn' }, args);
61
+ }
53
62
  }
54
- debug(kind, ...args) {
55
- log({ project: this.project, kind, type: 'debug' }, this.filters, args);
63
+ debug(tags, ...args) {
64
+ if (this._filterByTag(tags)) {
65
+ log({ project: this.project, tags, type: 'debug' }, args);
66
+ }
67
+ }
68
+ _filterByTag(tags) {
69
+ for (const tag of tags) {
70
+ if (this.filters.tags.includes(tag)) {
71
+ return true;
72
+ }
73
+ }
74
+ return false;
56
75
  }
57
76
  }
58
77
  exports.Logger = Logger;
@@ -1,32 +1,33 @@
1
+ function createLogHeader(options) {
2
+ let header = '';
3
+ const date = new Date();
4
+ const hours = date.getHours();
5
+ const minutes = date.getMinutes();
6
+ const seconds = date.getSeconds();
7
+ header = `ODIN at ${hours}:${minutes}:${seconds} in ${options === null || options === void 0 ? void 0 : options.project}\n`;
8
+ header += 'Tags: ';
9
+ for (const tag of options.tags) {
10
+ header += `${tag} `;
11
+ }
12
+ header += '\n';
13
+ return header;
14
+ }
1
15
  export class OdinError extends Error {
2
16
  constructor(message = '', options) {
3
17
  super(message);
4
18
  this.message = message;
5
19
  this.name = 'OdinError';
6
- const date = new Date();
7
- const hours = date.getHours();
8
- const minutes = date.getMinutes();
9
- const seconds = date.getSeconds();
10
- if (options === null || options === void 0 ? void 0 : options.project) {
11
- this.message = `ODIN ${options === null || options === void 0 ? void 0 : options.project} | ${options === null || options === void 0 ? void 0 : options.kind}`;
20
+ if (options) {
21
+ this.message += createLogHeader(options);
12
22
  }
13
- this.message += ` at ${options === null || options === void 0 ? void 0 : options.project} ${hours}:${minutes}:${seconds}\n`;
14
23
  this.message += `${message}\n`;
15
24
  }
16
25
  }
17
- export function log(options, filters = { filters: [] }, args) {
18
- if (filters.filters.includes(options.kind)) {
19
- let logMessage = '';
20
- const date = new Date();
21
- const hours = date.getHours();
22
- const minutes = date.getMinutes();
23
- const seconds = date.getSeconds();
24
- if (options === null || options === void 0 ? void 0 : options.project) {
25
- logMessage = `ODIN at ${hours}:${minutes}:${seconds} in ${options === null || options === void 0 ? void 0 : options.project}(${options === null || options === void 0 ? void 0 : options.kind})\n`;
26
- }
27
- if (options.type) {
28
- console[options.type](logMessage, ...args);
29
- }
26
+ export function log(options, args) {
27
+ let message = '';
28
+ message += createLogHeader(options);
29
+ if (options.type) {
30
+ console[options.type](message, ...args);
30
31
  }
31
32
  }
32
33
  export class Logger {
@@ -34,19 +35,37 @@ export class Logger {
34
35
  this.project = project;
35
36
  this.filters = filters;
36
37
  }
37
- log(kind, ...args) {
38
- log({ project: this.project, kind, type: 'log' }, this.filters, args);
38
+ log(tags, ...args) {
39
+ if (this._filterByTag(tags)) {
40
+ log({ project: this.project, tags, type: 'log' }, args);
41
+ }
39
42
  }
40
- info(kind, ...args) {
41
- log({ project: this.project, kind, type: 'info' }, this.filters, args);
43
+ info(tags, ...args) {
44
+ if (this._filterByTag(tags)) {
45
+ log({ project: this.project, tags, type: 'info' }, args);
46
+ }
42
47
  }
43
- error(kind, ...args) {
44
- log({ project: this.project, kind, type: 'error' }, this.filters, args);
48
+ error(tags, ...args) {
49
+ if (this._filterByTag(tags)) {
50
+ log({ project: this.project, tags, type: 'error' }, args);
51
+ }
45
52
  }
46
- warn(kind, ...args) {
47
- log({ project: this.project, kind, type: 'warn' }, this.filters, args);
53
+ warn(tags, ...args) {
54
+ if (this._filterByTag(tags)) {
55
+ log({ project: this.project, tags, type: 'warn' }, args);
56
+ }
48
57
  }
49
- debug(kind, ...args) {
50
- log({ project: this.project, kind, type: 'debug' }, this.filters, args);
58
+ debug(tags, ...args) {
59
+ if (this._filterByTag(tags)) {
60
+ log({ project: this.project, tags, type: 'debug' }, args);
61
+ }
62
+ }
63
+ _filterByTag(tags) {
64
+ for (const tag of tags) {
65
+ if (this.filters.tags.includes(tag)) {
66
+ return true;
67
+ }
68
+ }
69
+ return false;
51
70
  }
52
71
  }
@@ -1,25 +1,26 @@
1
1
  export type LogType = 'debug' | 'info' | 'warn' | 'error' | 'log';
2
2
  export type LogOptions = {
3
- kind: string;
3
+ tags: string[];
4
4
  project: string;
5
5
  type?: LogType;
6
6
  };
7
7
  export type LogFilters = {
8
- filters: string[];
8
+ tags: string[];
9
9
  };
10
10
  export declare class OdinError extends Error {
11
11
  message: string;
12
12
  readonly name = "OdinError";
13
13
  constructor(message?: string, options?: LogOptions);
14
14
  }
15
- export declare function log(options: LogOptions, filters: LogFilters | undefined, args: any[]): void;
15
+ export declare function log(options: LogOptions, args: any[]): void;
16
16
  export declare class Logger {
17
17
  readonly project: string;
18
18
  filters: LogFilters;
19
19
  constructor(project: string, filters: LogFilters);
20
- log(kind: string, ...args: any[]): void;
21
- info(kind: string, ...args: any[]): void;
22
- error(kind: string, ...args: any[]): void;
23
- warn(kind: string, ...args: any[]): void;
24
- debug(kind: string, ...args: any[]): void;
20
+ log(tags: string[], ...args: any[]): void;
21
+ info(tags: string[], ...args: any[]): void;
22
+ error(tags: string[], ...args: any[]): void;
23
+ warn(tags: string[], ...args: any[]): void;
24
+ debug(tags: string[], ...args: any[]): void;
25
+ private _filterByTag;
25
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4players/odin-common",
3
- "version": "2.4.9",
3
+ "version": "2.4.10",
4
4
  "description": "A collection of commonly used type definitions and utility functions across ODIN web projects",
5
5
  "author": "Josho Bleicker <josho.bleicker@4players.io> (https://www.4players.io)",
6
6
  "homepage": "https://www.4players.io",