@athenna/logger 5.14.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 +1 -1
- package/src/logger/Logger.d.ts +3 -9
- package/src/logger/Logger.js +23 -36
package/package.json
CHANGED
package/src/logger/Logger.d.ts
CHANGED
|
@@ -17,12 +17,7 @@ export declare class Logger extends Macroable {
|
|
|
17
17
|
*/
|
|
18
18
|
private runtimeConfigs;
|
|
19
19
|
/**
|
|
20
|
-
*
|
|
21
|
-
* in every structured log emitted by this instance.
|
|
22
|
-
*/
|
|
23
|
-
private messageDefaults;
|
|
24
|
-
/**
|
|
25
|
-
* Store the current logger strategy so create()
|
|
20
|
+
* Store the current logger strategy so config() and create()
|
|
26
21
|
* can clone the logger preserving its behavior.
|
|
27
22
|
*/
|
|
28
23
|
private selection;
|
|
@@ -97,8 +92,7 @@ export declare class Logger extends Macroable {
|
|
|
97
92
|
*/
|
|
98
93
|
private log;
|
|
99
94
|
/**
|
|
100
|
-
*
|
|
101
|
-
* structured formatters can enrich the output.
|
|
95
|
+
* Rebuild drivers using the current logger selection.
|
|
102
96
|
*/
|
|
103
|
-
private
|
|
97
|
+
private applySelection;
|
|
104
98
|
}
|
package/src/logger/Logger.js
CHANGED
|
@@ -23,16 +23,11 @@ export class Logger extends Macroable {
|
|
|
23
23
|
*/
|
|
24
24
|
this.runtimeConfigs = {};
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
27
|
-
* in every structured log emitted by this instance.
|
|
28
|
-
*/
|
|
29
|
-
this.messageDefaults = {};
|
|
30
|
-
/**
|
|
31
|
-
* Store the current logger strategy so create()
|
|
26
|
+
* Store the current logger strategy so config() and create()
|
|
32
27
|
* can clone the logger preserving its behavior.
|
|
33
28
|
*/
|
|
34
29
|
this.selection = {
|
|
35
|
-
|
|
30
|
+
method: 'vanilla',
|
|
36
31
|
values: []
|
|
37
32
|
};
|
|
38
33
|
this.channelOrVanilla(Config.get('logging.default'));
|
|
@@ -52,8 +47,8 @@ export class Logger extends Macroable {
|
|
|
52
47
|
* formatters.
|
|
53
48
|
*/
|
|
54
49
|
config(runtimeConfigs) {
|
|
55
|
-
this.runtimeConfigs = runtimeConfigs;
|
|
56
|
-
return this;
|
|
50
|
+
this.runtimeConfigs = Json.copy(runtimeConfigs || {});
|
|
51
|
+
return this.applySelection();
|
|
57
52
|
}
|
|
58
53
|
/**
|
|
59
54
|
* Create a new logger instance inheriting the current
|
|
@@ -61,12 +56,16 @@ export class Logger extends Macroable {
|
|
|
61
56
|
*/
|
|
62
57
|
create(defaults = {}) {
|
|
63
58
|
const logger = new Logger();
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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)
|
|
68
67
|
};
|
|
69
|
-
return logger
|
|
68
|
+
return logger.config(runtimeConfigs);
|
|
70
69
|
}
|
|
71
70
|
/**
|
|
72
71
|
* Change the log channel.
|
|
@@ -74,12 +73,12 @@ export class Logger extends Macroable {
|
|
|
74
73
|
channel(...channels) {
|
|
75
74
|
this.drivers = [];
|
|
76
75
|
this.selection = {
|
|
77
|
-
|
|
76
|
+
method: 'channel',
|
|
78
77
|
values: [...channels]
|
|
79
78
|
};
|
|
80
|
-
const runtimeConfigs = this.withDefaultFormatterConfig(this.runtimeConfigs);
|
|
81
79
|
channels.forEach(channel => {
|
|
82
|
-
|
|
80
|
+
const driver = DriverFactory.fabricate(channel, this.runtimeConfigs);
|
|
81
|
+
this.drivers.push(driver);
|
|
83
82
|
});
|
|
84
83
|
return this;
|
|
85
84
|
}
|
|
@@ -91,15 +90,16 @@ export class Logger extends Macroable {
|
|
|
91
90
|
vanilla(...configs) {
|
|
92
91
|
this.drivers = [];
|
|
93
92
|
this.selection = {
|
|
94
|
-
|
|
93
|
+
method: 'vanilla',
|
|
95
94
|
values: Json.copy(configs)
|
|
96
95
|
};
|
|
97
96
|
if (!configs.length) {
|
|
98
|
-
this.drivers.push(DriverFactory.fabricateVanilla(this.
|
|
97
|
+
this.drivers.push(DriverFactory.fabricateVanilla(this.runtimeConfigs));
|
|
99
98
|
return this;
|
|
100
99
|
}
|
|
101
100
|
configs.forEach(config => {
|
|
102
|
-
|
|
101
|
+
const driver = DriverFactory.fabricateVanilla({ ...config, ...this.runtimeConfigs });
|
|
102
|
+
this.drivers.push(driver);
|
|
103
103
|
});
|
|
104
104
|
return this;
|
|
105
105
|
}
|
|
@@ -175,22 +175,9 @@ export class Logger extends Macroable {
|
|
|
175
175
|
return Promise.all(promises);
|
|
176
176
|
}
|
|
177
177
|
/**
|
|
178
|
-
*
|
|
179
|
-
* structured formatters can enrich the output.
|
|
178
|
+
* Rebuild drivers using the current logger selection.
|
|
180
179
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return configs;
|
|
184
|
-
}
|
|
185
|
-
return {
|
|
186
|
-
...configs,
|
|
187
|
-
formatterConfig: {
|
|
188
|
-
...(configs.formatterConfig || {}),
|
|
189
|
-
defaults: {
|
|
190
|
-
...((configs.formatterConfig || {}).defaults || {}),
|
|
191
|
-
...this.messageDefaults
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
};
|
|
180
|
+
applySelection() {
|
|
181
|
+
return this[this.selection.method](...Json.copy(this.selection.values));
|
|
195
182
|
}
|
|
196
183
|
}
|