@athenna/logger 1.0.7 → 1.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/logger",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -155,6 +155,7 @@
155
155
  "dependencies": {
156
156
  "@athenna/ioc": "1.0.9",
157
157
  "@secjs/utils": "1.8.0",
158
+ "chalk": "4.1.1",
158
159
  "reflect-metadata": "0.1.13",
159
160
  "tscpaths": "0.0.9"
160
161
  }
package/src/Logger.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare class Logger {
9
9
  static get formatters(): string[];
10
10
  static buildDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): void;
11
11
  static buildFormatter(name: string, formatter: new () => FormatterContract): void;
12
+ private static applyLogEngine;
12
13
  channel(channel: string, runtimeConfig?: any): Logger;
13
14
  log(message: any, options?: {}): void | Promise<void>;
14
15
  info(message: any, options?: {}): void | Promise<void>;
package/src/Logger.js CHANGED
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.Logger = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
4
8
  const Color_1 = require("./Utils/Color");
5
9
  const utils_1 = require("@secjs/utils");
6
10
  const DriverFactory_1 = require("./Factories/DriverFactory");
@@ -24,6 +28,28 @@ class Logger {
24
28
  static buildFormatter(name, formatter) {
25
29
  FormatterFactory_1.FormatterFactory.createFormatter(name, formatter);
26
30
  }
31
+ static applyLogEngine(content) {
32
+ if (utils_1.Is.String(content)) {
33
+ const matches = content.match(/\({(.*?)} (.*?)\)/);
34
+ if (matches) {
35
+ const chalkMethodsString = matches[1].replace(/\s/g, '');
36
+ const chalkMethodsArray = chalkMethodsString.split(',');
37
+ const message = matches[2];
38
+ let chalk = chalk_1.default;
39
+ chalkMethodsArray.forEach(chalkMethod => {
40
+ if (!chalk[chalkMethod])
41
+ return;
42
+ chalk = chalk[chalkMethod];
43
+ });
44
+ content = content
45
+ .replace(`({${matches[1]}} `, '')
46
+ .replace(`({${matches[1]}}`, '')
47
+ .replace(`${matches[2]})`, chalk(message));
48
+ }
49
+ return content;
50
+ }
51
+ return content;
52
+ }
27
53
  channel(channel, runtimeConfig) {
28
54
  if (runtimeConfig)
29
55
  this.runtimeConfig = runtimeConfig;
@@ -34,6 +60,7 @@ class Logger {
34
60
  options = this.createOptions(options, {
35
61
  streamType: 'stdout',
36
62
  });
63
+ message = Logger.applyLogEngine(message);
37
64
  return this.driver.transport(message, options);
38
65
  }
39
66
  info(message, options = {}) {
@@ -44,6 +71,7 @@ class Logger {
44
71
  color: Color_1.Color.cyan,
45
72
  },
46
73
  });
74
+ message = Logger.applyLogEngine(message);
47
75
  return this.driver.transport(message, options);
48
76
  }
49
77
  warn(message, options = {}) {
@@ -54,6 +82,7 @@ class Logger {
54
82
  color: Color_1.Color.orange,
55
83
  },
56
84
  });
85
+ message = Logger.applyLogEngine(message);
57
86
  return this.driver.transport(message, options);
58
87
  }
59
88
  error(message, options = {}) {
@@ -64,6 +93,7 @@ class Logger {
64
93
  color: Color_1.Color.red,
65
94
  },
66
95
  });
96
+ message = Logger.applyLogEngine(message);
67
97
  return this.driver.transport(message, options);
68
98
  }
69
99
  debug(message, options = {}) {
@@ -74,6 +104,7 @@ class Logger {
74
104
  color: Color_1.Color.purple,
75
105
  },
76
106
  });
107
+ message = Logger.applyLogEngine(message);
77
108
  return this.driver.transport(message, options);
78
109
  }
79
110
  success(message, options = {}) {
@@ -84,6 +115,7 @@ class Logger {
84
115
  color: Color_1.Color.green,
85
116
  },
86
117
  });
118
+ message = Logger.applyLogEngine(message);
87
119
  return this.driver.transport(message, options);
88
120
  }
89
121
  createOptions(options, defaultValues) {
@@ -6,11 +6,19 @@
6
6
  * For the full copyright and license information, please view the LICENSE
7
7
  * file that was distributed with this source code.
8
8
  */
9
- import { Chalk } from 'chalk';
9
+ import chalk, { Chalk } from 'chalk';
10
10
  declare type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE';
11
11
  export declare class Color {
12
- static chalk: Chalk & {
13
- supportsColor: import("chalk").ColorSupport;
12
+ static chalk: chalk.Chalk & chalk.ChalkFunction & {
13
+ supportsColor: false | chalk.ColorSupport;
14
+ Level: chalk.Level;
15
+ Color: ("black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright") | ("bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright");
16
+ ForegroundColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
17
+ BackgroundColor: "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright";
18
+ Modifiers: "reset" | "bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "visible";
19
+ stderr: chalk.Chalk & {
20
+ supportsColor: false | chalk.ColorSupport;
21
+ };
14
22
  };
15
23
  static get bold(): Chalk;
16
24
  static get purple(): Chalk;