@athenna/logger 3.0.9 → 3.1.0
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/Drivers/ConsoleDriver.d.ts +12 -0
- package/build/Drivers/ConsoleDriver.js +19 -0
- package/build/Drivers/DiscordDriver.d.ts +12 -0
- package/build/Drivers/DiscordDriver.js +22 -0
- package/build/Drivers/Driver.d.ts +52 -0
- package/build/Drivers/Driver.js +85 -0
- package/build/Drivers/FileDriver.d.ts +12 -0
- package/build/Drivers/FileDriver.js +24 -0
- package/build/Drivers/NullDriver.d.ts +12 -0
- package/build/Drivers/NullDriver.js +14 -0
- package/build/Drivers/SlackDriver.d.ts +12 -0
- package/build/Drivers/SlackDriver.js +19 -0
- package/build/Drivers/StackDriver.d.ts +12 -0
- package/build/Drivers/StackDriver.js +19 -0
- package/build/Drivers/TelegramDriver.d.ts +12 -0
- package/build/Drivers/TelegramDriver.js +21 -0
- package/build/Exceptions/DriverExistException.d.ts +12 -0
- package/build/Exceptions/DriverExistException.js +21 -0
- package/{src/Facades/Log.js → build/Exceptions/FormatterExistException.d.ts} +4 -9
- package/build/Exceptions/FormatterExistException.js +21 -0
- package/build/Exceptions/NotFoundDriverException.d.ts +12 -0
- package/build/Exceptions/NotFoundDriverException.js +21 -0
- package/build/Exceptions/NotFoundFormatterException.d.ts +12 -0
- package/build/Exceptions/NotFoundFormatterException.js +21 -0
- package/build/Exceptions/NotImplementedConfigException.d.ts +12 -0
- package/build/Exceptions/NotImplementedConfigException.js +28 -0
- package/build/Facades/Log.d.ts +10 -0
- package/build/Facades/Log.js +10 -0
- package/build/Factories/DriverFactory.d.ts +39 -0
- package/build/Factories/DriverFactory.js +93 -0
- package/build/Factories/FormatterFactory.d.ts +29 -0
- package/build/Factories/FormatterFactory.js +57 -0
- package/build/Formatters/CliFormatter.d.ts +12 -0
- package/build/Formatters/CliFormatter.js +15 -0
- package/build/Formatters/Formatter.d.ts +85 -0
- package/build/Formatters/Formatter.js +177 -0
- package/build/Formatters/JsonFormatter.d.ts +12 -0
- package/build/Formatters/JsonFormatter.js +26 -0
- package/build/Formatters/MessageFormatter.d.ts +12 -0
- package/build/Formatters/MessageFormatter.js +14 -0
- package/build/Formatters/NoneFormatter.d.ts +12 -0
- package/{src → build}/Formatters/NoneFormatter.js +4 -12
- package/build/Formatters/RequestFormatter.d.ts +12 -0
- package/build/Formatters/RequestFormatter.js +45 -0
- package/build/Formatters/SimpleFormatter.d.ts +12 -0
- package/build/Formatters/SimpleFormatter.js +18 -0
- package/build/Helpers/ColorHelper.d.ts +131 -0
- package/build/Helpers/ColorHelper.js +215 -0
- package/build/Helpers/FactoryHelper.d.ts +14 -0
- package/build/Helpers/FactoryHelper.js +20 -0
- package/build/Logger/Logger.d.ts +68 -0
- package/build/Logger/Logger.js +105 -0
- package/build/Logger/VanillaLogger.d.ts +60 -0
- package/build/Logger/VanillaLogger.js +86 -0
- package/build/Providers/LoggerProvider.d.ts +12 -0
- package/{src → build}/Providers/LoggerProvider.js +5 -12
- package/build/index.d.ts +18 -0
- package/build/index.js +18 -0
- package/package.json +81 -59
- package/src/Drivers/ConsoleDriver.js +0 -40
- package/src/Drivers/DiscordDriver.js +0 -43
- package/src/Drivers/Driver.js +0 -134
- package/src/Drivers/FileDriver.js +0 -47
- package/src/Drivers/NullDriver.js +0 -33
- package/src/Drivers/SlackDriver.js +0 -40
- package/src/Drivers/StackDriver.js +0 -45
- package/src/Drivers/TelegramDriver.js +0 -46
- package/src/Exceptions/DriverExistException.js +0 -31
- package/src/Exceptions/FormatterExistException.js +0 -32
- package/src/Exceptions/NotFoundDriverException.js +0 -31
- package/src/Exceptions/NotFoundFormatterException.js +0 -31
- package/src/Exceptions/NotImplementedConfigException.js +0 -37
- package/src/Factories/DriverFactory.js +0 -128
- package/src/Factories/FormatterFactory.js +0 -77
- package/src/Formatters/CliFormatter.js +0 -24
- package/src/Formatters/Formatter.js +0 -266
- package/src/Formatters/JsonFormatter.js +0 -37
- package/src/Formatters/MessageFormatter.js +0 -26
- package/src/Formatters/RequestFormatter.js +0 -64
- package/src/Formatters/SimpleFormatter.js +0 -27
- package/src/Helpers/ColorHelper.js +0 -322
- package/src/Helpers/FactoryHelper.js +0 -31
- package/src/Helpers/VanillaLogger.js +0 -134
- package/src/index.d.ts +0 -797
- package/src/index.js +0 -180
|
@@ -0,0 +1,131 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,215 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 FactoryHelper {
|
|
10
|
+
/**
|
|
11
|
+
* Group the configuration values.
|
|
12
|
+
*/
|
|
13
|
+
static groupConfigs(object: any, defaultValue: any): any;
|
|
14
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { Options } from '@athenna/common';
|
|
10
|
+
export class FactoryHelper {
|
|
11
|
+
/**
|
|
12
|
+
* Group the configuration values.
|
|
13
|
+
*/
|
|
14
|
+
static groupConfigs(object, defaultValue) {
|
|
15
|
+
const formatter = object.formatter || defaultValue.formatter;
|
|
16
|
+
const formatterConfig = Options.create(object.formatterConfig, defaultValue.formatterConfig);
|
|
17
|
+
const driverConfig = Options.create(object, defaultValue);
|
|
18
|
+
return { ...driverConfig, formatter, formatterConfig };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
10
|
+
export declare class Logger {
|
|
11
|
+
/**
|
|
12
|
+
* The drivers responsible for transporting the logs.
|
|
13
|
+
*/
|
|
14
|
+
private drivers;
|
|
15
|
+
/**
|
|
16
|
+
* Runtime configurations to be used inside the Drivers and Formatters.
|
|
17
|
+
*/
|
|
18
|
+
private runtimeConfigs;
|
|
19
|
+
constructor();
|
|
20
|
+
/**
|
|
21
|
+
* Set runtime configurations for drivers and
|
|
22
|
+
* formatters.
|
|
23
|
+
*/
|
|
24
|
+
config(runtimeConfigs: any): this;
|
|
25
|
+
/**
|
|
26
|
+
* Change the log channel.
|
|
27
|
+
*/
|
|
28
|
+
channel(...channels: string[]): this;
|
|
29
|
+
/**
|
|
30
|
+
* Call drivers to transport the log.
|
|
31
|
+
*/
|
|
32
|
+
private log;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a log of type trace in channel.
|
|
35
|
+
*/
|
|
36
|
+
trace(...args: any[]): any | Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a log of type debug in channel.
|
|
39
|
+
*/
|
|
40
|
+
debug(...args: any[]): any | Promise<any>;
|
|
41
|
+
/**
|
|
42
|
+
* Creates a log of type info in channel.
|
|
43
|
+
*/
|
|
44
|
+
info(...args: any[]): any | Promise<any>;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a log of type success in channel.
|
|
47
|
+
*/
|
|
48
|
+
success(...args: any[]): any | Promise<any>;
|
|
49
|
+
/**
|
|
50
|
+
* Creates a log of type warn in channel.
|
|
51
|
+
*/
|
|
52
|
+
warn(...args: any[]): any | Promise<any>;
|
|
53
|
+
/**
|
|
54
|
+
* Creates a log of type error in channel.
|
|
55
|
+
*/
|
|
56
|
+
error(...args: any[]): any | Promise<any>;
|
|
57
|
+
/**
|
|
58
|
+
* Creates a log of type fatal in channel.
|
|
59
|
+
*/
|
|
60
|
+
fatal(...args: any[]): any | Promise<any>;
|
|
61
|
+
/**
|
|
62
|
+
* Get a new instance of any log driver
|
|
63
|
+
* with vanilla configurations. By default,
|
|
64
|
+
* vanilla logger will use the "console" driver
|
|
65
|
+
* and "none" formatter.
|
|
66
|
+
*/
|
|
67
|
+
static getVanillaLogger(configs?: any): VanillaLogger;
|
|
68
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { Config } from '@athenna/config';
|
|
10
|
+
import { ColorHelper } from '#src/Helpers/ColorHelper';
|
|
11
|
+
import { VanillaLogger } from '#src/Logger/VanillaLogger';
|
|
12
|
+
import { DriverFactory } from '#src/Factories/DriverFactory';
|
|
13
|
+
export class Logger {
|
|
14
|
+
/**
|
|
15
|
+
* The drivers responsible for transporting the logs.
|
|
16
|
+
*/
|
|
17
|
+
drivers = [];
|
|
18
|
+
/**
|
|
19
|
+
* Runtime configurations to be used inside the Drivers and Formatters.
|
|
20
|
+
*/
|
|
21
|
+
runtimeConfigs = {};
|
|
22
|
+
constructor() {
|
|
23
|
+
if (!Config.exists(`logging.channels.${Config.get('logging.default')}`)) {
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
this.drivers.push(DriverFactory.fabricate('default', this.runtimeConfigs));
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Set runtime configurations for drivers and
|
|
30
|
+
* formatters.
|
|
31
|
+
*/
|
|
32
|
+
config(runtimeConfigs) {
|
|
33
|
+
this.runtimeConfigs = runtimeConfigs;
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Change the log channel.
|
|
38
|
+
*/
|
|
39
|
+
channel(...channels) {
|
|
40
|
+
this.drivers = [];
|
|
41
|
+
channels.forEach(c => {
|
|
42
|
+
this.drivers.push(DriverFactory.fabricate(c, this.runtimeConfigs));
|
|
43
|
+
});
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Call drivers to transport the log.
|
|
48
|
+
*/
|
|
49
|
+
async log(level, ...args) {
|
|
50
|
+
const message = ColorHelper.applyLogEngine(...args);
|
|
51
|
+
const promises = this.drivers.map((driver) => driver.transport(level, message));
|
|
52
|
+
return Promise.all(promises);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Creates a log of type trace in channel.
|
|
56
|
+
*/
|
|
57
|
+
trace(...args) {
|
|
58
|
+
return this.log('trace', ...args);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a log of type debug in channel.
|
|
62
|
+
*/
|
|
63
|
+
debug(...args) {
|
|
64
|
+
return this.log('debug', ...args);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates a log of type info in channel.
|
|
68
|
+
*/
|
|
69
|
+
info(...args) {
|
|
70
|
+
return this.log('info', ...args);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Creates a log of type success in channel.
|
|
74
|
+
*/
|
|
75
|
+
success(...args) {
|
|
76
|
+
return this.log('success', ...args);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Creates a log of type warn in channel.
|
|
80
|
+
*/
|
|
81
|
+
warn(...args) {
|
|
82
|
+
return this.log('warn', ...args);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Creates a log of type error in channel.
|
|
86
|
+
*/
|
|
87
|
+
error(...args) {
|
|
88
|
+
return this.log('error', ...args);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a log of type fatal in channel.
|
|
92
|
+
*/
|
|
93
|
+
fatal(...args) {
|
|
94
|
+
return this.log('fatal', ...args);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Get a new instance of any log driver
|
|
98
|
+
* with vanilla configurations. By default,
|
|
99
|
+
* vanilla logger will use the "console" driver
|
|
100
|
+
* and "none" formatter.
|
|
101
|
+
*/
|
|
102
|
+
static getVanillaLogger(configs = {}) {
|
|
103
|
+
return new VanillaLogger(configs);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 { ServiceProvider } from '@athenna/ioc';
|
|
10
|
+
export declare class LoggerProvider extends ServiceProvider {
|
|
11
|
+
register(): void;
|
|
12
|
+
}
|