@athenna/logger 1.0.6 → 1.0.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 +2 -2
- package/src/Drivers/ConsoleDriver.d.ts +2 -2
- package/src/Drivers/ConsoleDriver.js +3 -5
- package/src/Drivers/DebugDriver.d.ts +2 -2
- package/src/Drivers/DebugDriver.js +3 -5
- package/src/Drivers/FileDriver.d.ts +2 -2
- package/src/Drivers/FileDriver.js +3 -5
- package/src/Logger.d.ts +10 -9
- package/src/Logger.js +72 -72
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.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.0.
|
|
156
|
+
"@athenna/ioc": "1.0.9",
|
|
157
157
|
"@secjs/utils": "1.8.0",
|
|
158
158
|
"reflect-metadata": "0.1.13",
|
|
159
159
|
"tscpaths": "0.0.9"
|
|
@@ -14,12 +14,12 @@ export interface ConsoleDriverOpts {
|
|
|
14
14
|
context: string;
|
|
15
15
|
formatter: string;
|
|
16
16
|
streamType: string;
|
|
17
|
+
formatterConfig: any;
|
|
17
18
|
}
|
|
18
19
|
export declare class ConsoleDriver implements DriverContract {
|
|
19
|
-
private readonly _level;
|
|
20
|
-
private readonly _context;
|
|
21
20
|
private readonly _formatter;
|
|
22
21
|
private readonly _streamType;
|
|
22
|
+
private readonly _formatterConfig;
|
|
23
23
|
constructor(channel: string, configs?: any);
|
|
24
24
|
transport(message: string, options?: ConsoleDriverOpts): void;
|
|
25
25
|
}
|
|
@@ -14,19 +14,17 @@ const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
|
14
14
|
class ConsoleDriver {
|
|
15
15
|
constructor(channel, configs = {}) {
|
|
16
16
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
17
|
-
this._level = configs.level || channelConfig.level;
|
|
18
|
-
this._context = configs.context || channelConfig.context;
|
|
19
17
|
this._formatter = configs.formatter || channelConfig.formatter;
|
|
20
18
|
this._streamType = configs.streamType || channelConfig.streamType;
|
|
19
|
+
this._formatterConfig =
|
|
20
|
+
configs.formatterConfig || channelConfig.formatterConfig;
|
|
21
21
|
}
|
|
22
22
|
transport(message, options) {
|
|
23
23
|
options = Object.assign({}, {
|
|
24
|
-
level: this._level,
|
|
25
|
-
context: this._context,
|
|
26
24
|
formatter: this._formatter,
|
|
27
25
|
streamType: this._streamType,
|
|
28
26
|
}, options);
|
|
29
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
27
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options.formatterConfig || this._formatterConfig);
|
|
30
28
|
process[options.streamType].write(`${message}\n`);
|
|
31
29
|
}
|
|
32
30
|
}
|
|
@@ -14,12 +14,12 @@ export interface DebugDriverOpts {
|
|
|
14
14
|
context: string;
|
|
15
15
|
formatter: string;
|
|
16
16
|
namespace: string;
|
|
17
|
+
formatterConfig: any;
|
|
17
18
|
}
|
|
18
19
|
export declare class DebugDriver implements DriverContract {
|
|
19
|
-
private readonly _level;
|
|
20
|
-
private readonly _context;
|
|
21
20
|
private readonly _formatter;
|
|
22
21
|
private readonly _namespace;
|
|
22
|
+
private readonly _formatterConfig;
|
|
23
23
|
constructor(channel: string, configs?: any);
|
|
24
24
|
transport(message: string, options?: DebugDriverOpts): void;
|
|
25
25
|
}
|
|
@@ -15,19 +15,17 @@ const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
|
15
15
|
class DebugDriver {
|
|
16
16
|
constructor(channel, configs = {}) {
|
|
17
17
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
18
|
-
this._level = configs.level || channelConfig.level;
|
|
19
|
-
this._context = configs.context || channelConfig.context;
|
|
20
18
|
this._formatter = configs.formatter || channelConfig.formatter;
|
|
21
19
|
this._namespace = configs.namespace || channelConfig.namespace;
|
|
20
|
+
this._formatterConfig =
|
|
21
|
+
configs.formatterConfig || channelConfig.formatterConfig;
|
|
22
22
|
}
|
|
23
23
|
transport(message, options) {
|
|
24
24
|
options = Object.assign({}, {
|
|
25
|
-
level: this._level,
|
|
26
|
-
context: this._context,
|
|
27
25
|
formatter: this._formatter,
|
|
28
26
|
namespace: this._namespace,
|
|
29
27
|
}, options);
|
|
30
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
28
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options.formatterConfig || this._formatterConfig);
|
|
31
29
|
debug_1.debug(options.namespace)(message);
|
|
32
30
|
}
|
|
33
31
|
}
|
|
@@ -12,12 +12,12 @@ export interface FileDriverOpts {
|
|
|
12
12
|
context: string;
|
|
13
13
|
formatter: string;
|
|
14
14
|
filePath: string;
|
|
15
|
+
formatterConfig: any;
|
|
15
16
|
}
|
|
16
17
|
export declare class FileDriver implements DriverContract {
|
|
17
|
-
private readonly _level;
|
|
18
|
-
private readonly _context;
|
|
19
18
|
private readonly _filePath;
|
|
20
19
|
private readonly _formatter;
|
|
20
|
+
private readonly _formatterConfig;
|
|
21
21
|
constructor(channel: string, configs?: any);
|
|
22
22
|
transport(message: string, options?: FileDriverOpts): Promise<void>;
|
|
23
23
|
}
|
|
@@ -17,15 +17,13 @@ const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
|
17
17
|
class FileDriver {
|
|
18
18
|
constructor(channel, configs = {}) {
|
|
19
19
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
20
|
-
this._level = configs.level || channelConfig.level;
|
|
21
|
-
this._context = configs.context || channelConfig.context;
|
|
22
20
|
this._filePath = configs.filePath || channelConfig.filePath;
|
|
23
21
|
this._formatter = configs.formatter || channelConfig.formatter;
|
|
22
|
+
this._formatterConfig =
|
|
23
|
+
configs.formatterConfig || channelConfig.formatterConfig;
|
|
24
24
|
}
|
|
25
25
|
async transport(message, options) {
|
|
26
26
|
options = Object.assign({}, {
|
|
27
|
-
level: this._level,
|
|
28
|
-
context: this._context,
|
|
29
27
|
filePath: this._filePath,
|
|
30
28
|
formatter: this._formatter,
|
|
31
29
|
}, options);
|
|
@@ -34,7 +32,7 @@ class FileDriver {
|
|
|
34
32
|
if (!fs_1.existsSync(dir)) {
|
|
35
33
|
fs_1.mkdirSync(dir, { recursive: true });
|
|
36
34
|
}
|
|
37
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
35
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options.formatterConfig || this._formatterConfig);
|
|
38
36
|
return new Promise((resolve, reject) => {
|
|
39
37
|
const stream = fs_1.createWriteStream(filePath, { flags: 'a' });
|
|
40
38
|
stream.write(`${Color_1.Color.removeColors(message)}` + '\n');
|
package/src/Logger.d.ts
CHANGED
|
@@ -4,16 +4,17 @@ export declare class Logger {
|
|
|
4
4
|
private runtimeConfig;
|
|
5
5
|
private channelName;
|
|
6
6
|
private driver;
|
|
7
|
-
|
|
8
|
-
static buildFormatter(name: string, formatter: new () => FormatterContract): void;
|
|
7
|
+
constructor(runtimeConfig?: any);
|
|
9
8
|
static get drivers(): string[];
|
|
10
9
|
static get formatters(): string[];
|
|
11
|
-
|
|
10
|
+
static buildDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): void;
|
|
11
|
+
static buildFormatter(name: string, formatter: new () => FormatterContract): void;
|
|
12
12
|
channel(channel: string, runtimeConfig?: any): Logger;
|
|
13
|
-
log(message: any, options?:
|
|
14
|
-
info(message: any, options?:
|
|
15
|
-
warn(message: any, options?:
|
|
16
|
-
error(message: any, options?:
|
|
17
|
-
debug(message: any, options?:
|
|
18
|
-
success(message: any, options?:
|
|
13
|
+
log(message: any, options?: {}): void | Promise<void>;
|
|
14
|
+
info(message: any, options?: {}): void | Promise<void>;
|
|
15
|
+
warn(message: any, options?: {}): void | Promise<void>;
|
|
16
|
+
error(message: any, options?: {}): void | Promise<void>;
|
|
17
|
+
debug(message: any, options?: {}): void | Promise<void>;
|
|
18
|
+
success(message: any, options?: {}): void | Promise<void>;
|
|
19
|
+
private createOptions;
|
|
19
20
|
}
|
package/src/Logger.js
CHANGED
|
@@ -12,98 +12,98 @@ class Logger {
|
|
|
12
12
|
this.channelName = 'default';
|
|
13
13
|
this.driver = DriverFactory_1.DriverFactory.fabricate(this.channelName, this.runtimeConfig);
|
|
14
14
|
}
|
|
15
|
-
static buildDriver(name, driver) {
|
|
16
|
-
DriverFactory_1.DriverFactory.createDriver(name, driver);
|
|
17
|
-
}
|
|
18
|
-
static buildFormatter(name, formatter) {
|
|
19
|
-
FormatterFactory_1.FormatterFactory.createFormatter(name, formatter);
|
|
20
|
-
}
|
|
21
15
|
static get drivers() {
|
|
22
16
|
return DriverFactory_1.DriverFactory.availableDrivers();
|
|
23
17
|
}
|
|
24
18
|
static get formatters() {
|
|
25
19
|
return FormatterFactory_1.FormatterFactory.availableFormatters();
|
|
26
20
|
}
|
|
21
|
+
static buildDriver(name, driver) {
|
|
22
|
+
DriverFactory_1.DriverFactory.createDriver(name, driver);
|
|
23
|
+
}
|
|
24
|
+
static buildFormatter(name, formatter) {
|
|
25
|
+
FormatterFactory_1.FormatterFactory.createFormatter(name, formatter);
|
|
26
|
+
}
|
|
27
27
|
channel(channel, runtimeConfig) {
|
|
28
28
|
if (runtimeConfig)
|
|
29
29
|
this.runtimeConfig = runtimeConfig;
|
|
30
30
|
this.driver = DriverFactory_1.DriverFactory.fabricate(channel, this.runtimeConfig);
|
|
31
31
|
return this;
|
|
32
32
|
}
|
|
33
|
-
|
|
34
|
-
options =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
...this.runtimeConfig.formatterConfig,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
await this.driver.transport(message, options);
|
|
33
|
+
log(message, options = {}) {
|
|
34
|
+
options = this.createOptions(options, {
|
|
35
|
+
streamType: 'stdout',
|
|
36
|
+
});
|
|
37
|
+
return this.driver.transport(message, options);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
options =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
await this.driver.transport(message, options);
|
|
39
|
+
info(message, options = {}) {
|
|
40
|
+
options = this.createOptions(options, {
|
|
41
|
+
streamType: 'stdout',
|
|
42
|
+
formatterConfig: {
|
|
43
|
+
level: 'INFO',
|
|
44
|
+
color: Color_1.Color.cyan,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
return this.driver.transport(message, options);
|
|
55
48
|
}
|
|
56
|
-
|
|
57
|
-
options =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
await this.driver.transport(message, options);
|
|
49
|
+
warn(message, options = {}) {
|
|
50
|
+
options = this.createOptions(options, {
|
|
51
|
+
streamType: 'stdout',
|
|
52
|
+
formatterConfig: {
|
|
53
|
+
level: 'WARN',
|
|
54
|
+
color: Color_1.Color.orange,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
return this.driver.transport(message, options);
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
options =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
await this.driver.transport(message, options);
|
|
59
|
+
error(message, options = {}) {
|
|
60
|
+
options = this.createOptions(options, {
|
|
61
|
+
streamType: 'stdout',
|
|
62
|
+
formatterConfig: {
|
|
63
|
+
level: 'ERROR',
|
|
64
|
+
color: Color_1.Color.red,
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
return this.driver.transport(message, options);
|
|
81
68
|
}
|
|
82
|
-
|
|
83
|
-
options =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
debug(message, options = {}) {
|
|
70
|
+
options = this.createOptions(options, {
|
|
71
|
+
streamType: 'stdout',
|
|
72
|
+
formatterConfig: {
|
|
73
|
+
level: 'DEBUG',
|
|
74
|
+
color: Color_1.Color.purple,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
return this.driver.transport(message, options);
|
|
78
|
+
}
|
|
79
|
+
success(message, options = {}) {
|
|
80
|
+
options = this.createOptions(options, {
|
|
81
|
+
streamType: 'stdout',
|
|
82
|
+
formatterConfig: {
|
|
83
|
+
level: 'SUCCESS',
|
|
84
|
+
color: Color_1.Color.green,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return this.driver.transport(message, options);
|
|
94
88
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
options.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
options = {
|
|
102
|
-
...options,
|
|
89
|
+
createOptions(options, defaultValues) {
|
|
90
|
+
let formatterConfig = Object.assign({}, {
|
|
91
|
+
...defaultValues.formatterConfig,
|
|
92
|
+
}, options.formatterConfig);
|
|
93
|
+
if (this.runtimeConfig.formatterConfig) {
|
|
94
|
+
formatterConfig = {
|
|
103
95
|
...this.runtimeConfig.formatterConfig,
|
|
96
|
+
...formatterConfig,
|
|
104
97
|
};
|
|
105
98
|
}
|
|
106
|
-
|
|
99
|
+
options = Object.assign({}, {
|
|
100
|
+
streamType: 'stdout',
|
|
101
|
+
}, options);
|
|
102
|
+
options = {
|
|
103
|
+
...options,
|
|
104
|
+
formatterConfig,
|
|
105
|
+
};
|
|
106
|
+
return options;
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
109
|
exports.Logger = Logger;
|