@athenna/logger 3.0.9 → 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/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 +176 -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 +48 -0
- package/build/Formatters/SimpleFormatter.d.ts +12 -0
- package/build/Formatters/SimpleFormatter.js +18 -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 +65 -0
- package/build/Logger/VanillaLogger.js +93 -0
- package/build/Providers/LoggerProvider.d.ts +12 -0
- package/{src → build}/Providers/LoggerProvider.js +5 -12
- package/build/index.d.ts +17 -0
- package/build/index.js +17 -0
- package/package.json +82 -61
- 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,77 +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 { CliFormatter } from '#src/Formatters/CliFormatter'
|
|
11
|
-
import { JsonFormatter } from '#src/Formatters/JsonFormatter'
|
|
12
|
-
import { NoneFormatter } from '#src/Formatters/NoneFormatter'
|
|
13
|
-
import { SimpleFormatter } from '#src/Formatters/SimpleFormatter'
|
|
14
|
-
import { MessageFormatter } from '#src/Formatters/MessageFormatter'
|
|
15
|
-
import { RequestFormatter } from '#src/Formatters/RequestFormatter'
|
|
16
|
-
import { FormatterExistException } from '#src/Exceptions/FormatterExistException'
|
|
17
|
-
import { NotFoundFormatterException } from '#src/Exceptions/NotFoundFormatterException'
|
|
18
|
-
|
|
19
|
-
export class FormatterFactory {
|
|
20
|
-
/**
|
|
21
|
-
* Formatters of FormatterFactory.
|
|
22
|
-
*
|
|
23
|
-
* @type {Map<string, { Formatter: any }>}
|
|
24
|
-
*/
|
|
25
|
-
static formatters = new Map()
|
|
26
|
-
.set('cli', { Formatter: CliFormatter })
|
|
27
|
-
.set('json', { Formatter: JsonFormatter })
|
|
28
|
-
.set('none', { Formatter: NoneFormatter })
|
|
29
|
-
.set('simple', { Formatter: SimpleFormatter })
|
|
30
|
-
.set('message', { Formatter: MessageFormatter })
|
|
31
|
-
.set('request', { Formatter: RequestFormatter })
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Return an array with all available formatters.
|
|
35
|
-
*
|
|
36
|
-
* @return {any[]}
|
|
37
|
-
*/
|
|
38
|
-
static availableFormatters() {
|
|
39
|
-
const availableFormatters = []
|
|
40
|
-
|
|
41
|
-
for (const [key] of this.formatters.entries()) {
|
|
42
|
-
availableFormatters.push(key)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return availableFormatters
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Fabricate a new instance of a formatter.
|
|
50
|
-
*
|
|
51
|
-
* @param {string} formatterName
|
|
52
|
-
* @return {any}
|
|
53
|
-
*/
|
|
54
|
-
static fabricate(formatterName) {
|
|
55
|
-
const formatterObject = this.formatters.get(formatterName)
|
|
56
|
-
|
|
57
|
-
if (!formatterObject) {
|
|
58
|
-
throw new NotFoundFormatterException(formatterName)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return new formatterObject.Formatter()
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Creates a new formatter implementation.
|
|
66
|
-
*
|
|
67
|
-
* @param {string} name
|
|
68
|
-
* @param {() => any} formatter
|
|
69
|
-
*/
|
|
70
|
-
static createFormatter(name, formatter) {
|
|
71
|
-
if (this.formatters.has(name)) {
|
|
72
|
-
throw new FormatterExistException(name)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this.formatters.set(name, { Formatter: formatter })
|
|
76
|
-
}
|
|
77
|
-
}
|
|
@@ -1,24 +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 CliFormatter extends Formatter {
|
|
13
|
-
/**
|
|
14
|
-
* Format the message.
|
|
15
|
-
*
|
|
16
|
-
* @param {string} message
|
|
17
|
-
* @return {string}
|
|
18
|
-
*/
|
|
19
|
-
format(message) {
|
|
20
|
-
const level = this.cliLevel()
|
|
21
|
-
|
|
22
|
-
return this.clean(`${level} ${this.toString(message)}`)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,266 +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 rTracer from 'cls-rtracer'
|
|
11
|
-
|
|
12
|
-
import { hostname } from 'node:os'
|
|
13
|
-
import { Is } from '@athenna/common'
|
|
14
|
-
import { ColorHelper } from '#src/Helpers/ColorHelper'
|
|
15
|
-
|
|
16
|
-
export class Formatter {
|
|
17
|
-
/**
|
|
18
|
-
* Holds the configuration object of formatter.
|
|
19
|
-
*/
|
|
20
|
-
configs = {}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new instance of Formatter.
|
|
24
|
-
*
|
|
25
|
-
* @param {any} configs
|
|
26
|
-
* @return {Formatter}
|
|
27
|
-
*/
|
|
28
|
-
config(configs) {
|
|
29
|
-
this.configs = configs
|
|
30
|
-
|
|
31
|
-
return this
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Format the message.
|
|
36
|
-
*
|
|
37
|
-
* @param {string} message
|
|
38
|
-
* @return {string}
|
|
39
|
-
*/
|
|
40
|
-
format(message) {}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Create the PID for formatter.
|
|
44
|
-
*
|
|
45
|
-
* @return {string}
|
|
46
|
-
*/
|
|
47
|
-
pid() {
|
|
48
|
-
return process.pid.toString()
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Create the hostname for formatter.
|
|
53
|
-
*
|
|
54
|
-
* @return {string}
|
|
55
|
-
*/
|
|
56
|
-
hostname() {
|
|
57
|
-
return hostname()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Get the level without any color or format.
|
|
62
|
-
*
|
|
63
|
-
* @return {string}
|
|
64
|
-
*/
|
|
65
|
-
level() {
|
|
66
|
-
return this.configs.level
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Get the trace id for formatter.
|
|
71
|
-
*
|
|
72
|
-
* @return {string | null}
|
|
73
|
-
*/
|
|
74
|
-
traceId() {
|
|
75
|
-
return rTracer.id() || null
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Create the timestamp for formatter.
|
|
80
|
-
*
|
|
81
|
-
* @return {string}
|
|
82
|
-
*/
|
|
83
|
-
timestamp() {
|
|
84
|
-
const localeStringOptions = {
|
|
85
|
-
year: 'numeric',
|
|
86
|
-
hour: 'numeric',
|
|
87
|
-
minute: 'numeric',
|
|
88
|
-
second: 'numeric',
|
|
89
|
-
day: '2-digit',
|
|
90
|
-
month: '2-digit',
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return new Date(Date.now()).toLocaleString(undefined, localeStringOptions)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Transform the message to string.
|
|
98
|
-
*
|
|
99
|
-
* @param message {string}
|
|
100
|
-
* @return {string}
|
|
101
|
-
*/
|
|
102
|
-
toString(message) {
|
|
103
|
-
if (Is.String(message)) {
|
|
104
|
-
return message
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (Is.Object(message)) {
|
|
108
|
-
message = JSON.stringify(message)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return `${message}`
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Clean the message removing colors if clean
|
|
116
|
-
* option is true. If force is true, then colors
|
|
117
|
-
* will be removed even if configs clean option
|
|
118
|
-
* is false.
|
|
119
|
-
*
|
|
120
|
-
* @param message {string}
|
|
121
|
-
* @param [force] {boolean}
|
|
122
|
-
* @return {string}
|
|
123
|
-
*/
|
|
124
|
-
clean(message, force = false) {
|
|
125
|
-
if (this.configs.clean || force) {
|
|
126
|
-
return ColorHelper.removeColors(message)
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
return message
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Apply all colors necessary to message.
|
|
134
|
-
*
|
|
135
|
-
* @param message {string}
|
|
136
|
-
* @return {string}
|
|
137
|
-
*/
|
|
138
|
-
applyColors(message) {
|
|
139
|
-
message = this.toString(message)
|
|
140
|
-
|
|
141
|
-
return this.applyColorsByChalk(this.applyColorsByLevel(message))
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Apply colors in message.
|
|
146
|
-
*
|
|
147
|
-
* @param message {string}
|
|
148
|
-
* @return {string}
|
|
149
|
-
*/
|
|
150
|
-
applyColorsByChalk(message) {
|
|
151
|
-
if (!this.configs.chalk) {
|
|
152
|
-
return message
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return this.configs.chalk(message)
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Apply colors in message by level.
|
|
160
|
-
*
|
|
161
|
-
* @param message {string}
|
|
162
|
-
* @return {string}
|
|
163
|
-
*/
|
|
164
|
-
applyColorsByLevel(message) {
|
|
165
|
-
const level = this.configs.level
|
|
166
|
-
|
|
167
|
-
return this.paintMessageByLevel(level, message)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Create the cli level string.
|
|
172
|
-
*
|
|
173
|
-
* @return {string}
|
|
174
|
-
*/
|
|
175
|
-
cliLevel() {
|
|
176
|
-
const level = this.configs.level
|
|
177
|
-
|
|
178
|
-
if (!ColorHelper[level]) {
|
|
179
|
-
return level
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return ColorHelper[level].bold(`[ ${level} ]`)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Create the simple level string.
|
|
187
|
-
*
|
|
188
|
-
* @return {string}
|
|
189
|
-
*/
|
|
190
|
-
simpleLevel() {
|
|
191
|
-
const level = this.configs.level
|
|
192
|
-
|
|
193
|
-
if (!ColorHelper[level]) {
|
|
194
|
-
return level
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return ColorHelper[level].bold(`[${level.toUpperCase()}]`)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Create the message level emoji string.
|
|
202
|
-
*
|
|
203
|
-
* @return {string}
|
|
204
|
-
*/
|
|
205
|
-
messageLevel() {
|
|
206
|
-
const level = this.configs.level
|
|
207
|
-
|
|
208
|
-
return this.getEmojiByLevel(level, this.configs.customEmoji)
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Get the emoji by level.
|
|
213
|
-
*
|
|
214
|
-
* @param {string} level
|
|
215
|
-
* @param {string} [customEmoji]
|
|
216
|
-
* @return {string}
|
|
217
|
-
*/
|
|
218
|
-
getEmojiByLevel(level, customEmoji) {
|
|
219
|
-
if (customEmoji) {
|
|
220
|
-
return customEmoji
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const levelEmojis = {
|
|
224
|
-
trace: '\u{1F43E}',
|
|
225
|
-
debug: '\u{1F50E}',
|
|
226
|
-
info: '\u{2139}',
|
|
227
|
-
success: '\u{2705}',
|
|
228
|
-
warn: '\u{26A0}',
|
|
229
|
-
error: '\u{274C}',
|
|
230
|
-
fatal: '\u{1F6D1}',
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
if (!levelEmojis[level.toLowerCase()]) {
|
|
234
|
-
return ''
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return levelEmojis[level.toLowerCase()]
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Paint the message by level.
|
|
242
|
-
*
|
|
243
|
-
* @param {string} level
|
|
244
|
-
* @param {string} message
|
|
245
|
-
* @return {string}
|
|
246
|
-
*/
|
|
247
|
-
paintMessageByLevel(level, message) {
|
|
248
|
-
const levelLower = level.toLowerCase()
|
|
249
|
-
|
|
250
|
-
const levelColors = {
|
|
251
|
-
trace: ColorHelper.trace,
|
|
252
|
-
debug: ColorHelper.debug,
|
|
253
|
-
info: ColorHelper.info,
|
|
254
|
-
success: ColorHelper.success,
|
|
255
|
-
warn: ColorHelper.warn,
|
|
256
|
-
error: ColorHelper.error,
|
|
257
|
-
fatal: ColorHelper.fatal,
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (!levelColors[levelLower]) {
|
|
261
|
-
return message
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return levelColors[levelLower](message)
|
|
265
|
-
}
|
|
266
|
-
}
|
|
@@ -1,37 +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 { Formatter } from '#src/Formatters/Formatter'
|
|
12
|
-
|
|
13
|
-
export class JsonFormatter extends Formatter {
|
|
14
|
-
/**
|
|
15
|
-
* Format the message.
|
|
16
|
-
*
|
|
17
|
-
* @param {any} message
|
|
18
|
-
* @return {string}
|
|
19
|
-
*/
|
|
20
|
-
format(message) {
|
|
21
|
-
const base = {
|
|
22
|
-
level: this.level(),
|
|
23
|
-
time: Date.now(),
|
|
24
|
-
pid: this.pid(),
|
|
25
|
-
hostname: this.hostname(),
|
|
26
|
-
traceId: this.traceId(),
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (Is.String(message)) {
|
|
30
|
-
base.msg = message
|
|
31
|
-
|
|
32
|
-
return JSON.stringify(base)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return JSON.stringify({ ...base, ...message })
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -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
|
-
}
|