@athenna/logger 1.0.9 → 1.1.2
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/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +3 -3
- 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 +6 -7
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -19,5 +19,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
21
|
__exportStar(require("./src/Logger"), exports);
|
|
22
|
+
__exportStar(require("./src/Utils/Color"), exports);
|
|
22
23
|
__exportStar(require("./src/Contracts/DriverContract"), exports);
|
|
23
24
|
__exportStar(require("./src/Contracts/FormatterContract"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -153,8 +153,8 @@
|
|
|
153
153
|
}
|
|
154
154
|
},
|
|
155
155
|
"dependencies": {
|
|
156
|
-
"@athenna/ioc": "1.
|
|
157
|
-
"@secjs/utils": "1.8.
|
|
156
|
+
"@athenna/ioc": "1.1.1",
|
|
157
|
+
"@secjs/utils": "1.8.2",
|
|
158
158
|
"chalk": "4.1.1",
|
|
159
159
|
"reflect-metadata": "0.1.13",
|
|
160
160
|
"tscpaths": "0.0.9"
|
|
@@ -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
|
@@ -5,13 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.Logger = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
const Color_1 = require("./Utils/Color");
|
|
9
8
|
const utils_1 = require("@secjs/utils");
|
|
9
|
+
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
13
|
constructor(runtimeConfig = {}) {
|
|
14
|
-
new utils_1.Config().safeLoad(utils_1.Path.config('logging'));
|
|
15
14
|
this.runtimeConfig = runtimeConfig;
|
|
16
15
|
this.channelName = 'default';
|
|
17
16
|
this.driver = DriverFactory_1.DriverFactory.fabricate(this.channelName, this.runtimeConfig);
|
|
@@ -68,7 +67,7 @@ class Logger {
|
|
|
68
67
|
streamType: 'stdout',
|
|
69
68
|
formatterConfig: {
|
|
70
69
|
level: 'INFO',
|
|
71
|
-
|
|
70
|
+
chalk: Color_1.Color.cyan,
|
|
72
71
|
},
|
|
73
72
|
});
|
|
74
73
|
message = Logger.applyLogEngine(message);
|
|
@@ -79,7 +78,7 @@ class Logger {
|
|
|
79
78
|
streamType: 'stdout',
|
|
80
79
|
formatterConfig: {
|
|
81
80
|
level: 'WARN',
|
|
82
|
-
|
|
81
|
+
chalk: Color_1.Color.orange,
|
|
83
82
|
},
|
|
84
83
|
});
|
|
85
84
|
message = Logger.applyLogEngine(message);
|
|
@@ -90,7 +89,7 @@ class Logger {
|
|
|
90
89
|
streamType: 'stdout',
|
|
91
90
|
formatterConfig: {
|
|
92
91
|
level: 'ERROR',
|
|
93
|
-
|
|
92
|
+
chalk: Color_1.Color.red,
|
|
94
93
|
},
|
|
95
94
|
});
|
|
96
95
|
message = Logger.applyLogEngine(message);
|
|
@@ -101,7 +100,7 @@ class Logger {
|
|
|
101
100
|
streamType: 'stdout',
|
|
102
101
|
formatterConfig: {
|
|
103
102
|
level: 'DEBUG',
|
|
104
|
-
|
|
103
|
+
chalk: Color_1.Color.purple,
|
|
105
104
|
},
|
|
106
105
|
});
|
|
107
106
|
message = Logger.applyLogEngine(message);
|
|
@@ -112,7 +111,7 @@ class Logger {
|
|
|
112
111
|
streamType: 'stdout',
|
|
113
112
|
formatterConfig: {
|
|
114
113
|
level: 'SUCCESS',
|
|
115
|
-
|
|
114
|
+
chalk: Color_1.Color.green,
|
|
116
115
|
},
|
|
117
116
|
});
|
|
118
117
|
message = Logger.applyLogEngine(message);
|