@athenna/logger 1.0.9 → 1.1.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/Drivers/ConsoleDriver.js +3 -3
- package/src/Drivers/DebugDriver.js +3 -3
- package/src/Drivers/FileDriver.js +3 -3
- package/src/Formatters/CliFormatter.d.ts +2 -2
- package/src/Formatters/CliFormatter.js +0 -1
- package/src/Formatters/JsonFormatter.d.ts +2 -2
- package/src/Formatters/JsonFormatter.js +1 -2
- package/src/Formatters/NestFormatter.d.ts +2 -2
- package/src/Formatters/NestFormatter.js +1 -2
- package/src/Formatters/SimpleFormatter.d.ts +2 -2
- package/src/Formatters/SimpleFormatter.js +2 -3
- package/src/Logger.js +5 -5
package/package.json
CHANGED
|
@@ -16,15 +16,15 @@ class ConsoleDriver {
|
|
|
16
16
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
17
17
|
this._formatter = configs.formatter || channelConfig.formatter;
|
|
18
18
|
this._streamType = configs.streamType || channelConfig.streamType;
|
|
19
|
-
this._formatterConfig =
|
|
20
|
-
configs.formatterConfig || channelConfig.formatterConfig;
|
|
19
|
+
this._formatterConfig = Object.assign({}, channelConfig.formatterConfig, configs.formatterConfig);
|
|
21
20
|
}
|
|
22
21
|
transport(message, options) {
|
|
23
22
|
options = Object.assign({}, {
|
|
24
23
|
formatter: this._formatter,
|
|
25
24
|
streamType: this._streamType,
|
|
26
25
|
}, options);
|
|
27
|
-
|
|
26
|
+
const formatterOptions = Object.assign({}, this._formatterConfig, options.formatterConfig);
|
|
27
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, formatterOptions);
|
|
28
28
|
process[options.streamType].write(`${message}\n`);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -17,15 +17,15 @@ class DebugDriver {
|
|
|
17
17
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
18
18
|
this._formatter = configs.formatter || channelConfig.formatter;
|
|
19
19
|
this._namespace = configs.namespace || channelConfig.namespace;
|
|
20
|
-
this._formatterConfig =
|
|
21
|
-
configs.formatterConfig || channelConfig.formatterConfig;
|
|
20
|
+
this._formatterConfig = Object.assign({}, channelConfig.formatterConfig, configs.formatterConfig);
|
|
22
21
|
}
|
|
23
22
|
transport(message, options) {
|
|
24
23
|
options = Object.assign({}, {
|
|
25
24
|
formatter: this._formatter,
|
|
26
25
|
namespace: this._namespace,
|
|
27
26
|
}, options);
|
|
28
|
-
|
|
27
|
+
const formatterOptions = Object.assign({}, this._formatterConfig, options.formatterConfig);
|
|
28
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, formatterOptions);
|
|
29
29
|
debug_1.debug(options.namespace)(message);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -19,8 +19,7 @@ class FileDriver {
|
|
|
19
19
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
20
20
|
this._filePath = configs.filePath || channelConfig.filePath;
|
|
21
21
|
this._formatter = configs.formatter || channelConfig.formatter;
|
|
22
|
-
this._formatterConfig =
|
|
23
|
-
configs.formatterConfig || channelConfig.formatterConfig;
|
|
22
|
+
this._formatterConfig = Object.assign({}, channelConfig.formatterConfig, configs.formatterConfig);
|
|
24
23
|
}
|
|
25
24
|
async transport(message, options) {
|
|
26
25
|
options = Object.assign({}, {
|
|
@@ -32,7 +31,8 @@ class FileDriver {
|
|
|
32
31
|
if (!fs_1.existsSync(dir)) {
|
|
33
32
|
fs_1.mkdirSync(dir, { recursive: true });
|
|
34
33
|
}
|
|
35
|
-
|
|
34
|
+
const formatterOptions = Object.assign({}, this._formatterConfig, options.formatterConfig);
|
|
35
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, formatterOptions);
|
|
36
36
|
return new Promise((resolve, reject) => {
|
|
37
37
|
const stream = fs_1.createWriteStream(filePath, { flags: 'a' });
|
|
38
38
|
stream.write(`${Color_1.Color.removeColors(message)}` + '\n');
|
|
@@ -10,10 +10,10 @@ import { Chalk } from 'chalk';
|
|
|
10
10
|
import { LevelTypes } from '../Contracts/LevelTypes';
|
|
11
11
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
12
12
|
export interface CliFormatterOptions {
|
|
13
|
-
|
|
13
|
+
chalk: Chalk;
|
|
14
14
|
level: LevelTypes;
|
|
15
15
|
}
|
|
16
16
|
export declare class CliFormatter implements FormatterContract {
|
|
17
17
|
private static paintByLevel;
|
|
18
|
-
format(message: string, options
|
|
18
|
+
format(message: string, options: CliFormatterOptions): string;
|
|
19
19
|
}
|
|
@@ -22,7 +22,6 @@ class CliFormatter {
|
|
|
22
22
|
return levelColors[level.toLowerCase()](`[ ${level.toLowerCase()} ]`);
|
|
23
23
|
}
|
|
24
24
|
format(message, options) {
|
|
25
|
-
options = Object.assign({}, { level: 'info' }, options);
|
|
26
25
|
const level = CliFormatter.paintByLevel(options.level);
|
|
27
26
|
return `${level} ${message}`;
|
|
28
27
|
}
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
import { Chalk } from 'chalk';
|
|
10
10
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
11
11
|
export interface JsonFormatterOptions {
|
|
12
|
-
|
|
12
|
+
chalk: Chalk;
|
|
13
13
|
}
|
|
14
14
|
export declare class JsonFormatter implements FormatterContract {
|
|
15
|
-
format(message: Record<any, unknown>, options
|
|
15
|
+
format(message: Record<any, unknown>, options: JsonFormatterOptions): string;
|
|
16
16
|
}
|
|
@@ -12,9 +12,8 @@ exports.JsonFormatter = void 0;
|
|
|
12
12
|
const Color_1 = require("../Utils/Color");
|
|
13
13
|
class JsonFormatter {
|
|
14
14
|
format(message, options) {
|
|
15
|
-
options = Object.assign({}, { color: Color_1.Color.green }, options);
|
|
16
15
|
const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
|
|
17
|
-
return `${pid} - ${Color_1.Color.bold('JSON:')} ${options.
|
|
16
|
+
return `${pid} - ${Color_1.Color.bold('JSON:')} ${options.chalk(JSON.stringify(message, null, 2))}`;
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
exports.JsonFormatter = JsonFormatter;
|
|
@@ -9,11 +9,11 @@
|
|
|
9
9
|
import { Chalk } from 'chalk';
|
|
10
10
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
11
11
|
export interface ContextFormatterOptions {
|
|
12
|
-
|
|
12
|
+
chalk: Chalk;
|
|
13
13
|
context: string;
|
|
14
14
|
}
|
|
15
15
|
export declare class NestFormatter implements FormatterContract {
|
|
16
16
|
private static lastTimestamp?;
|
|
17
17
|
private static getTimestampDiff;
|
|
18
|
-
format(message: string, options
|
|
18
|
+
format(message: string, options: ContextFormatterOptions): string;
|
|
19
19
|
}
|
|
@@ -21,12 +21,11 @@ class NestFormatter {
|
|
|
21
21
|
return result;
|
|
22
22
|
}
|
|
23
23
|
format(message, options) {
|
|
24
|
-
options = Object.assign({}, { color: Color_1.Color.green, context: 'Logger' }, options);
|
|
25
24
|
const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
|
|
26
25
|
const timestamp = getTimestamp_1.getTimestamp();
|
|
27
26
|
const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
|
|
28
27
|
const timestampDiff = NestFormatter.getTimestampDiff();
|
|
29
|
-
return `${pid} - ${timestamp} ${messageCtx}${options.
|
|
28
|
+
return `${pid} - ${timestamp} ${messageCtx}${options.chalk(message)}${timestampDiff}`;
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
exports.NestFormatter = NestFormatter;
|
|
@@ -10,12 +10,12 @@ import { Chalk } from 'chalk';
|
|
|
10
10
|
import { LevelTypes } from '../Contracts/LevelTypes';
|
|
11
11
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
12
12
|
export interface LogFormatterOptions {
|
|
13
|
-
|
|
13
|
+
chalk: Chalk;
|
|
14
14
|
level: LevelTypes;
|
|
15
15
|
}
|
|
16
16
|
export declare class SimpleFormatter implements FormatterContract {
|
|
17
17
|
private static lastTimestamp?;
|
|
18
18
|
private static getTimestampDiff;
|
|
19
19
|
private static paintByLevel;
|
|
20
|
-
format(message: string, options
|
|
20
|
+
format(message: string, options: LogFormatterOptions): string;
|
|
21
21
|
}
|
|
@@ -28,14 +28,13 @@ class SimpleFormatter {
|
|
|
28
28
|
error: Color_1.Color.error,
|
|
29
29
|
success: Color_1.Color.log,
|
|
30
30
|
};
|
|
31
|
-
return levelColors[level.toLowerCase()](`[${level}]`);
|
|
31
|
+
return levelColors[level.toLowerCase()](`[${level.toUpperCase()}]`);
|
|
32
32
|
}
|
|
33
33
|
format(message, options) {
|
|
34
|
-
options = Object.assign({}, { color: Color_1.Color.green, level: 'info' }, options);
|
|
35
34
|
const timestamp = getTimestamp_1.getTimestamp();
|
|
36
35
|
const timestampDiff = SimpleFormatter.getTimestampDiff();
|
|
37
36
|
const level = SimpleFormatter.paintByLevel(options.level);
|
|
38
|
-
return `${level} - ${timestamp} ${options.
|
|
37
|
+
return `${level} - ${timestamp} ${options.chalk(message)}${timestampDiff}`;
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
40
|
exports.SimpleFormatter = SimpleFormatter;
|
package/src/Logger.js
CHANGED
|
@@ -68,7 +68,7 @@ class Logger {
|
|
|
68
68
|
streamType: 'stdout',
|
|
69
69
|
formatterConfig: {
|
|
70
70
|
level: 'INFO',
|
|
71
|
-
|
|
71
|
+
chalk: Color_1.Color.cyan,
|
|
72
72
|
},
|
|
73
73
|
});
|
|
74
74
|
message = Logger.applyLogEngine(message);
|
|
@@ -79,7 +79,7 @@ class Logger {
|
|
|
79
79
|
streamType: 'stdout',
|
|
80
80
|
formatterConfig: {
|
|
81
81
|
level: 'WARN',
|
|
82
|
-
|
|
82
|
+
chalk: Color_1.Color.orange,
|
|
83
83
|
},
|
|
84
84
|
});
|
|
85
85
|
message = Logger.applyLogEngine(message);
|
|
@@ -90,7 +90,7 @@ class Logger {
|
|
|
90
90
|
streamType: 'stdout',
|
|
91
91
|
formatterConfig: {
|
|
92
92
|
level: 'ERROR',
|
|
93
|
-
|
|
93
|
+
chalk: Color_1.Color.red,
|
|
94
94
|
},
|
|
95
95
|
});
|
|
96
96
|
message = Logger.applyLogEngine(message);
|
|
@@ -101,7 +101,7 @@ class Logger {
|
|
|
101
101
|
streamType: 'stdout',
|
|
102
102
|
formatterConfig: {
|
|
103
103
|
level: 'DEBUG',
|
|
104
|
-
|
|
104
|
+
chalk: Color_1.Color.purple,
|
|
105
105
|
},
|
|
106
106
|
});
|
|
107
107
|
message = Logger.applyLogEngine(message);
|
|
@@ -112,7 +112,7 @@ class Logger {
|
|
|
112
112
|
streamType: 'stdout',
|
|
113
113
|
formatterConfig: {
|
|
114
114
|
level: 'SUCCESS',
|
|
115
|
-
|
|
115
|
+
chalk: Color_1.Color.green,
|
|
116
116
|
},
|
|
117
117
|
});
|
|
118
118
|
message = Logger.applyLogEngine(message);
|