@athenna/logger 1.0.2 → 1.0.3
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
|
@@ -12,6 +12,7 @@ export interface ConsoleDriverOpts {
|
|
|
12
12
|
color: Color;
|
|
13
13
|
level: string;
|
|
14
14
|
context: string;
|
|
15
|
+
formatter: string;
|
|
15
16
|
streamType: string;
|
|
16
17
|
}
|
|
17
18
|
export declare class ConsoleDriver implements DriverContract {
|
|
@@ -19,6 +20,6 @@ export declare class ConsoleDriver implements DriverContract {
|
|
|
19
20
|
private readonly _context;
|
|
20
21
|
private readonly _formatter;
|
|
21
22
|
private readonly _streamType;
|
|
22
|
-
constructor(channel: string);
|
|
23
|
+
constructor(channel: string, configs?: any);
|
|
23
24
|
transport(message: string, options?: ConsoleDriverOpts): void;
|
|
24
25
|
}
|
|
@@ -12,20 +12,21 @@ exports.ConsoleDriver = void 0;
|
|
|
12
12
|
const utils_1 = require("@secjs/utils");
|
|
13
13
|
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
14
14
|
class ConsoleDriver {
|
|
15
|
-
constructor(channel) {
|
|
15
|
+
constructor(channel, configs = {}) {
|
|
16
16
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
17
|
-
this._level =
|
|
18
|
-
this._context =
|
|
19
|
-
this._formatter =
|
|
20
|
-
this._streamType =
|
|
17
|
+
this._level = configs.level || channelConfig.level;
|
|
18
|
+
this._context = configs.context || channelConfig.context;
|
|
19
|
+
this._formatter = configs.formatter || channelConfig.formatter;
|
|
20
|
+
this._streamType = configs.streamType || channelConfig.streamType;
|
|
21
21
|
}
|
|
22
22
|
transport(message, options) {
|
|
23
23
|
options = Object.assign({}, {
|
|
24
24
|
level: this._level,
|
|
25
25
|
context: this._context,
|
|
26
|
+
formatter: this._formatter,
|
|
26
27
|
streamType: this._streamType,
|
|
27
28
|
}, options);
|
|
28
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(
|
|
29
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
29
30
|
process[this._streamType].write(`${message}\n`);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
@@ -20,6 +20,6 @@ export declare class DebugDriver implements DriverContract {
|
|
|
20
20
|
private readonly _context;
|
|
21
21
|
private readonly _formatter;
|
|
22
22
|
private readonly _namespace;
|
|
23
|
-
constructor(channel: string);
|
|
23
|
+
constructor(channel: string, configs?: any);
|
|
24
24
|
transport(message: string, options?: DebugDriverOpts): void;
|
|
25
25
|
}
|
|
@@ -13,20 +13,21 @@ const debug_1 = require("debug");
|
|
|
13
13
|
const utils_1 = require("@secjs/utils");
|
|
14
14
|
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
15
15
|
class DebugDriver {
|
|
16
|
-
constructor(channel) {
|
|
16
|
+
constructor(channel, configs = {}) {
|
|
17
17
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
18
|
-
this._level =
|
|
19
|
-
this._context =
|
|
20
|
-
this._formatter =
|
|
21
|
-
this._namespace =
|
|
18
|
+
this._level = configs.level || channelConfig.level;
|
|
19
|
+
this._context = configs.context || channelConfig.context;
|
|
20
|
+
this._formatter = configs.formatter || channelConfig.formatter;
|
|
21
|
+
this._namespace = configs.namespace || channelConfig.namespace;
|
|
22
22
|
}
|
|
23
23
|
transport(message, options) {
|
|
24
24
|
options = Object.assign({}, {
|
|
25
25
|
level: this._level,
|
|
26
26
|
context: this._context,
|
|
27
|
+
formatter: this._formatter,
|
|
27
28
|
namespace: this._namespace,
|
|
28
29
|
}, options);
|
|
29
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(
|
|
30
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
30
31
|
debug_1.debug(options.namespace)(message);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
@@ -18,6 +18,6 @@ export declare class FileDriver implements DriverContract {
|
|
|
18
18
|
private readonly _context;
|
|
19
19
|
private readonly _filePath;
|
|
20
20
|
private readonly _formatter;
|
|
21
|
-
constructor(channel: string);
|
|
21
|
+
constructor(channel: string, configs?: any);
|
|
22
22
|
transport(message: string, options?: FileDriverOpts): Promise<void>;
|
|
23
23
|
}
|
|
@@ -10,26 +10,31 @@
|
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.FileDriver = void 0;
|
|
12
12
|
const path_1 = require("path");
|
|
13
|
-
const Color_1 = require("../Utils/Color");
|
|
14
13
|
const utils_1 = require("@secjs/utils");
|
|
14
|
+
const Color_1 = require("../Utils/Color");
|
|
15
15
|
const fs_1 = require("fs");
|
|
16
16
|
const FormatterFactory_1 = require("../Factories/FormatterFactory");
|
|
17
17
|
class FileDriver {
|
|
18
|
-
constructor(channel) {
|
|
18
|
+
constructor(channel, configs = {}) {
|
|
19
19
|
const channelConfig = utils_1.Config.get(`logging.channels.${channel}`);
|
|
20
|
-
this._level =
|
|
21
|
-
this._context =
|
|
22
|
-
this._filePath =
|
|
23
|
-
this._formatter =
|
|
20
|
+
this._level = configs.level || channelConfig.level;
|
|
21
|
+
this._context = configs.context || channelConfig.context;
|
|
22
|
+
this._filePath = configs.filePath || channelConfig.filePath;
|
|
23
|
+
this._formatter = configs.formatter || channelConfig.formatter;
|
|
24
24
|
}
|
|
25
25
|
async transport(message, options) {
|
|
26
|
-
options = Object.assign({}, {
|
|
26
|
+
options = Object.assign({}, {
|
|
27
|
+
level: this._level,
|
|
28
|
+
context: this._context,
|
|
29
|
+
filePath: this._filePath,
|
|
30
|
+
formatter: this._formatter,
|
|
31
|
+
}, options);
|
|
27
32
|
const filePath = options.filePath;
|
|
28
33
|
const { dir } = path_1.parse(filePath);
|
|
29
34
|
if (!fs_1.existsSync(dir)) {
|
|
30
35
|
fs_1.mkdirSync(dir, { recursive: true });
|
|
31
36
|
}
|
|
32
|
-
message = FormatterFactory_1.FormatterFactory.fabricate(
|
|
37
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
33
38
|
return new Promise((resolve, reject) => {
|
|
34
39
|
const stream = fs_1.createWriteStream(filePath, { flags: 'a' });
|
|
35
40
|
stream.write(`${Color_1.Color.removeColors(message)}` + '\n');
|