@athenna/logger 3.1.0 → 3.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/build/Constants/VanillaChannels.d.ts +42 -0
- package/build/Constants/VanillaChannels.js +42 -0
- package/build/Exceptions/NotImplementedConfigException.d.ts +1 -1
- package/build/Exceptions/NotImplementedConfigException.js +4 -3
- package/build/Factories/DriverFactory.js +1 -1
- package/build/Formatters/Formatter.js +15 -16
- package/build/Formatters/NoneFormatter.js +1 -1
- package/build/Formatters/RequestFormatter.js +5 -2
- package/build/Logger/Logger.d.ts +25 -10
- package/build/Logger/Logger.js +57 -19
- package/build/index.d.ts +0 -2
- package/build/index.js +0 -2
- package/package.json +6 -7
- package/build/Helpers/ColorHelper.d.ts +0 -131
- package/build/Helpers/ColorHelper.js +0 -215
- package/build/Logger/VanillaLogger.d.ts +0 -60
- package/build/Logger/VanillaLogger.js +0 -86
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Athenna default vanilla channels. This configurations
|
|
11
|
+
* will be used by the "channelOrVanilla" method. If the
|
|
12
|
+
* configuration does not exist, than the vanilla will be set.
|
|
13
|
+
*/
|
|
14
|
+
export declare const VANILLA_CHANNELS: {
|
|
15
|
+
default: {
|
|
16
|
+
driver: string;
|
|
17
|
+
channels: string[];
|
|
18
|
+
};
|
|
19
|
+
stack: {
|
|
20
|
+
driver: string;
|
|
21
|
+
channels: string[];
|
|
22
|
+
};
|
|
23
|
+
discard: {
|
|
24
|
+
driver: string;
|
|
25
|
+
};
|
|
26
|
+
console: {
|
|
27
|
+
level: string;
|
|
28
|
+
formatter: string;
|
|
29
|
+
driver: string;
|
|
30
|
+
};
|
|
31
|
+
exception: {
|
|
32
|
+
level: string;
|
|
33
|
+
formatter: string;
|
|
34
|
+
driver: string;
|
|
35
|
+
streamType: string;
|
|
36
|
+
};
|
|
37
|
+
application: {
|
|
38
|
+
level: string;
|
|
39
|
+
driver: string;
|
|
40
|
+
formatter: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
/**
|
|
10
|
+
* Athenna default vanilla channels. This configurations
|
|
11
|
+
* will be used by the "channelOrVanilla" method. If the
|
|
12
|
+
* configuration does not exist, than the vanilla will be set.
|
|
13
|
+
*/
|
|
14
|
+
export const VANILLA_CHANNELS = {
|
|
15
|
+
default: {
|
|
16
|
+
driver: 'stack',
|
|
17
|
+
channels: ['application'],
|
|
18
|
+
},
|
|
19
|
+
stack: {
|
|
20
|
+
driver: 'stack',
|
|
21
|
+
channels: ['application'],
|
|
22
|
+
},
|
|
23
|
+
discard: {
|
|
24
|
+
driver: 'null',
|
|
25
|
+
},
|
|
26
|
+
console: {
|
|
27
|
+
level: 'trace',
|
|
28
|
+
formatter: 'cli',
|
|
29
|
+
driver: 'console',
|
|
30
|
+
},
|
|
31
|
+
exception: {
|
|
32
|
+
level: 'trace',
|
|
33
|
+
formatter: 'none',
|
|
34
|
+
driver: 'console',
|
|
35
|
+
streamType: 'stderr',
|
|
36
|
+
},
|
|
37
|
+
application: {
|
|
38
|
+
level: 'trace',
|
|
39
|
+
driver: 'console',
|
|
40
|
+
formatter: 'simple',
|
|
41
|
+
},
|
|
42
|
+
};
|
|
@@ -6,11 +6,12 @@
|
|
|
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 { Path, Exception } from '@athenna/common';
|
|
9
|
+
import { Path, Exception, Is } from '@athenna/common';
|
|
10
10
|
export class NotImplementedConfigException extends Exception {
|
|
11
|
-
constructor(channelName
|
|
11
|
+
constructor(channelName) {
|
|
12
12
|
let help = '';
|
|
13
|
-
|
|
13
|
+
const channels = Config.get('logging.channels');
|
|
14
|
+
if (channels && !Is.Empty(channels)) {
|
|
14
15
|
const availableConfigs = Object.keys(channels).join(', ');
|
|
15
16
|
help += `Available configurations are: ${availableConfigs}.`;
|
|
16
17
|
}
|
|
@@ -79,7 +79,7 @@ export class DriverFactory {
|
|
|
79
79
|
*/
|
|
80
80
|
static getChannelConfig(channelName) {
|
|
81
81
|
if (channelName === 'default') {
|
|
82
|
-
channelName = Config.get('logging.default'
|
|
82
|
+
channelName = Config.get('logging.default', channelName);
|
|
83
83
|
}
|
|
84
84
|
const channelConfig = Config.get(`logging.channels.${channelName}`);
|
|
85
85
|
if (!channelConfig) {
|
|
@@ -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 (!
|
|
116
|
-
return level;
|
|
114
|
+
if (!Color[level]) {
|
|
115
|
+
return Color.bold(`[ ${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 (!
|
|
126
|
-
return level;
|
|
124
|
+
if (!Color[level]) {
|
|
125
|
+
return Color.bold(`[${level.toUpperCase()}]`);
|
|
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.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
|
-
import { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
10
9
|
export declare class Logger {
|
|
11
10
|
/**
|
|
12
11
|
* The drivers responsible for transporting the logs.
|
|
@@ -17,19 +16,38 @@ export declare class Logger {
|
|
|
17
16
|
*/
|
|
18
17
|
private runtimeConfigs;
|
|
19
18
|
constructor();
|
|
19
|
+
/**
|
|
20
|
+
* Create a new standalone logger instance. Very
|
|
21
|
+
* useful to create new loggers without changing the
|
|
22
|
+
* channels that are already defined in the main instance.
|
|
23
|
+
*/
|
|
24
|
+
static standalone(...configs: any[]): Logger;
|
|
20
25
|
/**
|
|
21
26
|
* Set runtime configurations for drivers and
|
|
22
27
|
* formatters.
|
|
23
28
|
*/
|
|
24
|
-
config(runtimeConfigs: any):
|
|
29
|
+
config(runtimeConfigs: any): Logger;
|
|
25
30
|
/**
|
|
26
31
|
* Change the log channel.
|
|
27
32
|
*/
|
|
28
|
-
channel(...channels: string[]):
|
|
33
|
+
channel(...channels: string[]): Logger;
|
|
29
34
|
/**
|
|
30
|
-
*
|
|
35
|
+
* Change the log drivers using vanilla configurations.
|
|
36
|
+
* This method does not depend in Athenna configuration
|
|
37
|
+
* files to be executed.
|
|
31
38
|
*/
|
|
32
|
-
|
|
39
|
+
vanilla(...configs: any[]): Logger;
|
|
40
|
+
/**
|
|
41
|
+
* Verify if channel configuration exists. If not, Athenna will
|
|
42
|
+
* use the default vanilla configurations as drivers.
|
|
43
|
+
*/
|
|
44
|
+
channelOrVanilla(channel: string, configs?: {}): Logger;
|
|
45
|
+
/**
|
|
46
|
+
* Create a new standalone logger instance. Very
|
|
47
|
+
* useful to create new loggers without changing the
|
|
48
|
+
* channels that are already defined in the main instance.
|
|
49
|
+
*/
|
|
50
|
+
standalone(...configs: any[]): Logger;
|
|
33
51
|
/**
|
|
34
52
|
* Creates a log of type trace in channel.
|
|
35
53
|
*/
|
|
@@ -59,10 +77,7 @@ export declare class Logger {
|
|
|
59
77
|
*/
|
|
60
78
|
fatal(...args: any[]): any | Promise<any>;
|
|
61
79
|
/**
|
|
62
|
-
*
|
|
63
|
-
* with vanilla configurations. By default,
|
|
64
|
-
* vanilla logger will use the "console" driver
|
|
65
|
-
* and "none" formatter.
|
|
80
|
+
* Call drivers to transport the log.
|
|
66
81
|
*/
|
|
67
|
-
|
|
82
|
+
private log;
|
|
68
83
|
}
|
package/build/Logger/Logger.js
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
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
|
-
import { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
12
11
|
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
12
|
+
import { VANILLA_CHANNELS } from '../Constants/VanillaChannels.js';
|
|
13
13
|
export class Logger {
|
|
14
14
|
/**
|
|
15
15
|
* The drivers responsible for transporting the logs.
|
|
@@ -20,10 +20,17 @@ export class Logger {
|
|
|
20
20
|
*/
|
|
21
21
|
runtimeConfigs = {};
|
|
22
22
|
constructor() {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
this.channelOrVanilla(Config.get('logging.default'));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a new standalone logger instance. Very
|
|
27
|
+
* useful to create new loggers without changing the
|
|
28
|
+
* channels that are already defined in the main instance.
|
|
29
|
+
*/
|
|
30
|
+
static standalone(...configs) {
|
|
31
|
+
const logger = new Logger();
|
|
32
|
+
logger.vanilla(...configs);
|
|
33
|
+
return logger;
|
|
27
34
|
}
|
|
28
35
|
/**
|
|
29
36
|
* Set runtime configurations for drivers and
|
|
@@ -38,18 +45,50 @@ export class Logger {
|
|
|
38
45
|
*/
|
|
39
46
|
channel(...channels) {
|
|
40
47
|
this.drivers = [];
|
|
41
|
-
channels.forEach(
|
|
42
|
-
this.drivers.push(DriverFactory.fabricate(
|
|
48
|
+
channels.forEach(channel => {
|
|
49
|
+
this.drivers.push(DriverFactory.fabricate(channel, this.runtimeConfigs));
|
|
43
50
|
});
|
|
44
51
|
return this;
|
|
45
52
|
}
|
|
46
53
|
/**
|
|
47
|
-
*
|
|
54
|
+
* Change the log drivers using vanilla configurations.
|
|
55
|
+
* This method does not depend in Athenna configuration
|
|
56
|
+
* files to be executed.
|
|
48
57
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
vanilla(...configs) {
|
|
59
|
+
this.drivers = [];
|
|
60
|
+
if (!configs.length) {
|
|
61
|
+
this.drivers.push(DriverFactory.fabricateVanilla());
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
configs.forEach(config => {
|
|
65
|
+
this.drivers.push(DriverFactory.fabricateVanilla(config));
|
|
66
|
+
});
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Verify if channel configuration exists. If not, Athenna will
|
|
71
|
+
* use the default vanilla configurations as drivers.
|
|
72
|
+
*/
|
|
73
|
+
channelOrVanilla(channel, configs = {}) {
|
|
74
|
+
if (channel === 'default') {
|
|
75
|
+
channel = Config.get(`logging.channels.${Config.get('logging.default')}`, 'default');
|
|
76
|
+
}
|
|
77
|
+
if (Config.exists(`logging.channels.${channel}`)) {
|
|
78
|
+
return this.channel(channel);
|
|
79
|
+
}
|
|
80
|
+
return this.vanilla({
|
|
81
|
+
...VANILLA_CHANNELS[channel],
|
|
82
|
+
...configs,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create a new standalone logger instance. Very
|
|
87
|
+
* useful to create new loggers without changing the
|
|
88
|
+
* channels that are already defined in the main instance.
|
|
89
|
+
*/
|
|
90
|
+
standalone(...configs) {
|
|
91
|
+
return Logger.standalone(configs);
|
|
53
92
|
}
|
|
54
93
|
/**
|
|
55
94
|
* Creates a log of type trace in channel.
|
|
@@ -94,12 +133,11 @@ export class Logger {
|
|
|
94
133
|
return this.log('fatal', ...args);
|
|
95
134
|
}
|
|
96
135
|
/**
|
|
97
|
-
*
|
|
98
|
-
* with vanilla configurations. By default,
|
|
99
|
-
* vanilla logger will use the "console" driver
|
|
100
|
-
* and "none" formatter.
|
|
136
|
+
* Call drivers to transport the log.
|
|
101
137
|
*/
|
|
102
|
-
|
|
103
|
-
|
|
138
|
+
async log(level, ...args) {
|
|
139
|
+
const message = Color.apply(...args);
|
|
140
|
+
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
141
|
+
return Promise.all(promises);
|
|
104
142
|
}
|
|
105
143
|
}
|
package/build/index.d.ts
CHANGED
|
@@ -9,9 +9,7 @@
|
|
|
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
|
-
export * from './Logger/VanillaLogger.js';
|
|
15
13
|
export * from './Helpers/FactoryHelper.js';
|
|
16
14
|
export * from './Factories/DriverFactory.js';
|
|
17
15
|
export * from './Providers/LoggerProvider.js';
|
package/build/index.js
CHANGED
|
@@ -9,9 +9,7 @@
|
|
|
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
|
-
export * from './Logger/VanillaLogger.js';
|
|
15
13
|
export * from './Helpers/FactoryHelper.js';
|
|
16
14
|
export * from './Factories/DriverFactory.js';
|
|
17
15
|
export * from './Providers/LoggerProvider.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
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
|
-
}
|
|
@@ -1,60 +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
|
-
export declare class VanillaLogger {
|
|
10
|
-
/**
|
|
11
|
-
* The driver responsible for transporting the logs.
|
|
12
|
-
*/
|
|
13
|
-
drivers: any[];
|
|
14
|
-
constructor(configs: any);
|
|
15
|
-
/**
|
|
16
|
-
* Set runtime configurations for drivers and
|
|
17
|
-
* formatters.
|
|
18
|
-
*/
|
|
19
|
-
config(): VanillaLogger;
|
|
20
|
-
/**
|
|
21
|
-
* Change the log channel.
|
|
22
|
-
*/
|
|
23
|
-
channel(): VanillaLogger;
|
|
24
|
-
/**
|
|
25
|
-
* Call drivers to transport the log.
|
|
26
|
-
*
|
|
27
|
-
* @param {string} level
|
|
28
|
-
* @param {string} args
|
|
29
|
-
* @return {any | Promise<any>}
|
|
30
|
-
*/
|
|
31
|
-
private log;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a log of type trace in channel.
|
|
34
|
-
*/
|
|
35
|
-
trace(...args: any[]): any | Promise<any>;
|
|
36
|
-
/**
|
|
37
|
-
* Creates a log of type debug in channel.
|
|
38
|
-
*/
|
|
39
|
-
debug(...args: any[]): any | Promise<any>;
|
|
40
|
-
/**
|
|
41
|
-
* Creates a log of type info in channel.
|
|
42
|
-
*/
|
|
43
|
-
info(...args: any[]): any | Promise<any>;
|
|
44
|
-
/**
|
|
45
|
-
* Creates a log of type success in channel.
|
|
46
|
-
*/
|
|
47
|
-
success(...args: any[]): any | Promise<any>;
|
|
48
|
-
/**
|
|
49
|
-
* Creates a log of type warn in channel.
|
|
50
|
-
*/
|
|
51
|
-
warn(...args: any[]): any | Promise<any>;
|
|
52
|
-
/**
|
|
53
|
-
* Creates a log of type error in channel.
|
|
54
|
-
*/
|
|
55
|
-
error(...args: any[]): any | Promise<any>;
|
|
56
|
-
/**
|
|
57
|
-
* Creates a log of type fatal in channel.
|
|
58
|
-
*/
|
|
59
|
-
fatal(...args: any[]): any | Promise<any>;
|
|
60
|
-
}
|
|
@@ -1,86 +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 { ColorHelper } from '#src/Helpers/ColorHelper';
|
|
10
|
-
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
11
|
-
export class VanillaLogger {
|
|
12
|
-
/**
|
|
13
|
-
* The driver responsible for transporting the logs.
|
|
14
|
-
*/
|
|
15
|
-
drivers = [];
|
|
16
|
-
constructor(configs) {
|
|
17
|
-
this.drivers.push(DriverFactory.fabricateVanilla(configs));
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Set runtime configurations for drivers and
|
|
21
|
-
* formatters.
|
|
22
|
-
*/
|
|
23
|
-
config() {
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Change the log channel.
|
|
28
|
-
*/
|
|
29
|
-
channel() {
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Call drivers to transport the log.
|
|
34
|
-
*
|
|
35
|
-
* @param {string} level
|
|
36
|
-
* @param {string} args
|
|
37
|
-
* @return {any | Promise<any>}
|
|
38
|
-
*/
|
|
39
|
-
log(level, ...args) {
|
|
40
|
-
const message = ColorHelper.applyLogEngine(...args);
|
|
41
|
-
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
42
|
-
return Promise.all(promises);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Creates a log of type trace in channel.
|
|
46
|
-
*/
|
|
47
|
-
trace(...args) {
|
|
48
|
-
return this.log('trace', ...args);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Creates a log of type debug in channel.
|
|
52
|
-
*/
|
|
53
|
-
debug(...args) {
|
|
54
|
-
return this.log('debug', ...args);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Creates a log of type info in channel.
|
|
58
|
-
*/
|
|
59
|
-
info(...args) {
|
|
60
|
-
return this.log('info', ...args);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Creates a log of type success in channel.
|
|
64
|
-
*/
|
|
65
|
-
success(...args) {
|
|
66
|
-
return this.log('success', ...args);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Creates a log of type warn in channel.
|
|
70
|
-
*/
|
|
71
|
-
warn(...args) {
|
|
72
|
-
return this.log('warn', ...args);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Creates a log of type error in channel.
|
|
76
|
-
*/
|
|
77
|
-
error(...args) {
|
|
78
|
-
return this.log('error', ...args);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Creates a log of type fatal in channel.
|
|
82
|
-
*/
|
|
83
|
-
fatal(...args) {
|
|
84
|
-
return this.log('fatal', ...args);
|
|
85
|
-
}
|
|
86
|
-
}
|