@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
|
@@ -1,26 +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
|
-
|
|
10
|
-
import { Formatter } from '#src/Formatters/Formatter'
|
|
11
|
-
|
|
12
|
-
export class MessageFormatter extends Formatter {
|
|
13
|
-
/**
|
|
14
|
-
* Format the message.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} message
|
|
17
|
-
* @return {string}
|
|
18
|
-
*/
|
|
19
|
-
format(message) {
|
|
20
|
-
return this.clean(
|
|
21
|
-
`${this.messageLevel()} - (${this.pid()}) - (${this.hostname()}): ${this.toString(
|
|
22
|
-
message,
|
|
23
|
-
)}`,
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,64 +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
|
-
|
|
10
|
-
import { ColorHelper } from '#src/index'
|
|
11
|
-
import { Formatter } from '#src/Formatters/Formatter'
|
|
12
|
-
|
|
13
|
-
export class RequestFormatter extends Formatter {
|
|
14
|
-
/**
|
|
15
|
-
* Format the message.
|
|
16
|
-
*
|
|
17
|
-
* @param {any} ctx
|
|
18
|
-
* @return {string}
|
|
19
|
-
*/
|
|
20
|
-
format(ctx) {
|
|
21
|
-
const ip = ctx.request.ip
|
|
22
|
-
const status = ctx.status
|
|
23
|
-
const responseTimeMs = `${Math.round(ctx.responseTime)}ms`
|
|
24
|
-
const methodAndStatus = ColorHelper[ctx.request.method](
|
|
25
|
-
`[${ctx.request.method}::${ctx.status}]`,
|
|
26
|
-
)
|
|
27
|
-
|
|
28
|
-
if (!this.configs.asJson) {
|
|
29
|
-
return this.clean(
|
|
30
|
-
`${methodAndStatus} - [${ip}] - ${new Date().toISOString()} - ${
|
|
31
|
-
ctx.request.baseUrl
|
|
32
|
-
} ${responseTimeMs}`,
|
|
33
|
-
)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const metadata = {
|
|
37
|
-
method: ctx.request.method,
|
|
38
|
-
duration: responseTimeMs,
|
|
39
|
-
status: status <= 399 ? 'SUCCESS' : 'ERROR',
|
|
40
|
-
statusCode: status,
|
|
41
|
-
url: ctx.request.hostUrl,
|
|
42
|
-
path: ctx.request.baseUrl,
|
|
43
|
-
createdAt: Date.now(),
|
|
44
|
-
traceId: this.traceId(),
|
|
45
|
-
data: ctx.data,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const request = {
|
|
49
|
-
url: ctx.request.hostUrl,
|
|
50
|
-
method: ctx.request.method,
|
|
51
|
-
body: ctx.request.body,
|
|
52
|
-
params: ctx.request.params,
|
|
53
|
-
queries: ctx.request.queries,
|
|
54
|
-
headers: ctx.request.headers,
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const response = {
|
|
58
|
-
body: ctx.body,
|
|
59
|
-
headers: ctx.headers,
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return JSON.stringify({ request, response, metadata })
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,27 +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
|
-
|
|
10
|
-
import { Formatter } from '#src/Formatters/Formatter'
|
|
11
|
-
|
|
12
|
-
export class SimpleFormatter extends Formatter {
|
|
13
|
-
/**
|
|
14
|
-
* Format the message.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} message
|
|
17
|
-
* @return {string}
|
|
18
|
-
*/
|
|
19
|
-
format(message) {
|
|
20
|
-
const pid = this.pid()
|
|
21
|
-
const time = this.timestamp()
|
|
22
|
-
const level = this.simpleLevel()
|
|
23
|
-
const colorizedMsg = this.applyColors(message)
|
|
24
|
-
|
|
25
|
-
return this.clean(`${level} - ${time} - (${pid}) ${colorizedMsg}`)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,322 +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
|
-
|
|
10
|
-
import { Is } from '@athenna/common'
|
|
11
|
-
import { format } from 'node:util'
|
|
12
|
-
import chalk, { Chalk } from 'chalk'
|
|
13
|
-
|
|
14
|
-
export class ColorHelper {
|
|
15
|
-
/**
|
|
16
|
-
* Chalk instance.
|
|
17
|
-
*
|
|
18
|
-
* @return {import('chalk').ChalkInstance}
|
|
19
|
-
*/
|
|
20
|
-
static chalk = chalk
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Paint as bold.
|
|
24
|
-
*
|
|
25
|
-
* @return {import('chalk').ChalkInstance}
|
|
26
|
-
*/
|
|
27
|
-
static get bold() {
|
|
28
|
-
return ColorHelper.chalk.bold
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Paint as grey.
|
|
33
|
-
*
|
|
34
|
-
* @return {import('chalk').ChalkInstance}
|
|
35
|
-
*/
|
|
36
|
-
static get grey() {
|
|
37
|
-
return ColorHelper.chalk.hex('#505050')
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Paint as purple.
|
|
42
|
-
*
|
|
43
|
-
* @return {import('chalk').ChalkInstance}
|
|
44
|
-
*/
|
|
45
|
-
static get purple() {
|
|
46
|
-
return ColorHelper.chalk.hex('#7628c8')
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Paint as darkPurple.
|
|
51
|
-
*
|
|
52
|
-
* @return {import('chalk').ChalkInstance}
|
|
53
|
-
*/
|
|
54
|
-
static get darkPurple() {
|
|
55
|
-
return ColorHelper.chalk.hex('#501b86')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Paint as yellow.
|
|
60
|
-
*
|
|
61
|
-
* @return {import('chalk').ChalkInstance}
|
|
62
|
-
*/
|
|
63
|
-
static get yellow() {
|
|
64
|
-
return ColorHelper.chalk.hex('#ffe600')
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Paint as cyan.
|
|
69
|
-
*
|
|
70
|
-
* @return {import('chalk').ChalkInstance}
|
|
71
|
-
*/
|
|
72
|
-
static get cyan() {
|
|
73
|
-
return ColorHelper.chalk.hex('#00ffff')
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Paint as white.
|
|
78
|
-
*
|
|
79
|
-
* @return {import('chalk').ChalkInstance}
|
|
80
|
-
*/
|
|
81
|
-
static get white() {
|
|
82
|
-
return ColorHelper.chalk.hex('#ffffff')
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Paint as orange.
|
|
87
|
-
*
|
|
88
|
-
* @return {import('chalk').ChalkInstance}
|
|
89
|
-
*/
|
|
90
|
-
static get orange() {
|
|
91
|
-
return ColorHelper.chalk.hex('#f18b0e')
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Paint as green.
|
|
96
|
-
*
|
|
97
|
-
* @return {import('chalk').ChalkInstance}
|
|
98
|
-
*/
|
|
99
|
-
static get green() {
|
|
100
|
-
return ColorHelper.chalk.hex('#0ef12c')
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Paint as darkGreen.
|
|
105
|
-
*
|
|
106
|
-
* @return {import('chalk').ChalkInstance}
|
|
107
|
-
*/
|
|
108
|
-
static get darkGreen() {
|
|
109
|
-
return ColorHelper.chalk.hex('#1cb70b')
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Paint as red.
|
|
114
|
-
*
|
|
115
|
-
* @return {import('chalk').ChalkInstance}
|
|
116
|
-
*/
|
|
117
|
-
static get red() {
|
|
118
|
-
return ColorHelper.chalk.hex('#f10e0e')
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Paint as darkRed.
|
|
123
|
-
*
|
|
124
|
-
* @return {import('chalk').ChalkInstance}
|
|
125
|
-
*/
|
|
126
|
-
static get darkRed() {
|
|
127
|
-
return ColorHelper.chalk.hex('#710909')
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Paint debugs.
|
|
132
|
-
*
|
|
133
|
-
* @return {import('chalk').ChalkInstance}
|
|
134
|
-
*/
|
|
135
|
-
static get trace() {
|
|
136
|
-
return this.grey.bold
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Paint debugs.
|
|
141
|
-
*
|
|
142
|
-
* @return {import('chalk').ChalkInstance}
|
|
143
|
-
*/
|
|
144
|
-
static get debug() {
|
|
145
|
-
return this.purple.bold
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Paint infos.
|
|
150
|
-
*
|
|
151
|
-
* @return {import('chalk').ChalkInstance}
|
|
152
|
-
*/
|
|
153
|
-
static get info() {
|
|
154
|
-
return this.cyan
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Paint success.
|
|
159
|
-
*
|
|
160
|
-
* @return {import('chalk').ChalkInstance}
|
|
161
|
-
*/
|
|
162
|
-
static get success() {
|
|
163
|
-
return this.green
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Paint warning.
|
|
168
|
-
*
|
|
169
|
-
* @return {import('chalk').ChalkInstance}
|
|
170
|
-
*/
|
|
171
|
-
static get warn() {
|
|
172
|
-
return this.orange
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Paint error.
|
|
177
|
-
*
|
|
178
|
-
* @return {import('chalk').ChalkInstance}
|
|
179
|
-
*/
|
|
180
|
-
static get error() {
|
|
181
|
-
return this.red
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Paint fatal.
|
|
186
|
-
*
|
|
187
|
-
* @return {import('chalk').ChalkInstance}
|
|
188
|
-
*/
|
|
189
|
-
static get fatal() {
|
|
190
|
-
return ColorHelper.chalk.bgRed
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Paint http method.
|
|
195
|
-
*
|
|
196
|
-
* @return {import('chalk').ChalkInstance}
|
|
197
|
-
*/
|
|
198
|
-
static get GET() {
|
|
199
|
-
return this.purple.bold
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Paint http method.
|
|
204
|
-
*
|
|
205
|
-
* @return {import('chalk').ChalkInstance}
|
|
206
|
-
*/
|
|
207
|
-
static get HEAD() {
|
|
208
|
-
return this.cyan.bold
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Paint http method.
|
|
213
|
-
*
|
|
214
|
-
* @return {import('chalk').ChalkInstance}
|
|
215
|
-
*/
|
|
216
|
-
static get PUT() {
|
|
217
|
-
return this.orange.bold
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Paint http method.
|
|
222
|
-
*
|
|
223
|
-
* @return {import('chalk').ChalkInstance}
|
|
224
|
-
*/
|
|
225
|
-
static get PATCH() {
|
|
226
|
-
return this.yellow.bold
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Paint http method.
|
|
231
|
-
*
|
|
232
|
-
* @return {import('chalk').ChalkInstance}
|
|
233
|
-
*/
|
|
234
|
-
static get POST() {
|
|
235
|
-
return this.green.bold
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* Paint http method.
|
|
240
|
-
*
|
|
241
|
-
* @return {import('chalk').ChalkInstance}
|
|
242
|
-
*/
|
|
243
|
-
static get DELETE() {
|
|
244
|
-
return this.red.bold
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Paint http method.
|
|
249
|
-
*
|
|
250
|
-
* @return {import('chalk').ChalkInstance}
|
|
251
|
-
*/
|
|
252
|
-
static get OPTIONS() {
|
|
253
|
-
return this.cyan.bold
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Remove all colors and special chars of string.
|
|
258
|
-
*
|
|
259
|
-
* @param {string} string
|
|
260
|
-
* @return {string}
|
|
261
|
-
*/
|
|
262
|
-
static removeColors(string) {
|
|
263
|
-
return ColorHelper.chalk.reset(string).replace(
|
|
264
|
-
// eslint-disable-next-line no-control-regex
|
|
265
|
-
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
|
|
266
|
-
'',
|
|
267
|
-
)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
/**
|
|
271
|
-
* Paint by the http method.
|
|
272
|
-
*
|
|
273
|
-
* @param {'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH', 'OPTIONS', 'HEAD' } method
|
|
274
|
-
* @return {import('chalk').ChalkInstance}
|
|
275
|
-
*/
|
|
276
|
-
static httpMethod(method) {
|
|
277
|
-
return this[method]
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Applies the log engine to execute chalk methods.
|
|
282
|
-
*
|
|
283
|
-
* @param {string} args
|
|
284
|
-
* @return {any}
|
|
285
|
-
*/
|
|
286
|
-
static applyLogEngine(...args) {
|
|
287
|
-
if (!Is.String(args[0])) {
|
|
288
|
-
return args[0]
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
let content = format(...args.filter(arg => arg !== undefined))
|
|
292
|
-
|
|
293
|
-
const matches = content.match(/\({(.*?)} ([\s\S]*?)\)/g)
|
|
294
|
-
|
|
295
|
-
if (!matches) {
|
|
296
|
-
return content
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
matches.forEach(match => {
|
|
300
|
-
const [chalkMethodsInBrackets, chalkMethodsString] =
|
|
301
|
-
match.match(/\{(.*?)\}/)
|
|
302
|
-
|
|
303
|
-
const message = match
|
|
304
|
-
.replace(chalkMethodsInBrackets, '')
|
|
305
|
-
.replace(/\s*\(\s*|\s*\)\s*/g, '')
|
|
306
|
-
|
|
307
|
-
const chalkMethodsArray = chalkMethodsString.replace(/\s/g, '').split(',')
|
|
308
|
-
|
|
309
|
-
let chalk = new Chalk()
|
|
310
|
-
|
|
311
|
-
chalkMethodsArray.forEach(chalkMethod => {
|
|
312
|
-
if (!chalk[chalkMethod]) return
|
|
313
|
-
|
|
314
|
-
chalk = chalk[chalkMethod]
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
content = content.replace(match, chalk(message))
|
|
318
|
-
})
|
|
319
|
-
|
|
320
|
-
return content
|
|
321
|
-
}
|
|
322
|
-
}
|
|
@@ -1,31 +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
|
-
|
|
10
|
-
import { Options } from '@athenna/common'
|
|
11
|
-
|
|
12
|
-
export class FactoryHelper {
|
|
13
|
-
/**
|
|
14
|
-
* Group the configuration values.
|
|
15
|
-
*
|
|
16
|
-
* @param {any} object
|
|
17
|
-
* @param {any} defaultValue
|
|
18
|
-
* @return {any}
|
|
19
|
-
*/
|
|
20
|
-
static groupConfigs(object, defaultValue) {
|
|
21
|
-
const formatter = object.formatter || defaultValue.formatter
|
|
22
|
-
const formatterConfig = Options.create(
|
|
23
|
-
object.formatterConfig,
|
|
24
|
-
defaultValue.formatterConfig,
|
|
25
|
-
)
|
|
26
|
-
|
|
27
|
-
const driverConfig = Options.create(object, defaultValue)
|
|
28
|
-
|
|
29
|
-
return { ...driverConfig, formatter, formatterConfig }
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1,134 +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
|
-
|
|
10
|
-
import { ColorHelper } from '#src/index'
|
|
11
|
-
import { DriverFactory } from '#src/Factories/DriverFactory'
|
|
12
|
-
|
|
13
|
-
export class VanillaLogger {
|
|
14
|
-
/**
|
|
15
|
-
* The driver responsible for transporting the logs.
|
|
16
|
-
*
|
|
17
|
-
* @type {any[]}
|
|
18
|
-
*/
|
|
19
|
-
#drivers = []
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Creates a new instance of ConsoleLogger.
|
|
23
|
-
*
|
|
24
|
-
* @param {any} [configs]
|
|
25
|
-
* @return {VanillaLogger}
|
|
26
|
-
*/
|
|
27
|
-
constructor(configs) {
|
|
28
|
-
this.#drivers.push(DriverFactory.fabricateVanilla(configs))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Set runtime configurations for drivers and
|
|
33
|
-
* formatters.
|
|
34
|
-
*
|
|
35
|
-
* @return {VanillaLogger}
|
|
36
|
-
*/
|
|
37
|
-
config() {
|
|
38
|
-
return this
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Change the log channel.
|
|
43
|
-
*
|
|
44
|
-
* @return {VanillaLogger}
|
|
45
|
-
*/
|
|
46
|
-
channel() {
|
|
47
|
-
return this
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Call drivers to transport the log.
|
|
52
|
-
*
|
|
53
|
-
* @param {string} level
|
|
54
|
-
* @param {string} args
|
|
55
|
-
* @return {any | Promise<any>}
|
|
56
|
-
*/
|
|
57
|
-
#log(level, ...args) {
|
|
58
|
-
const message = ColorHelper.applyLogEngine(...args)
|
|
59
|
-
|
|
60
|
-
const promises = this.#drivers.map(d => d.transport(level, message))
|
|
61
|
-
|
|
62
|
-
return Promise.all(promises)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Creates a log of type trace in channel.
|
|
67
|
-
*
|
|
68
|
-
* @param {string|any} args
|
|
69
|
-
* @return {any | Promise<any>}
|
|
70
|
-
*/
|
|
71
|
-
trace(...args) {
|
|
72
|
-
return this.#log('trace', ...args)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Creates a log of type debug in channel.
|
|
77
|
-
*
|
|
78
|
-
* @param {string|any} args
|
|
79
|
-
* @return {any | Promise<any>}
|
|
80
|
-
*/
|
|
81
|
-
debug(...args) {
|
|
82
|
-
return this.#log('debug', ...args)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Creates a log of type info in channel.
|
|
87
|
-
*
|
|
88
|
-
* @param {string|any} args
|
|
89
|
-
* @return {any | Promise<any>}
|
|
90
|
-
*/
|
|
91
|
-
info(...args) {
|
|
92
|
-
return this.#log('info', ...args)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Creates a log of type success in channel.
|
|
97
|
-
*
|
|
98
|
-
* @param {string|any} args
|
|
99
|
-
* @return {any | Promise<any>}
|
|
100
|
-
*/
|
|
101
|
-
success(...args) {
|
|
102
|
-
return this.#log('success', ...args)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Creates a log of type warn in channel.
|
|
107
|
-
*
|
|
108
|
-
* @param {string|any} args
|
|
109
|
-
* @return {any | Promise<any>}
|
|
110
|
-
*/
|
|
111
|
-
warn(...args) {
|
|
112
|
-
return this.#log('warn', ...args)
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Creates a log of type error in channel.
|
|
117
|
-
*
|
|
118
|
-
* @param {string|any} args
|
|
119
|
-
* @return {any | Promise<any>}
|
|
120
|
-
*/
|
|
121
|
-
error(...args) {
|
|
122
|
-
return this.#log('error', ...args)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Creates a log of type fatal in channel.
|
|
127
|
-
*
|
|
128
|
-
* @param {string|any} args
|
|
129
|
-
* @return {any | Promise<any>}
|
|
130
|
-
*/
|
|
131
|
-
fatal(...args) {
|
|
132
|
-
return this.#log('fatal', ...args)
|
|
133
|
-
}
|
|
134
|
-
}
|