@athenna/logger 3.1.0 → 3.1.1
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/build/Formatters/Formatter.js +13 -14
- package/build/Formatters/RequestFormatter.js +5 -2
- package/build/Logger/Logger.js +2 -2
- package/build/Logger/VanillaLogger.d.ts +5 -0
- package/build/Logger/VanillaLogger.js +9 -2
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -1
- package/package.json +6 -7
- package/build/Helpers/ColorHelper.d.ts +0 -131
- package/build/Helpers/ColorHelper.js +0 -215
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import rTracer from 'cls-rtracer';
|
|
10
10
|
import { hostname } from 'node:os';
|
|
11
|
-
import { Is } from '@athenna/common';
|
|
12
|
-
import { ColorHelper } from '#src/Helpers/ColorHelper';
|
|
11
|
+
import { Is, Color } from '@athenna/common';
|
|
13
12
|
export class Formatter {
|
|
14
13
|
/**
|
|
15
14
|
* Holds the configuration object of formatter.
|
|
@@ -80,7 +79,7 @@ export class Formatter {
|
|
|
80
79
|
*/
|
|
81
80
|
clean(message, force = false) {
|
|
82
81
|
if (this.configs.clean || force) {
|
|
83
|
-
return
|
|
82
|
+
return Color.removeColors(message);
|
|
84
83
|
}
|
|
85
84
|
return message;
|
|
86
85
|
}
|
|
@@ -112,20 +111,20 @@ export class Formatter {
|
|
|
112
111
|
*/
|
|
113
112
|
cliLevel() {
|
|
114
113
|
const level = this.configs.level;
|
|
115
|
-
if (!
|
|
114
|
+
if (!Color[level]) {
|
|
116
115
|
return level;
|
|
117
116
|
}
|
|
118
|
-
return
|
|
117
|
+
return Color[level].bold(`[ ${level} ]`);
|
|
119
118
|
}
|
|
120
119
|
/**
|
|
121
120
|
* Create the simple level string.
|
|
122
121
|
*/
|
|
123
122
|
simpleLevel() {
|
|
124
123
|
const level = this.configs.level;
|
|
125
|
-
if (!
|
|
124
|
+
if (!Color[level]) {
|
|
126
125
|
return level;
|
|
127
126
|
}
|
|
128
|
-
return
|
|
127
|
+
return Color[level].bold(`[${level.toUpperCase()}]`);
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
130
|
* Create the message level emoji string.
|
|
@@ -161,13 +160,13 @@ export class Formatter {
|
|
|
161
160
|
paintMessageByLevel(level, message) {
|
|
162
161
|
const levelLower = level.toLowerCase();
|
|
163
162
|
const levelColors = {
|
|
164
|
-
trace:
|
|
165
|
-
debug:
|
|
166
|
-
info:
|
|
167
|
-
success:
|
|
168
|
-
warn:
|
|
169
|
-
error:
|
|
170
|
-
fatal:
|
|
163
|
+
trace: Color.trace,
|
|
164
|
+
debug: Color.debug,
|
|
165
|
+
info: Color.info,
|
|
166
|
+
success: Color.success,
|
|
167
|
+
warn: Color.warn,
|
|
168
|
+
error: Color.error,
|
|
169
|
+
fatal: Color.fatal,
|
|
171
170
|
};
|
|
172
171
|
if (!levelColors[levelLower]) {
|
|
173
172
|
return message;
|
|
@@ -6,14 +6,17 @@
|
|
|
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 {
|
|
9
|
+
import { Color, Is } from '@athenna/common';
|
|
10
10
|
import { Formatter } from '#src/Formatters/Formatter';
|
|
11
11
|
export class RequestFormatter extends Formatter {
|
|
12
12
|
format(ctx) {
|
|
13
|
+
if (Is.String(ctx)) {
|
|
14
|
+
return ctx;
|
|
15
|
+
}
|
|
13
16
|
const ip = ctx.request.ip;
|
|
14
17
|
const status = ctx.status;
|
|
15
18
|
const responseTimeMs = `${Math.round(ctx.responseTime)}ms`;
|
|
16
|
-
const methodAndStatus =
|
|
19
|
+
const methodAndStatus = Color[ctx.request.method](`[${ctx.request.method}::${ctx.status}]`);
|
|
17
20
|
if (!this.configs.asJson) {
|
|
18
21
|
return this.clean(`${methodAndStatus} - [${ip}] - ${new Date().toISOString()} - ${ctx.request.baseUrl} ${responseTimeMs}`);
|
|
19
22
|
}
|
package/build/Logger/Logger.js
CHANGED
|
@@ -6,8 +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 { Color } from '@athenna/common';
|
|
9
10
|
import { Config } from '@athenna/config';
|
|
10
|
-
import { ColorHelper } from '#src/Helpers/ColorHelper';
|
|
11
11
|
import { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
12
12
|
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
13
13
|
export class Logger {
|
|
@@ -47,7 +47,7 @@ export class Logger {
|
|
|
47
47
|
* Call drivers to transport the log.
|
|
48
48
|
*/
|
|
49
49
|
async log(level, ...args) {
|
|
50
|
-
const message =
|
|
50
|
+
const message = Color.apply(...args);
|
|
51
51
|
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
52
52
|
return Promise.all(promises);
|
|
53
53
|
}
|
|
@@ -12,6 +12,11 @@ export declare class VanillaLogger {
|
|
|
12
12
|
*/
|
|
13
13
|
drivers: any[];
|
|
14
14
|
constructor(configs: any);
|
|
15
|
+
/**
|
|
16
|
+
* Log a simple log message without using the log driver
|
|
17
|
+
* but using the Color engine.
|
|
18
|
+
*/
|
|
19
|
+
simple(...args: any[]): void;
|
|
15
20
|
/**
|
|
16
21
|
* Set runtime configurations for drivers and
|
|
17
22
|
* formatters.
|
|
@@ -6,7 +6,7 @@
|
|
|
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 {
|
|
9
|
+
import { Color } from '@athenna/common';
|
|
10
10
|
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
11
11
|
export class VanillaLogger {
|
|
12
12
|
/**
|
|
@@ -16,6 +16,13 @@ export class VanillaLogger {
|
|
|
16
16
|
constructor(configs) {
|
|
17
17
|
this.drivers.push(DriverFactory.fabricateVanilla(configs));
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Log a simple log message without using the log driver
|
|
21
|
+
* but using the Color engine.
|
|
22
|
+
*/
|
|
23
|
+
simple(...args) {
|
|
24
|
+
process.stdout.write(Color.apply(...args).concat('\n'));
|
|
25
|
+
}
|
|
19
26
|
/**
|
|
20
27
|
* Set runtime configurations for drivers and
|
|
21
28
|
* formatters.
|
|
@@ -37,7 +44,7 @@ export class VanillaLogger {
|
|
|
37
44
|
* @return {any | Promise<any>}
|
|
38
45
|
*/
|
|
39
46
|
log(level, ...args) {
|
|
40
|
-
const message =
|
|
47
|
+
const message = Color.apply(...args);
|
|
41
48
|
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
42
49
|
return Promise.all(promises);
|
|
43
50
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
export * from './Facades/Log.js';
|
|
10
10
|
export * from './Logger/Logger.js';
|
|
11
11
|
export * from './Drivers/Driver.js';
|
|
12
|
-
export * from './Helpers/ColorHelper.js';
|
|
13
12
|
export * from './Formatters/Formatter.js';
|
|
14
13
|
export * from './Logger/VanillaLogger.js';
|
|
15
14
|
export * from './Helpers/FactoryHelper.js';
|
package/build/index.js
CHANGED
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
export * from './Facades/Log.js';
|
|
10
10
|
export * from './Logger/Logger.js';
|
|
11
11
|
export * from './Drivers/Driver.js';
|
|
12
|
-
export * from './Helpers/ColorHelper.js';
|
|
13
12
|
export * from './Formatters/Formatter.js';
|
|
14
13
|
export * from './Logger/VanillaLogger.js';
|
|
15
14
|
export * from './Helpers/FactoryHelper.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "The Athenna logging solution. Log in stdout, files and buckets.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "João Lenon <lenon@athenna.io>",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"telegram",
|
|
14
14
|
"console",
|
|
15
15
|
"debug",
|
|
16
|
-
"pino",
|
|
17
16
|
"buckets",
|
|
18
17
|
"logger",
|
|
19
18
|
"drivers",
|
|
@@ -22,10 +21,10 @@
|
|
|
22
21
|
"esm"
|
|
23
22
|
],
|
|
24
23
|
"scripts": {
|
|
25
|
-
"build": "
|
|
24
|
+
"build": "ts-node bin/build.ts",
|
|
26
25
|
"lint:fix": "eslint \"{src,tests}/**/*.ts\" --fix",
|
|
27
|
-
"test": "npm run --silent lint:fix && ts-node
|
|
28
|
-
"test:debug": "cross-env DEBUG=api:* ts-node
|
|
26
|
+
"test": "npm run --silent lint:fix && ts-node bin/test.ts",
|
|
27
|
+
"test:debug": "cross-env DEBUG=api:* ts-node bin/test.ts --inspect",
|
|
29
28
|
"test:coverage": "c8 npm run --silent test"
|
|
30
29
|
},
|
|
31
30
|
"files": [
|
|
@@ -49,7 +48,6 @@
|
|
|
49
48
|
"./providers/LoggerProvider": "./build/Providers/LoggerProvider.js"
|
|
50
49
|
},
|
|
51
50
|
"dependencies": {
|
|
52
|
-
"chalk": "^5.2.0",
|
|
53
51
|
"telegraf": "^4.11.2"
|
|
54
52
|
},
|
|
55
53
|
"devDependencies": {
|
|
@@ -153,7 +151,8 @@
|
|
|
153
151
|
"ioc": true,
|
|
154
152
|
"Env": true,
|
|
155
153
|
"Path": true,
|
|
156
|
-
"Config": true
|
|
154
|
+
"Config": true,
|
|
155
|
+
"container": true
|
|
157
156
|
},
|
|
158
157
|
"plugins": [
|
|
159
158
|
"prettier",
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/logger
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { ChalkInstance } from 'chalk';
|
|
10
|
-
export declare class ColorHelper {
|
|
11
|
-
/**
|
|
12
|
-
* Chalk instance.
|
|
13
|
-
*/
|
|
14
|
-
static chalk: ChalkInstance;
|
|
15
|
-
/**
|
|
16
|
-
* Paint as bold.
|
|
17
|
-
*/
|
|
18
|
-
static get bold(): ChalkInstance;
|
|
19
|
-
/**
|
|
20
|
-
* Paint as grey.
|
|
21
|
-
*/
|
|
22
|
-
static get grey(): ChalkInstance;
|
|
23
|
-
/**
|
|
24
|
-
* Paint as purple.
|
|
25
|
-
*/
|
|
26
|
-
static get purple(): ChalkInstance;
|
|
27
|
-
/**
|
|
28
|
-
* Paint as darkPurple.
|
|
29
|
-
*/
|
|
30
|
-
static get darkPurple(): ChalkInstance;
|
|
31
|
-
/**
|
|
32
|
-
* Paint as yellow.
|
|
33
|
-
*/
|
|
34
|
-
static get yellow(): ChalkInstance;
|
|
35
|
-
/**
|
|
36
|
-
* Paint as cyan.
|
|
37
|
-
*/
|
|
38
|
-
static get cyan(): ChalkInstance;
|
|
39
|
-
/**
|
|
40
|
-
* Paint as white.
|
|
41
|
-
*/
|
|
42
|
-
static get white(): ChalkInstance;
|
|
43
|
-
/**
|
|
44
|
-
* Paint as orange.
|
|
45
|
-
*/
|
|
46
|
-
static get orange(): ChalkInstance;
|
|
47
|
-
/**
|
|
48
|
-
* Paint as green.
|
|
49
|
-
*/
|
|
50
|
-
static get green(): ChalkInstance;
|
|
51
|
-
/**
|
|
52
|
-
* Paint as darkGreen.
|
|
53
|
-
*/
|
|
54
|
-
static get darkGreen(): ChalkInstance;
|
|
55
|
-
/**
|
|
56
|
-
* Paint as red.
|
|
57
|
-
*/
|
|
58
|
-
static get red(): ChalkInstance;
|
|
59
|
-
/**
|
|
60
|
-
* Paint as darkRed.
|
|
61
|
-
*/
|
|
62
|
-
static get darkRed(): ChalkInstance;
|
|
63
|
-
/**
|
|
64
|
-
* Paint debugs.
|
|
65
|
-
*/
|
|
66
|
-
static get trace(): ChalkInstance;
|
|
67
|
-
/**
|
|
68
|
-
* Paint debugs.
|
|
69
|
-
*/
|
|
70
|
-
static get debug(): ChalkInstance;
|
|
71
|
-
/**
|
|
72
|
-
* Paint infos.
|
|
73
|
-
*/
|
|
74
|
-
static get info(): ChalkInstance;
|
|
75
|
-
/**
|
|
76
|
-
* Paint success.
|
|
77
|
-
*/
|
|
78
|
-
static get success(): ChalkInstance;
|
|
79
|
-
/**
|
|
80
|
-
* Paint warning.
|
|
81
|
-
*/
|
|
82
|
-
static get warn(): ChalkInstance;
|
|
83
|
-
/**
|
|
84
|
-
* Paint error.
|
|
85
|
-
*/
|
|
86
|
-
static get error(): ChalkInstance;
|
|
87
|
-
/**
|
|
88
|
-
* Paint fatal.
|
|
89
|
-
*/
|
|
90
|
-
static get fatal(): ChalkInstance;
|
|
91
|
-
/**
|
|
92
|
-
* Paint http method.
|
|
93
|
-
*/
|
|
94
|
-
static get GET(): ChalkInstance;
|
|
95
|
-
/**
|
|
96
|
-
* Paint http method.
|
|
97
|
-
*/
|
|
98
|
-
static get HEAD(): ChalkInstance;
|
|
99
|
-
/**
|
|
100
|
-
* Paint http method.
|
|
101
|
-
*/
|
|
102
|
-
static get PUT(): ChalkInstance;
|
|
103
|
-
/**
|
|
104
|
-
* Paint http method.
|
|
105
|
-
*/
|
|
106
|
-
static get PATCH(): ChalkInstance;
|
|
107
|
-
/**
|
|
108
|
-
* Paint http method.
|
|
109
|
-
*/
|
|
110
|
-
static get POST(): ChalkInstance;
|
|
111
|
-
/**
|
|
112
|
-
* Paint http method.
|
|
113
|
-
*/
|
|
114
|
-
static get DELETE(): ChalkInstance;
|
|
115
|
-
/**
|
|
116
|
-
* Paint http method.
|
|
117
|
-
*/
|
|
118
|
-
static get OPTIONS(): ChalkInstance;
|
|
119
|
-
/**
|
|
120
|
-
* Remove all colors and special chars of string.
|
|
121
|
-
*/
|
|
122
|
-
static removeColors(value: string): string;
|
|
123
|
-
/**
|
|
124
|
-
* Paint by the http method.
|
|
125
|
-
*/
|
|
126
|
-
static httpMethod(method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD'): ChalkInstance;
|
|
127
|
-
/**
|
|
128
|
-
* Applies the log engine to execute chalk methods.
|
|
129
|
-
*/
|
|
130
|
-
static applyLogEngine(...args: string[]): any;
|
|
131
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @athenna/logger
|
|
3
|
-
*
|
|
4
|
-
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
-
*
|
|
6
|
-
* For the full copyright and license information, please view the LICENSE
|
|
7
|
-
* file that was distributed with this source code.
|
|
8
|
-
*/
|
|
9
|
-
import { format } from 'node:util';
|
|
10
|
-
import { Is } from '@athenna/common';
|
|
11
|
-
import { Chalk } from 'chalk';
|
|
12
|
-
export class ColorHelper {
|
|
13
|
-
/**
|
|
14
|
-
* Chalk instance.
|
|
15
|
-
*/
|
|
16
|
-
static chalk = new Chalk();
|
|
17
|
-
/**
|
|
18
|
-
* Paint as bold.
|
|
19
|
-
*/
|
|
20
|
-
static get bold() {
|
|
21
|
-
return ColorHelper.chalk.bold;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Paint as grey.
|
|
25
|
-
*/
|
|
26
|
-
static get grey() {
|
|
27
|
-
return ColorHelper.chalk.hex('#505050');
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Paint as purple.
|
|
31
|
-
*/
|
|
32
|
-
static get purple() {
|
|
33
|
-
return ColorHelper.chalk.hex('#7628c8');
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Paint as darkPurple.
|
|
37
|
-
*/
|
|
38
|
-
static get darkPurple() {
|
|
39
|
-
return ColorHelper.chalk.hex('#501b86');
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Paint as yellow.
|
|
43
|
-
*/
|
|
44
|
-
static get yellow() {
|
|
45
|
-
return ColorHelper.chalk.hex('#ffe600');
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Paint as cyan.
|
|
49
|
-
*/
|
|
50
|
-
static get cyan() {
|
|
51
|
-
return ColorHelper.chalk.hex('#00ffff');
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Paint as white.
|
|
55
|
-
*/
|
|
56
|
-
static get white() {
|
|
57
|
-
return ColorHelper.chalk.hex('#ffffff');
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Paint as orange.
|
|
61
|
-
*/
|
|
62
|
-
static get orange() {
|
|
63
|
-
return ColorHelper.chalk.hex('#f18b0e');
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Paint as green.
|
|
67
|
-
*/
|
|
68
|
-
static get green() {
|
|
69
|
-
return ColorHelper.chalk.hex('#0ef12c');
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Paint as darkGreen.
|
|
73
|
-
*/
|
|
74
|
-
static get darkGreen() {
|
|
75
|
-
return ColorHelper.chalk.hex('#1cb70b');
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Paint as red.
|
|
79
|
-
*/
|
|
80
|
-
static get red() {
|
|
81
|
-
return ColorHelper.chalk.hex('#f10e0e');
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Paint as darkRed.
|
|
85
|
-
*/
|
|
86
|
-
static get darkRed() {
|
|
87
|
-
return ColorHelper.chalk.hex('#710909');
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Paint debugs.
|
|
91
|
-
*/
|
|
92
|
-
static get trace() {
|
|
93
|
-
return this.grey.bold;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Paint debugs.
|
|
97
|
-
*/
|
|
98
|
-
static get debug() {
|
|
99
|
-
return this.purple.bold;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Paint infos.
|
|
103
|
-
*/
|
|
104
|
-
static get info() {
|
|
105
|
-
return this.cyan;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Paint success.
|
|
109
|
-
*/
|
|
110
|
-
static get success() {
|
|
111
|
-
return this.green;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Paint warning.
|
|
115
|
-
*/
|
|
116
|
-
static get warn() {
|
|
117
|
-
return this.orange;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Paint error.
|
|
121
|
-
*/
|
|
122
|
-
static get error() {
|
|
123
|
-
return this.red;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Paint fatal.
|
|
127
|
-
*/
|
|
128
|
-
static get fatal() {
|
|
129
|
-
return ColorHelper.chalk.bgRed;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Paint http method.
|
|
133
|
-
*/
|
|
134
|
-
static get GET() {
|
|
135
|
-
return this.purple.bold;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Paint http method.
|
|
139
|
-
*/
|
|
140
|
-
static get HEAD() {
|
|
141
|
-
return this.cyan.bold;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Paint http method.
|
|
145
|
-
*/
|
|
146
|
-
static get PUT() {
|
|
147
|
-
return this.orange.bold;
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* Paint http method.
|
|
151
|
-
*/
|
|
152
|
-
static get PATCH() {
|
|
153
|
-
return this.yellow.bold;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Paint http method.
|
|
157
|
-
*/
|
|
158
|
-
static get POST() {
|
|
159
|
-
return this.green.bold;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Paint http method.
|
|
163
|
-
*/
|
|
164
|
-
static get DELETE() {
|
|
165
|
-
return this.red.bold;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Paint http method.
|
|
169
|
-
*/
|
|
170
|
-
static get OPTIONS() {
|
|
171
|
-
return this.cyan.bold;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Remove all colors and special chars of string.
|
|
175
|
-
*/
|
|
176
|
-
static removeColors(value) {
|
|
177
|
-
return ColorHelper.chalk.reset(value).replace(
|
|
178
|
-
// eslint-disable-next-line no-control-regex
|
|
179
|
-
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Paint by the http method.
|
|
183
|
-
*/
|
|
184
|
-
static httpMethod(method) {
|
|
185
|
-
return this[method];
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Applies the log engine to execute chalk methods.
|
|
189
|
-
*/
|
|
190
|
-
static applyLogEngine(...args) {
|
|
191
|
-
if (!Is.String(args[0])) {
|
|
192
|
-
return args[0];
|
|
193
|
-
}
|
|
194
|
-
let content = format(...args.filter(arg => arg !== undefined));
|
|
195
|
-
const matches = content.match(/\({(.*?)} ([\s\S]*?)\)/g);
|
|
196
|
-
if (!matches) {
|
|
197
|
-
return content;
|
|
198
|
-
}
|
|
199
|
-
matches.forEach(match => {
|
|
200
|
-
const [chalkMethodsInBrackets, chalkMethodsString] = match.match(/\{(.*?)\}/);
|
|
201
|
-
const message = match
|
|
202
|
-
.replace(chalkMethodsInBrackets, '')
|
|
203
|
-
.replace(/\s*\(\s*|\s*\)\s*/g, '');
|
|
204
|
-
const chalkMethodsArray = chalkMethodsString.replace(/\s/g, '').split(',');
|
|
205
|
-
let chalk = new Chalk();
|
|
206
|
-
chalkMethodsArray.forEach(chalkMethod => {
|
|
207
|
-
if (!chalk[chalkMethod])
|
|
208
|
-
return;
|
|
209
|
-
chalk = chalk[chalkMethod];
|
|
210
|
-
});
|
|
211
|
-
content = content.replace(match, chalk(message));
|
|
212
|
-
});
|
|
213
|
-
return content;
|
|
214
|
-
}
|
|
215
|
-
}
|