@athenna/logger 1.0.6 → 1.0.9
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 +3 -2
- package/src/Contracts/LevelTypes.d.ts +1 -0
- package/src/Contracts/LevelTypes.js +2 -0
- 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/Factories/FormatterFactory.js +6 -6
- package/src/Formatters/{DebugFormatter.d.ts → CliFormatter.d.ts} +6 -7
- package/src/Formatters/CliFormatter.js +30 -0
- package/src/Formatters/{ContextFormatter.d.ts → NestFormatter.d.ts} +2 -2
- package/src/Formatters/{ContextFormatter.js → NestFormatter.js} +11 -11
- package/src/Formatters/{LogFormatter.d.ts → SimpleFormatter.d.ts} +6 -3
- package/src/Formatters/{LogFormatter.js → SimpleFormatter.js} +17 -9
- package/src/Logger.d.ts +11 -9
- package/src/Logger.js +103 -71
- package/src/Utils/Color.d.ts +11 -3
- package/src/Formatters/DebugFormatter.js +0 -32
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -153,8 +153,9 @@
|
|
|
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
|
+
"chalk": "4.1.1",
|
|
158
159
|
"reflect-metadata": "0.1.13",
|
|
159
160
|
"tscpaths": "0.0.9"
|
|
160
161
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare type LevelTypes = 'info' | 'INFO' | 'debug' | 'DEBUG' | 'warn' | 'WARN' | 'error' | 'ERROR' | 'success' | 'SUCCESS';
|
|
@@ -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');
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
11
|
exports.FormatterFactory = void 0;
|
|
12
|
-
const LogFormatter_1 = require("../Formatters/LogFormatter");
|
|
13
12
|
const JsonFormatter_1 = require("../Formatters/JsonFormatter");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const NestFormatter_1 = require("../Formatters/NestFormatter");
|
|
14
|
+
const SimpleFormatter_1 = require("../Formatters/SimpleFormatter");
|
|
16
15
|
const NotFoundFormatterException_1 = require("../Exceptions/NotFoundFormatterException");
|
|
17
16
|
const FormatterAlreadyExistException_1 = require("../Exceptions/FormatterAlreadyExistException");
|
|
17
|
+
const CliFormatter_1 = require("../Formatters/CliFormatter");
|
|
18
18
|
class FormatterFactory {
|
|
19
19
|
static availableFormatters() {
|
|
20
20
|
const availableFormatters = [];
|
|
@@ -39,7 +39,7 @@ class FormatterFactory {
|
|
|
39
39
|
}
|
|
40
40
|
exports.FormatterFactory = FormatterFactory;
|
|
41
41
|
FormatterFactory.formatters = new Map()
|
|
42
|
-
.set('
|
|
43
|
-
.set('
|
|
42
|
+
.set('cli', { Formatter: CliFormatter_1.CliFormatter })
|
|
43
|
+
.set('nest', { Formatter: NestFormatter_1.NestFormatter })
|
|
44
44
|
.set('json', { Formatter: JsonFormatter_1.JsonFormatter })
|
|
45
|
-
.set('
|
|
45
|
+
.set('simple', { Formatter: SimpleFormatter_1.SimpleFormatter });
|
|
@@ -7,14 +7,13 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Chalk } from 'chalk';
|
|
10
|
+
import { LevelTypes } from '../Contracts/LevelTypes';
|
|
10
11
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
11
|
-
export interface
|
|
12
|
+
export interface CliFormatterOptions {
|
|
12
13
|
color: Chalk;
|
|
13
|
-
|
|
14
|
-
namespace: string;
|
|
14
|
+
level: LevelTypes;
|
|
15
15
|
}
|
|
16
|
-
export declare class
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
private static getTimestampDiff;
|
|
16
|
+
export declare class CliFormatter implements FormatterContract {
|
|
17
|
+
private static paintByLevel;
|
|
18
|
+
format(message: string, options?: CliFormatterOptions): string;
|
|
20
19
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @athenna/logger
|
|
4
|
+
*
|
|
5
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
6
|
+
*
|
|
7
|
+
* For the full copyright and license information, please view the LICENSE
|
|
8
|
+
* file that was distributed with this source code.
|
|
9
|
+
*/
|
|
10
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
+
exports.CliFormatter = void 0;
|
|
12
|
+
const Color_1 = require("../Utils/Color");
|
|
13
|
+
class CliFormatter {
|
|
14
|
+
static paintByLevel(level) {
|
|
15
|
+
const levelColors = {
|
|
16
|
+
info: Color_1.Color.info,
|
|
17
|
+
debug: Color_1.Color.debug,
|
|
18
|
+
warn: Color_1.Color.warning,
|
|
19
|
+
error: Color_1.Color.error,
|
|
20
|
+
success: Color_1.Color.log,
|
|
21
|
+
};
|
|
22
|
+
return levelColors[level.toLowerCase()](`[ ${level.toLowerCase()} ]`);
|
|
23
|
+
}
|
|
24
|
+
format(message, options) {
|
|
25
|
+
options = Object.assign({}, { level: 'info' }, options);
|
|
26
|
+
const level = CliFormatter.paintByLevel(options.level);
|
|
27
|
+
return `${level} ${message}`;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.CliFormatter = CliFormatter;
|
|
@@ -12,8 +12,8 @@ export interface ContextFormatterOptions {
|
|
|
12
12
|
color: Chalk;
|
|
13
13
|
context: string;
|
|
14
14
|
}
|
|
15
|
-
export declare class
|
|
16
|
-
format(message: string, options?: ContextFormatterOptions): string;
|
|
15
|
+
export declare class NestFormatter implements FormatterContract {
|
|
17
16
|
private static lastTimestamp?;
|
|
18
17
|
private static getTimestampDiff;
|
|
18
|
+
format(message: string, options?: ContextFormatterOptions): string;
|
|
19
19
|
}
|
|
@@ -8,18 +8,10 @@
|
|
|
8
8
|
* file that was distributed with this source code.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.
|
|
11
|
+
exports.NestFormatter = void 0;
|
|
12
12
|
const Color_1 = require("../Utils/Color");
|
|
13
13
|
const getTimestamp_1 = require("../Utils/getTimestamp");
|
|
14
|
-
class
|
|
15
|
-
format(message, options) {
|
|
16
|
-
options = Object.assign({}, { color: Color_1.Color.green, context: 'Logger' }, options);
|
|
17
|
-
const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
|
|
18
|
-
const timestamp = getTimestamp_1.getTimestamp();
|
|
19
|
-
const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
|
|
20
|
-
const timestampDiff = ContextFormatter.getTimestampDiff();
|
|
21
|
-
return `${pid} - ${timestamp} ${messageCtx}${options.color(message)}${timestampDiff}`;
|
|
22
|
-
}
|
|
14
|
+
class NestFormatter {
|
|
23
15
|
static getTimestampDiff() {
|
|
24
16
|
let result = '';
|
|
25
17
|
if (this.lastTimestamp) {
|
|
@@ -28,5 +20,13 @@ class ContextFormatter {
|
|
|
28
20
|
this.lastTimestamp = Date.now();
|
|
29
21
|
return result;
|
|
30
22
|
}
|
|
23
|
+
format(message, options) {
|
|
24
|
+
options = Object.assign({}, { color: Color_1.Color.green, context: 'Logger' }, options);
|
|
25
|
+
const pid = Color_1.Color.yellow(`[Athenna] - PID: ${process.pid}`);
|
|
26
|
+
const timestamp = getTimestamp_1.getTimestamp();
|
|
27
|
+
const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
|
|
28
|
+
const timestampDiff = NestFormatter.getTimestampDiff();
|
|
29
|
+
return `${pid} - ${timestamp} ${messageCtx}${options.color(message)}${timestampDiff}`;
|
|
30
|
+
}
|
|
31
31
|
}
|
|
32
|
-
exports.
|
|
32
|
+
exports.NestFormatter = NestFormatter;
|
|
@@ -7,12 +7,15 @@
|
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
9
|
import { Chalk } from 'chalk';
|
|
10
|
+
import { LevelTypes } from '../Contracts/LevelTypes';
|
|
10
11
|
import { FormatterContract } from '../Contracts/FormatterContract';
|
|
11
12
|
export interface LogFormatterOptions {
|
|
12
13
|
color: Chalk;
|
|
13
|
-
level:
|
|
14
|
+
level: LevelTypes;
|
|
14
15
|
}
|
|
15
|
-
export declare class
|
|
16
|
-
|
|
16
|
+
export declare class SimpleFormatter implements FormatterContract {
|
|
17
|
+
private static lastTimestamp?;
|
|
18
|
+
private static getTimestampDiff;
|
|
17
19
|
private static paintByLevel;
|
|
20
|
+
format(message: string, options?: LogFormatterOptions): string;
|
|
18
21
|
}
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
* file that was distributed with this source code.
|
|
9
9
|
*/
|
|
10
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.
|
|
11
|
+
exports.SimpleFormatter = void 0;
|
|
12
12
|
const Color_1 = require("../Utils/Color");
|
|
13
13
|
const getTimestamp_1 = require("../Utils/getTimestamp");
|
|
14
|
-
class
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
class SimpleFormatter {
|
|
15
|
+
static getTimestampDiff() {
|
|
16
|
+
let result = '';
|
|
17
|
+
if (this.lastTimestamp) {
|
|
18
|
+
result = Color_1.Color.yellow(` +${Date.now() - this.lastTimestamp}ms`);
|
|
19
|
+
}
|
|
20
|
+
this.lastTimestamp = Date.now();
|
|
21
|
+
return result;
|
|
21
22
|
}
|
|
22
23
|
static paintByLevel(level) {
|
|
23
24
|
const levelColors = {
|
|
@@ -29,5 +30,12 @@ class LogFormatter {
|
|
|
29
30
|
};
|
|
30
31
|
return levelColors[level.toLowerCase()](`[${level}]`);
|
|
31
32
|
}
|
|
33
|
+
format(message, options) {
|
|
34
|
+
options = Object.assign({}, { color: Color_1.Color.green, level: 'info' }, options);
|
|
35
|
+
const timestamp = getTimestamp_1.getTimestamp();
|
|
36
|
+
const timestampDiff = SimpleFormatter.getTimestampDiff();
|
|
37
|
+
const level = SimpleFormatter.paintByLevel(options.level);
|
|
38
|
+
return `${level} - ${timestamp} ${options.color(message)}${timestampDiff}`;
|
|
39
|
+
}
|
|
32
40
|
}
|
|
33
|
-
exports.
|
|
41
|
+
exports.SimpleFormatter = SimpleFormatter;
|
package/src/Logger.d.ts
CHANGED
|
@@ -4,16 +4,18 @@ 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
|
+
private static applyLogEngine;
|
|
12
13
|
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?:
|
|
14
|
+
log(message: any, options?: {}): void | Promise<void>;
|
|
15
|
+
info(message: any, options?: {}): void | Promise<void>;
|
|
16
|
+
warn(message: any, options?: {}): void | Promise<void>;
|
|
17
|
+
error(message: any, options?: {}): void | Promise<void>;
|
|
18
|
+
debug(message: any, options?: {}): void | Promise<void>;
|
|
19
|
+
success(message: any, options?: {}): void | Promise<void>;
|
|
20
|
+
private createOptions;
|
|
19
21
|
}
|
package/src/Logger.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.Logger = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
4
8
|
const Color_1 = require("./Utils/Color");
|
|
5
9
|
const utils_1 = require("@secjs/utils");
|
|
6
10
|
const DriverFactory_1 = require("./Factories/DriverFactory");
|
|
@@ -12,17 +16,39 @@ class Logger {
|
|
|
12
16
|
this.channelName = 'default';
|
|
13
17
|
this.driver = DriverFactory_1.DriverFactory.fabricate(this.channelName, this.runtimeConfig);
|
|
14
18
|
}
|
|
19
|
+
static get drivers() {
|
|
20
|
+
return DriverFactory_1.DriverFactory.availableDrivers();
|
|
21
|
+
}
|
|
22
|
+
static get formatters() {
|
|
23
|
+
return FormatterFactory_1.FormatterFactory.availableFormatters();
|
|
24
|
+
}
|
|
15
25
|
static buildDriver(name, driver) {
|
|
16
26
|
DriverFactory_1.DriverFactory.createDriver(name, driver);
|
|
17
27
|
}
|
|
18
28
|
static buildFormatter(name, formatter) {
|
|
19
29
|
FormatterFactory_1.FormatterFactory.createFormatter(name, formatter);
|
|
20
30
|
}
|
|
21
|
-
static
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
static applyLogEngine(content) {
|
|
32
|
+
if (utils_1.Is.String(content)) {
|
|
33
|
+
const matches = content.match(/\({(.*?)} (.*?)\)/);
|
|
34
|
+
if (matches) {
|
|
35
|
+
const chalkMethodsString = matches[1].replace(/\s/g, '');
|
|
36
|
+
const chalkMethodsArray = chalkMethodsString.split(',');
|
|
37
|
+
const message = matches[2];
|
|
38
|
+
let chalk = chalk_1.default;
|
|
39
|
+
chalkMethodsArray.forEach(chalkMethod => {
|
|
40
|
+
if (!chalk[chalkMethod])
|
|
41
|
+
return;
|
|
42
|
+
chalk = chalk[chalkMethod];
|
|
43
|
+
});
|
|
44
|
+
content = content
|
|
45
|
+
.replace(`({${matches[1]}} `, '')
|
|
46
|
+
.replace(`({${matches[1]}}`, '')
|
|
47
|
+
.replace(`${matches[2]})`, chalk(message));
|
|
48
|
+
}
|
|
49
|
+
return content;
|
|
50
|
+
}
|
|
51
|
+
return content;
|
|
26
52
|
}
|
|
27
53
|
channel(channel, runtimeConfig) {
|
|
28
54
|
if (runtimeConfig)
|
|
@@ -30,80 +56,86 @@ class Logger {
|
|
|
30
56
|
this.driver = DriverFactory_1.DriverFactory.fabricate(channel, this.runtimeConfig);
|
|
31
57
|
return this;
|
|
32
58
|
}
|
|
33
|
-
|
|
34
|
-
options =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
await this.driver.transport(message, options);
|
|
59
|
+
log(message, options = {}) {
|
|
60
|
+
options = this.createOptions(options, {
|
|
61
|
+
streamType: 'stdout',
|
|
62
|
+
});
|
|
63
|
+
message = Logger.applyLogEngine(message);
|
|
64
|
+
return this.driver.transport(message, options);
|
|
42
65
|
}
|
|
43
|
-
|
|
44
|
-
options =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
await this.driver.transport(message, options);
|
|
66
|
+
info(message, options = {}) {
|
|
67
|
+
options = this.createOptions(options, {
|
|
68
|
+
streamType: 'stdout',
|
|
69
|
+
formatterConfig: {
|
|
70
|
+
level: 'INFO',
|
|
71
|
+
color: Color_1.Color.cyan,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
message = Logger.applyLogEngine(message);
|
|
75
|
+
return this.driver.transport(message, options);
|
|
55
76
|
}
|
|
56
|
-
|
|
57
|
-
options =
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
await this.driver.transport(message, options);
|
|
77
|
+
warn(message, options = {}) {
|
|
78
|
+
options = this.createOptions(options, {
|
|
79
|
+
streamType: 'stdout',
|
|
80
|
+
formatterConfig: {
|
|
81
|
+
level: 'WARN',
|
|
82
|
+
color: Color_1.Color.orange,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
message = Logger.applyLogEngine(message);
|
|
86
|
+
return this.driver.transport(message, options);
|
|
68
87
|
}
|
|
69
|
-
|
|
70
|
-
options =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
await this.driver.transport(message, options);
|
|
88
|
+
error(message, options = {}) {
|
|
89
|
+
options = this.createOptions(options, {
|
|
90
|
+
streamType: 'stdout',
|
|
91
|
+
formatterConfig: {
|
|
92
|
+
level: 'ERROR',
|
|
93
|
+
color: Color_1.Color.red,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
message = Logger.applyLogEngine(message);
|
|
97
|
+
return this.driver.transport(message, options);
|
|
81
98
|
}
|
|
82
|
-
|
|
83
|
-
options =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
debug(message, options = {}) {
|
|
100
|
+
options = this.createOptions(options, {
|
|
101
|
+
streamType: 'stdout',
|
|
102
|
+
formatterConfig: {
|
|
103
|
+
level: 'DEBUG',
|
|
104
|
+
color: Color_1.Color.purple,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
message = Logger.applyLogEngine(message);
|
|
108
|
+
return this.driver.transport(message, options);
|
|
109
|
+
}
|
|
110
|
+
success(message, options = {}) {
|
|
111
|
+
options = this.createOptions(options, {
|
|
112
|
+
streamType: 'stdout',
|
|
113
|
+
formatterConfig: {
|
|
114
|
+
level: 'SUCCESS',
|
|
115
|
+
color: Color_1.Color.green,
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
message = Logger.applyLogEngine(message);
|
|
119
|
+
return this.driver.transport(message, options);
|
|
94
120
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
options.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
options = {
|
|
102
|
-
...options,
|
|
121
|
+
createOptions(options, defaultValues) {
|
|
122
|
+
let formatterConfig = Object.assign({}, {
|
|
123
|
+
...defaultValues.formatterConfig,
|
|
124
|
+
}, options.formatterConfig);
|
|
125
|
+
if (this.runtimeConfig.formatterConfig) {
|
|
126
|
+
formatterConfig = {
|
|
103
127
|
...this.runtimeConfig.formatterConfig,
|
|
128
|
+
...formatterConfig,
|
|
104
129
|
};
|
|
105
130
|
}
|
|
106
|
-
|
|
131
|
+
options = Object.assign({}, {
|
|
132
|
+
streamType: 'stdout',
|
|
133
|
+
}, options);
|
|
134
|
+
options = {
|
|
135
|
+
...options,
|
|
136
|
+
formatterConfig,
|
|
137
|
+
};
|
|
138
|
+
return options;
|
|
107
139
|
}
|
|
108
140
|
}
|
|
109
141
|
exports.Logger = Logger;
|
package/src/Utils/Color.d.ts
CHANGED
|
@@ -6,11 +6,19 @@
|
|
|
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 { Chalk } from 'chalk';
|
|
9
|
+
import chalk, { Chalk } from 'chalk';
|
|
10
10
|
declare type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
11
11
|
export declare class Color {
|
|
12
|
-
static chalk: Chalk & {
|
|
13
|
-
supportsColor:
|
|
12
|
+
static chalk: chalk.Chalk & chalk.ChalkFunction & {
|
|
13
|
+
supportsColor: false | chalk.ColorSupport;
|
|
14
|
+
Level: chalk.Level;
|
|
15
|
+
Color: ("black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright") | ("bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright");
|
|
16
|
+
ForegroundColor: "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white" | "gray" | "grey" | "blackBright" | "redBright" | "greenBright" | "yellowBright" | "blueBright" | "magentaBright" | "cyanBright" | "whiteBright";
|
|
17
|
+
BackgroundColor: "bgBlack" | "bgRed" | "bgGreen" | "bgYellow" | "bgBlue" | "bgMagenta" | "bgCyan" | "bgWhite" | "bgGray" | "bgGrey" | "bgBlackBright" | "bgRedBright" | "bgGreenBright" | "bgYellowBright" | "bgBlueBright" | "bgMagentaBright" | "bgCyanBright" | "bgWhiteBright";
|
|
18
|
+
Modifiers: "reset" | "bold" | "dim" | "italic" | "underline" | "inverse" | "hidden" | "strikethrough" | "visible";
|
|
19
|
+
stderr: chalk.Chalk & {
|
|
20
|
+
supportsColor: false | chalk.ColorSupport;
|
|
21
|
+
};
|
|
14
22
|
};
|
|
15
23
|
static get bold(): Chalk;
|
|
16
24
|
static get purple(): Chalk;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @athenna/logger
|
|
4
|
-
*
|
|
5
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.DebugFormatter = void 0;
|
|
12
|
-
const Color_1 = require("../Utils/Color");
|
|
13
|
-
const getTimestamp_1 = require("../Utils/getTimestamp");
|
|
14
|
-
class DebugFormatter {
|
|
15
|
-
format(message, options) {
|
|
16
|
-
options = Object.assign({}, { color: Color_1.Color.green, context: 'Debugger', namespace: 'api:main' }, options);
|
|
17
|
-
const pid = Color_1.Color.yellow(`[Athenna Debugger] - PID: ${process.pid}`);
|
|
18
|
-
const timestamp = Color_1.Color.white(getTimestamp_1.getTimestamp());
|
|
19
|
-
const messageCtx = Color_1.Color.yellow(`[${options.context}] `);
|
|
20
|
-
const timestampDiff = DebugFormatter.getTimestampDiff();
|
|
21
|
-
return `${pid} - ${timestamp} ${messageCtx}${options.color(message)}${timestampDiff}`;
|
|
22
|
-
}
|
|
23
|
-
static getTimestampDiff() {
|
|
24
|
-
let result = '';
|
|
25
|
-
if (this.lastTimestamp) {
|
|
26
|
-
result = Color_1.Color.yellow(` +${Date.now() - this.lastTimestamp}ms`);
|
|
27
|
-
}
|
|
28
|
-
this.lastTimestamp = Date.now();
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.DebugFormatter = DebugFormatter;
|