@athenna/logger 1.1.6 → 1.1.7

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.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -153,7 +153,7 @@
153
153
  }
154
154
  },
155
155
  "dependencies": {
156
- "@athenna/ioc": "1.1.2",
156
+ "@athenna/ioc": "1.1.3",
157
157
  "@secjs/utils": "1.8.3",
158
158
  "chalk": "4.1.1",
159
159
  "reflect-metadata": "0.1.13",
@@ -9,5 +9,5 @@
9
9
  */
10
10
  Object.defineProperty(exports, "__esModule", { value: true });
11
11
  exports.Log = void 0;
12
- const Handler_1 = require("../Utils/Handler");
13
- exports.Log = new Proxy({}, new Handler_1.Handler('Athenna/Core/Logger'));
12
+ const ioc_1 = require("@athenna/ioc");
13
+ exports.Log = ioc_1.Facade.createFor('Athenna/Core/Logger');
package/src/Logger.d.ts CHANGED
@@ -1,21 +1,110 @@
1
1
  import { DriverContract } from './Contracts/DriverContract';
2
2
  import { FormatterContract } from './Contracts/FormatterContract';
3
3
  export declare class Logger {
4
+ /**
5
+ * Runtime configurations to be used inside the Drivers and Formatters.
6
+ * @private
7
+ */
4
8
  private runtimeConfig;
5
- private channelName;
9
+ /**
10
+ * The driver responsible for transporting the logs.
11
+ * @private
12
+ */
6
13
  private driver;
7
- constructor(runtimeConfig?: any);
14
+ /**
15
+ * The log channel selected with driver and formatter configurations.
16
+ * @private
17
+ */
18
+ private channelName;
19
+ /**
20
+ * Creates a new instance of Logger.
21
+ *
22
+ * @return {Logger}
23
+ */
24
+ constructor();
25
+ /**
26
+ * Return all drivers available.
27
+ */
8
28
  static get drivers(): string[];
29
+ /**
30
+ * Return all formatters available.
31
+ */
9
32
  static get formatters(): string[];
33
+ /**
34
+ * Builds a new driver to use within Logger class.
35
+ *
36
+ * @param name
37
+ * @param driver
38
+ */
10
39
  static buildDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): void;
40
+ /**
41
+ * Builds a new formatter to use within Logger class.
42
+ *
43
+ * @param name
44
+ * @param formatter
45
+ */
11
46
  static buildFormatter(name: string, formatter: new () => FormatterContract): void;
47
+ /**
48
+ * Applies the log engine to execute chalk methods of string.
49
+ *
50
+ * @param content
51
+ * @private
52
+ */
12
53
  private static applyLogEngine;
54
+ /**
55
+ * Change the log channel.
56
+ *
57
+ * @param channel
58
+ * @param runtimeConfig
59
+ */
13
60
  channel(channel: string, runtimeConfig?: any): Logger;
61
+ /**
62
+ * Creates a log of type log in channel.
63
+ * @param message
64
+ * @param options
65
+ */
14
66
  log(message: any, options?: {}): void | Promise<void>;
67
+ /**
68
+ * Creates a log of type info in channel.
69
+ *
70
+ * @param message
71
+ * @param options
72
+ */
15
73
  info(message: any, options?: {}): void | Promise<void>;
74
+ /**
75
+ * Creates a log of type warn in channel.
76
+ *
77
+ * @param message
78
+ * @param options
79
+ */
16
80
  warn(message: any, options?: {}): void | Promise<void>;
81
+ /**
82
+ * Creates a log of type error in channel.
83
+ *
84
+ * @param message
85
+ * @param options
86
+ */
17
87
  error(message: any, options?: {}): void | Promise<void>;
88
+ /**
89
+ * Creates a log of type debug in channel.
90
+ *
91
+ * @param message
92
+ * @param options
93
+ */
18
94
  debug(message: any, options?: {}): void | Promise<void>;
95
+ /**
96
+ * Creates a log of type success in channel.
97
+ *
98
+ * @param message
99
+ * @param options
100
+ */
19
101
  success(message: any, options?: {}): void | Promise<void>;
102
+ /**
103
+ * Create options concatenating client options with default options.
104
+ *
105
+ * @param options
106
+ * @param defaultValues
107
+ * @private
108
+ */
20
109
  private createOptions;
21
110
  }
package/src/Logger.js CHANGED
@@ -10,23 +10,60 @@ const Color_1 = require("./Utils/Color");
10
10
  const DriverFactory_1 = require("./Factories/DriverFactory");
11
11
  const FormatterFactory_1 = require("./Factories/FormatterFactory");
12
12
  class Logger {
13
- constructor(runtimeConfig = {}) {
14
- this.runtimeConfig = runtimeConfig;
13
+ /**
14
+ * Creates a new instance of Logger.
15
+ *
16
+ * @return {Logger}
17
+ */
18
+ constructor() {
19
+ /**
20
+ * Runtime configurations to be used inside the Drivers and Formatters.
21
+ * @private
22
+ */
23
+ this.runtimeConfig = {};
24
+ /**
25
+ * The log channel selected with driver and formatter configurations.
26
+ * @private
27
+ */
15
28
  this.channelName = 'default';
16
29
  this.driver = DriverFactory_1.DriverFactory.fabricate(this.channelName, this.runtimeConfig);
17
30
  }
31
+ /**
32
+ * Return all drivers available.
33
+ */
18
34
  static get drivers() {
19
35
  return DriverFactory_1.DriverFactory.availableDrivers();
20
36
  }
37
+ /**
38
+ * Return all formatters available.
39
+ */
21
40
  static get formatters() {
22
41
  return FormatterFactory_1.FormatterFactory.availableFormatters();
23
42
  }
43
+ /**
44
+ * Builds a new driver to use within Logger class.
45
+ *
46
+ * @param name
47
+ * @param driver
48
+ */
24
49
  static buildDriver(name, driver) {
25
50
  DriverFactory_1.DriverFactory.createDriver(name, driver);
26
51
  }
52
+ /**
53
+ * Builds a new formatter to use within Logger class.
54
+ *
55
+ * @param name
56
+ * @param formatter
57
+ */
27
58
  static buildFormatter(name, formatter) {
28
59
  FormatterFactory_1.FormatterFactory.createFormatter(name, formatter);
29
60
  }
61
+ /**
62
+ * Applies the log engine to execute chalk methods of string.
63
+ *
64
+ * @param content
65
+ * @private
66
+ */
30
67
  static applyLogEngine(content) {
31
68
  if (utils_1.Is.String(content)) {
32
69
  const matches = content.match(/\({(.*?)} (.*?)\)/);
@@ -49,22 +86,37 @@ class Logger {
49
86
  }
50
87
  return content;
51
88
  }
89
+ /**
90
+ * Change the log channel.
91
+ *
92
+ * @param channel
93
+ * @param runtimeConfig
94
+ */
52
95
  channel(channel, runtimeConfig) {
53
96
  if (runtimeConfig)
54
97
  this.runtimeConfig = runtimeConfig;
55
98
  this.driver = DriverFactory_1.DriverFactory.fabricate(channel, this.runtimeConfig);
99
+ this.channelName = channel;
56
100
  return this;
57
101
  }
102
+ /**
103
+ * Creates a log of type log in channel.
104
+ * @param message
105
+ * @param options
106
+ */
58
107
  log(message, options = {}) {
59
- options = this.createOptions(options, {
60
- streamType: 'stdout',
61
- });
108
+ options = this.createOptions(options, {});
62
109
  message = Logger.applyLogEngine(message);
63
110
  return this.driver.transport(message, options);
64
111
  }
112
+ /**
113
+ * Creates a log of type info in channel.
114
+ *
115
+ * @param message
116
+ * @param options
117
+ */
65
118
  info(message, options = {}) {
66
119
  options = this.createOptions(options, {
67
- streamType: 'stdout',
68
120
  formatterConfig: {
69
121
  level: 'INFO',
70
122
  chalk: Color_1.Color.cyan,
@@ -73,6 +125,12 @@ class Logger {
73
125
  message = Logger.applyLogEngine(message);
74
126
  return this.driver.transport(message, options);
75
127
  }
128
+ /**
129
+ * Creates a log of type warn in channel.
130
+ *
131
+ * @param message
132
+ * @param options
133
+ */
76
134
  warn(message, options = {}) {
77
135
  options = this.createOptions(options, {
78
136
  streamType: 'stdout',
@@ -84,6 +142,12 @@ class Logger {
84
142
  message = Logger.applyLogEngine(message);
85
143
  return this.driver.transport(message, options);
86
144
  }
145
+ /**
146
+ * Creates a log of type error in channel.
147
+ *
148
+ * @param message
149
+ * @param options
150
+ */
87
151
  error(message, options = {}) {
88
152
  options = this.createOptions(options, {
89
153
  streamType: 'stdout',
@@ -95,6 +159,12 @@ class Logger {
95
159
  message = Logger.applyLogEngine(message);
96
160
  return this.driver.transport(message, options);
97
161
  }
162
+ /**
163
+ * Creates a log of type debug in channel.
164
+ *
165
+ * @param message
166
+ * @param options
167
+ */
98
168
  debug(message, options = {}) {
99
169
  options = this.createOptions(options, {
100
170
  streamType: 'stdout',
@@ -106,6 +176,12 @@ class Logger {
106
176
  message = Logger.applyLogEngine(message);
107
177
  return this.driver.transport(message, options);
108
178
  }
179
+ /**
180
+ * Creates a log of type success in channel.
181
+ *
182
+ * @param message
183
+ * @param options
184
+ */
109
185
  success(message, options = {}) {
110
186
  options = this.createOptions(options, {
111
187
  streamType: 'stdout',
@@ -117,6 +193,13 @@ class Logger {
117
193
  message = Logger.applyLogEngine(message);
118
194
  return this.driver.transport(message, options);
119
195
  }
196
+ /**
197
+ * Create options concatenating client options with default options.
198
+ *
199
+ * @param options
200
+ * @param defaultValues
201
+ * @private
202
+ */
120
203
  createOptions(options, defaultValues) {
121
204
  let formatterConfig = Object.assign({}, {
122
205
  ...defaultValues.formatterConfig,
@@ -18,7 +18,7 @@ class LoggerProvider extends ioc_1.ServiceProvider {
18
18
  * @return void
19
19
  */
20
20
  register() {
21
- this.container.instance('Athenna/Core/Logger', new Logger_1.Logger());
21
+ this.container.bind('Athenna/Core/Logger', Logger_1.Logger);
22
22
  }
23
23
  }
24
24
  exports.LoggerProvider = LoggerProvider;
@@ -1,13 +0,0 @@
1
- /**
2
- * @athenna/logger
3
- *
4
- * (c) João Lenon <lenon@athenna.io>
5
- *
6
- * For the full copyright and license information, please view the LICENSE
7
- * file that was distributed with this source code.
8
- */
9
- export declare class Handler {
10
- private readonly alias;
11
- constructor(alias: any);
12
- get(_object: any, key: string): any;
13
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /**
3
- * @athenna/logger
4
- *
5
- * (c) João Lenon <lenon@athenna.io>
6
- *
7
- * For the full copyright and license information, please view the LICENSE
8
- * file that was distributed with this source code.
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.Handler = void 0;
12
- class Handler {
13
- constructor(alias) {
14
- this.alias = alias;
15
- }
16
- get(_object, key) {
17
- const provider = ioc.use(this.alias);
18
- if (!provider) {
19
- return () => { };
20
- }
21
- return provider[key];
22
- }
23
- }
24
- exports.Handler = Handler;