@athenna/logger 5.13.0 → 5.15.0
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
package/src/logger/Logger.d.ts
CHANGED
|
@@ -16,6 +16,11 @@ export declare class Logger extends Macroable {
|
|
|
16
16
|
* Runtime configurations to be used inside the Drivers and Formatters.
|
|
17
17
|
*/
|
|
18
18
|
private runtimeConfigs;
|
|
19
|
+
/**
|
|
20
|
+
* Store the current logger strategy so config() and create()
|
|
21
|
+
* can clone the logger preserving its behavior.
|
|
22
|
+
*/
|
|
23
|
+
private selection;
|
|
19
24
|
constructor();
|
|
20
25
|
/**
|
|
21
26
|
* Create a new standalone logger instance. Very
|
|
@@ -28,6 +33,11 @@ export declare class Logger extends Macroable {
|
|
|
28
33
|
* formatters.
|
|
29
34
|
*/
|
|
30
35
|
config(runtimeConfigs: any): Logger;
|
|
36
|
+
/**
|
|
37
|
+
* Create a new logger instance inheriting the current
|
|
38
|
+
* configuration and adding default message content.
|
|
39
|
+
*/
|
|
40
|
+
create(defaults?: any): Logger;
|
|
31
41
|
/**
|
|
32
42
|
* Change the log channel.
|
|
33
43
|
*/
|
|
@@ -81,4 +91,8 @@ export declare class Logger extends Macroable {
|
|
|
81
91
|
* Call drivers to transport the log.
|
|
82
92
|
*/
|
|
83
93
|
private log;
|
|
94
|
+
/**
|
|
95
|
+
* Rebuild drivers using the current logger selection.
|
|
96
|
+
*/
|
|
97
|
+
private applySelection;
|
|
84
98
|
}
|
package/src/logger/Logger.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { Config } from '@athenna/config';
|
|
10
10
|
import { Driver } from '#src/drivers/Driver';
|
|
11
|
-
import { Color, Macroable } from '@athenna/common';
|
|
11
|
+
import { Color, Json, Macroable } from '@athenna/common';
|
|
12
12
|
import { DriverFactory } from '#src/factories/DriverFactory';
|
|
13
13
|
import { VANILLA_CHANNELS } from '#src/constants/VanillaChannels';
|
|
14
14
|
export class Logger extends Macroable {
|
|
@@ -22,6 +22,14 @@ export class Logger extends Macroable {
|
|
|
22
22
|
* Runtime configurations to be used inside the Drivers and Formatters.
|
|
23
23
|
*/
|
|
24
24
|
this.runtimeConfigs = {};
|
|
25
|
+
/**
|
|
26
|
+
* Store the current logger strategy so config() and create()
|
|
27
|
+
* can clone the logger preserving its behavior.
|
|
28
|
+
*/
|
|
29
|
+
this.selection = {
|
|
30
|
+
method: 'vanilla',
|
|
31
|
+
values: []
|
|
32
|
+
};
|
|
25
33
|
this.channelOrVanilla(Config.get('logging.default'));
|
|
26
34
|
}
|
|
27
35
|
/**
|
|
@@ -39,16 +47,38 @@ export class Logger extends Macroable {
|
|
|
39
47
|
* formatters.
|
|
40
48
|
*/
|
|
41
49
|
config(runtimeConfigs) {
|
|
42
|
-
this.runtimeConfigs = runtimeConfigs;
|
|
43
|
-
return this;
|
|
50
|
+
this.runtimeConfigs = Json.copy(runtimeConfigs || {});
|
|
51
|
+
return this.applySelection();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Create a new logger instance inheriting the current
|
|
55
|
+
* configuration and adding default message content.
|
|
56
|
+
*/
|
|
57
|
+
create(defaults = {}) {
|
|
58
|
+
const logger = new Logger();
|
|
59
|
+
const runtimeConfigs = Json.copy(this.runtimeConfigs);
|
|
60
|
+
if (!runtimeConfigs.formatterConfig) {
|
|
61
|
+
runtimeConfigs.formatterConfig = {};
|
|
62
|
+
}
|
|
63
|
+
runtimeConfigs.formatterConfig.defaults = Json.copy(defaults);
|
|
64
|
+
logger.selection = {
|
|
65
|
+
method: this.selection.method,
|
|
66
|
+
values: Json.copy(this.selection.values)
|
|
67
|
+
};
|
|
68
|
+
return logger.config(runtimeConfigs);
|
|
44
69
|
}
|
|
45
70
|
/**
|
|
46
71
|
* Change the log channel.
|
|
47
72
|
*/
|
|
48
73
|
channel(...channels) {
|
|
49
74
|
this.drivers = [];
|
|
75
|
+
this.selection = {
|
|
76
|
+
method: 'channel',
|
|
77
|
+
values: [...channels]
|
|
78
|
+
};
|
|
50
79
|
channels.forEach(channel => {
|
|
51
|
-
|
|
80
|
+
const driver = DriverFactory.fabricate(channel, this.runtimeConfigs);
|
|
81
|
+
this.drivers.push(driver);
|
|
52
82
|
});
|
|
53
83
|
return this;
|
|
54
84
|
}
|
|
@@ -59,12 +89,17 @@ export class Logger extends Macroable {
|
|
|
59
89
|
*/
|
|
60
90
|
vanilla(...configs) {
|
|
61
91
|
this.drivers = [];
|
|
92
|
+
this.selection = {
|
|
93
|
+
method: 'vanilla',
|
|
94
|
+
values: Json.copy(configs)
|
|
95
|
+
};
|
|
62
96
|
if (!configs.length) {
|
|
63
|
-
this.drivers.push(DriverFactory.fabricateVanilla());
|
|
97
|
+
this.drivers.push(DriverFactory.fabricateVanilla(this.runtimeConfigs));
|
|
64
98
|
return this;
|
|
65
99
|
}
|
|
66
100
|
configs.forEach(config => {
|
|
67
|
-
|
|
101
|
+
const driver = DriverFactory.fabricateVanilla({ ...config, ...this.runtimeConfigs });
|
|
102
|
+
this.drivers.push(driver);
|
|
68
103
|
});
|
|
69
104
|
return this;
|
|
70
105
|
}
|
|
@@ -139,4 +174,10 @@ export class Logger extends Macroable {
|
|
|
139
174
|
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
140
175
|
return Promise.all(promises);
|
|
141
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* Rebuild drivers using the current logger selection.
|
|
179
|
+
*/
|
|
180
|
+
applySelection() {
|
|
181
|
+
return this[this.selection.method](...Json.copy(this.selection.values));
|
|
182
|
+
}
|
|
142
183
|
}
|