@athenna/logger 1.0.2 → 1.0.5
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 +0 -1
- package/index.js +0 -1
- package/package.json +3 -1
- package/src/Drivers/ConsoleDriver.d.ts +2 -1
- package/src/Drivers/ConsoleDriver.js +8 -7
- package/src/Drivers/DebugDriver.d.ts +1 -1
- package/src/Drivers/DebugDriver.js +7 -6
- package/src/Drivers/FileDriver.d.ts +1 -1
- package/src/Drivers/FileDriver.js +13 -8
- package/src/Formatters/ContextFormatter.js +1 -1
- package/src/Formatters/DebugFormatter.js +1 -1
- package/src/Formatters/JsonFormatter.js +1 -1
- package/src/{Utils/global.d.ts → Providers/LoggerProvider.d.ts} +4 -6
- package/src/{Utils/global.js → Providers/LoggerProvider.js} +9 -4
- package/src/Log.d.ts +0 -18
- package/src/Log.js +0 -79
package/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
export * from './src/Log';
|
|
10
9
|
export * from './src/Logger';
|
|
11
10
|
export * from './src/Contracts/DriverContract';
|
|
12
11
|
export * from './src/Contracts/FormatterContract';
|
package/index.js
CHANGED
|
@@ -18,7 +18,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
18
18
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
19
|
};
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
__exportStar(require("./src/Log"), exports);
|
|
22
21
|
__exportStar(require("./src/Logger"), exports);
|
|
23
22
|
__exportStar(require("./src/Contracts/DriverContract"), exports);
|
|
24
23
|
__exportStar(require("./src/Contracts/FormatterContract"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -130,6 +130,7 @@
|
|
|
130
130
|
"@typescript-eslint/interface-name-prefix": "off",
|
|
131
131
|
"@typescript-eslint/no-explicit-any": "off",
|
|
132
132
|
"prettier/prettier": "error",
|
|
133
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
133
134
|
"@typescript-eslint/no-unused-vars": [
|
|
134
135
|
"error",
|
|
135
136
|
{
|
|
@@ -152,6 +153,7 @@
|
|
|
152
153
|
}
|
|
153
154
|
},
|
|
154
155
|
"dependencies": {
|
|
156
|
+
"@athenna/ioc": "1.0.7",
|
|
155
157
|
"@secjs/utils": "1.8.0",
|
|
156
158
|
"reflect-metadata": "0.1.13",
|
|
157
159
|
"tscpaths": "0.0.9"
|
|
@@ -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,21 +12,22 @@ 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
|
-
process[
|
|
29
|
+
message = FormatterFactory_1.FormatterFactory.fabricate(options.formatter).format(message, options);
|
|
30
|
+
process[options.streamType].write(`${message}\n`);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
exports.ConsoleDriver = ConsoleDriver;
|
|
@@ -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');
|
|
@@ -14,7 +14,7 @@ const getTimestamp_1 = require("../Utils/getTimestamp");
|
|
|
14
14
|
class ContextFormatter {
|
|
15
15
|
format(message, options) {
|
|
16
16
|
options = Object.assign({}, { color: Color_1.Color.green, context: 'Logger' }, options);
|
|
17
|
-
const pid = Color_1.Color.
|
|
17
|
+
const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
|
|
18
18
|
const timestamp = getTimestamp_1.getTimestamp();
|
|
19
19
|
const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
|
|
20
20
|
const timestampDiff = ContextFormatter.getTimestampDiff();
|
|
@@ -14,7 +14,7 @@ const getTimestamp_1 = require("../Utils/getTimestamp");
|
|
|
14
14
|
class DebugFormatter {
|
|
15
15
|
format(message, options) {
|
|
16
16
|
options = Object.assign({}, { color: Color_1.Color.green, context: 'Debugger', namespace: 'api:main' }, options);
|
|
17
|
-
const pid = Color_1.Color.
|
|
17
|
+
const pid = Color_1.Color.yellow(`[Athenna Debugger] - PID: ${process.pid}`);
|
|
18
18
|
const timestamp = Color_1.Color.white(getTimestamp_1.getTimestamp());
|
|
19
19
|
const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
|
|
20
20
|
const timestampDiff = DebugFormatter.getTimestampDiff();
|
|
@@ -14,7 +14,7 @@ class JsonFormatter {
|
|
|
14
14
|
format(message, options) {
|
|
15
15
|
options = Object.assign({}, { color: Color_1.Color.green }, options);
|
|
16
16
|
const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
|
|
17
|
-
return `${pid} - ${Color_1.Color.bold('JSON:')} ${options.color(JSON.stringify(message))}`;
|
|
17
|
+
return `${pid} - ${Color_1.Color.bold('JSON:')} ${options.color(JSON.stringify(message, null, 2))}`;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
exports.JsonFormatter = JsonFormatter;
|
|
@@ -6,10 +6,8 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const Log: typeof LogFunction;
|
|
14
|
-
const Logger: typeof LoggerClass;
|
|
9
|
+
import { ServiceProvider } from '@athenna/ioc';
|
|
10
|
+
export declare class LoggerProvider extends ServiceProvider {
|
|
11
|
+
boot(): void;
|
|
12
|
+
register(): void;
|
|
15
13
|
}
|
|
@@ -8,8 +8,13 @@
|
|
|
8
8
|
* file that was distributed with this source code.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
|
|
11
|
+
exports.LoggerProvider = void 0;
|
|
12
12
|
const Logger_1 = require("../Logger");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const ioc_1 = require("@athenna/ioc");
|
|
14
|
+
class LoggerProvider extends ioc_1.ServiceProvider {
|
|
15
|
+
boot() { }
|
|
16
|
+
register() {
|
|
17
|
+
this.container.bind('Athenna/Core/Logger', Logger_1.Logger);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.LoggerProvider = LoggerProvider;
|
package/src/Log.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { DriverContract } from './Contracts/DriverContract';
|
|
2
|
-
import { FormatterContract } from './Contracts/FormatterContract';
|
|
3
|
-
export declare class Log {
|
|
4
|
-
private static _options?;
|
|
5
|
-
private static logger;
|
|
6
|
-
static options(options?: any): void;
|
|
7
|
-
static buildDriver(name: string, driver: new (channel: string, configs?: any) => DriverContract): typeof Log;
|
|
8
|
-
static buildFormatter(name: string, formatter: new () => FormatterContract): typeof Log;
|
|
9
|
-
static get drivers(): string[];
|
|
10
|
-
static get formatters(): string[];
|
|
11
|
-
static channel(channel: string): typeof Log;
|
|
12
|
-
static log(message: any, options?: any): void;
|
|
13
|
-
static info(message: any, options?: any): void;
|
|
14
|
-
static warn(message: any, options?: any): void;
|
|
15
|
-
static error(message: any, options?: any): void;
|
|
16
|
-
static debug(message: any, options?: any): void;
|
|
17
|
-
static success(message: any, options?: any): void;
|
|
18
|
-
}
|
package/src/Log.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Log = void 0;
|
|
4
|
-
const Logger_1 = require("./Logger");
|
|
5
|
-
class Log {
|
|
6
|
-
static options(options) {
|
|
7
|
-
this._options = options;
|
|
8
|
-
}
|
|
9
|
-
static buildDriver(name, driver) {
|
|
10
|
-
Logger_1.Logger.buildDriver(name, driver);
|
|
11
|
-
return this;
|
|
12
|
-
}
|
|
13
|
-
static buildFormatter(name, formatter) {
|
|
14
|
-
Logger_1.Logger.buildFormatter(name, formatter);
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
static get drivers() {
|
|
18
|
-
return Logger_1.Logger.drivers;
|
|
19
|
-
}
|
|
20
|
-
static get formatters() {
|
|
21
|
-
return Logger_1.Logger.formatters;
|
|
22
|
-
}
|
|
23
|
-
static channel(channel) {
|
|
24
|
-
if (!this.logger)
|
|
25
|
-
this.logger = new Logger_1.Logger();
|
|
26
|
-
this.logger.channel(channel);
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
static log(message, options) {
|
|
30
|
-
options = {
|
|
31
|
-
...options,
|
|
32
|
-
...this._options,
|
|
33
|
-
};
|
|
34
|
-
this.logger.log(message, options);
|
|
35
|
-
this.logger = new Logger_1.Logger();
|
|
36
|
-
}
|
|
37
|
-
static info(message, options) {
|
|
38
|
-
options = {
|
|
39
|
-
...options,
|
|
40
|
-
...this._options,
|
|
41
|
-
};
|
|
42
|
-
this.logger.info(message, options);
|
|
43
|
-
this.logger = new Logger_1.Logger();
|
|
44
|
-
}
|
|
45
|
-
static warn(message, options) {
|
|
46
|
-
options = {
|
|
47
|
-
...options,
|
|
48
|
-
...this._options,
|
|
49
|
-
};
|
|
50
|
-
this.logger.warn(message, options);
|
|
51
|
-
this.logger = new Logger_1.Logger();
|
|
52
|
-
}
|
|
53
|
-
static error(message, options) {
|
|
54
|
-
options = {
|
|
55
|
-
...options,
|
|
56
|
-
...this._options,
|
|
57
|
-
};
|
|
58
|
-
this.logger.error(message, options);
|
|
59
|
-
this.logger = new Logger_1.Logger();
|
|
60
|
-
}
|
|
61
|
-
static debug(message, options) {
|
|
62
|
-
options = {
|
|
63
|
-
...options,
|
|
64
|
-
...this._options,
|
|
65
|
-
};
|
|
66
|
-
this.logger.debug(message, options);
|
|
67
|
-
this.logger = new Logger_1.Logger();
|
|
68
|
-
}
|
|
69
|
-
static success(message, options) {
|
|
70
|
-
options = {
|
|
71
|
-
...options,
|
|
72
|
-
...this._options,
|
|
73
|
-
};
|
|
74
|
-
this.logger.success(message, options);
|
|
75
|
-
this.logger = new Logger_1.Logger();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.Log = Log;
|
|
79
|
-
Log._options = {};
|