@athenna/logger 3.0.2 → 3.0.4
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@athenna/logger",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.4",
|
|
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>",
|
|
@@ -52,13 +52,14 @@
|
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
54
|
"@athenna/common": "3.0.0",
|
|
55
|
-
"@athenna/config": "3.0.
|
|
55
|
+
"@athenna/config": "3.0.2",
|
|
56
56
|
"@athenna/ioc": "3.0.0",
|
|
57
57
|
"@japa/assert": "1.3.4",
|
|
58
58
|
"@japa/run-failed-tests": "1.0.7",
|
|
59
59
|
"@japa/runner": "2.0.7",
|
|
60
60
|
"@japa/spec-reporter": "1.1.12",
|
|
61
61
|
"c8": "7.11.2",
|
|
62
|
+
"cls-rtracer": "2.6.2",
|
|
62
63
|
"commitizen": "4.2.5",
|
|
63
64
|
"cross-env": "7.0.3",
|
|
64
65
|
"cz-conventional-changelog": "3.3.0",
|
|
@@ -8,11 +8,12 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { hostname } from 'node:os'
|
|
11
|
-
|
|
12
11
|
import { Is } from '@athenna/common'
|
|
13
|
-
|
|
12
|
+
import { createRequire } from 'node:module'
|
|
14
13
|
import { ColorHelper } from '#src/Helpers/ColorHelper'
|
|
15
14
|
|
|
15
|
+
const require = createRequire(import.meta.url)
|
|
16
|
+
|
|
16
17
|
export class Formatter {
|
|
17
18
|
/**
|
|
18
19
|
* Holds the configuration object of formatter.
|
|
@@ -57,6 +58,30 @@ export class Formatter {
|
|
|
57
58
|
return hostname()
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Get the level without any color or format.
|
|
63
|
+
*
|
|
64
|
+
* @return {string}
|
|
65
|
+
*/
|
|
66
|
+
level() {
|
|
67
|
+
return this.configs.level
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Get the trace id for formatter.
|
|
72
|
+
*
|
|
73
|
+
* @return {string | null}
|
|
74
|
+
*/
|
|
75
|
+
traceId() {
|
|
76
|
+
try {
|
|
77
|
+
const rTracer = require('cls-rtracer')
|
|
78
|
+
|
|
79
|
+
return rTracer.id()
|
|
80
|
+
} catch (err) {
|
|
81
|
+
return null
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
60
85
|
/**
|
|
61
86
|
* Create the timestamp for formatter.
|
|
62
87
|
*
|
|
@@ -95,13 +120,16 @@ export class Formatter {
|
|
|
95
120
|
|
|
96
121
|
/**
|
|
97
122
|
* Clean the message removing colors if clean
|
|
98
|
-
* option is true.
|
|
123
|
+
* option is true. If force is true, then colors
|
|
124
|
+
* will be removed even if configs clean option
|
|
125
|
+
* is false.
|
|
99
126
|
*
|
|
100
127
|
* @param message {string}
|
|
128
|
+
* @param [force] {boolean}
|
|
101
129
|
* @return {string}
|
|
102
130
|
*/
|
|
103
|
-
clean(message) {
|
|
104
|
-
if (this.configs.clean) {
|
|
131
|
+
clean(message, force = false) {
|
|
132
|
+
if (this.configs.clean || force) {
|
|
105
133
|
return ColorHelper.removeColors(message)
|
|
106
134
|
}
|
|
107
135
|
|
|
@@ -19,10 +19,11 @@ export class JsonFormatter extends Formatter {
|
|
|
19
19
|
*/
|
|
20
20
|
format(message) {
|
|
21
21
|
const base = {
|
|
22
|
-
level: this.
|
|
22
|
+
level: this.level(),
|
|
23
23
|
time: Date.now(),
|
|
24
24
|
pid: this.pid(),
|
|
25
25
|
hostname: this.hostname(),
|
|
26
|
+
traceId: this.traceId(),
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
if (Is.String(message)) {
|
|
@@ -17,12 +17,11 @@ export class SimpleFormatter extends Formatter {
|
|
|
17
17
|
* @return {string}
|
|
18
18
|
*/
|
|
19
19
|
format(message) {
|
|
20
|
+
const pid = this.pid()
|
|
21
|
+
const time = this.timestamp()
|
|
20
22
|
const level = this.simpleLevel()
|
|
23
|
+
const colorizedMsg = this.applyColors(message)
|
|
21
24
|
|
|
22
|
-
return this.clean(
|
|
23
|
-
`${level} - ${this.timestamp()} - (${this.pid()}) ${this.applyColors(
|
|
24
|
-
message,
|
|
25
|
-
)}`,
|
|
26
|
-
)
|
|
25
|
+
return this.clean(`${level} - ${time} - (${pid}) ${colorizedMsg}`)
|
|
27
26
|
}
|
|
28
27
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -126,6 +126,20 @@ export class Formatter {
|
|
|
126
126
|
*/
|
|
127
127
|
hostname(): string
|
|
128
128
|
|
|
129
|
+
/**
|
|
130
|
+
* Get the level without any color or format.
|
|
131
|
+
*
|
|
132
|
+
* @return {string}
|
|
133
|
+
*/
|
|
134
|
+
level(): string
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Get the trace id for formatter.
|
|
138
|
+
*
|
|
139
|
+
* @return {string | null}
|
|
140
|
+
*/
|
|
141
|
+
traceId(): string | null
|
|
142
|
+
|
|
129
143
|
/**
|
|
130
144
|
* Create the timestamp for formatter.
|
|
131
145
|
*
|
|
@@ -143,12 +157,15 @@ export class Formatter {
|
|
|
143
157
|
|
|
144
158
|
/**
|
|
145
159
|
* Clean the message removing colors if clean
|
|
146
|
-
* option is true.
|
|
160
|
+
* option is true. If force is true, then colors
|
|
161
|
+
* will be removed even if configs clean option
|
|
162
|
+
* is false.
|
|
147
163
|
*
|
|
148
164
|
* @param message {string}
|
|
165
|
+
* @param [force] {boolean}
|
|
149
166
|
* @return {string}
|
|
150
167
|
*/
|
|
151
|
-
clean(message
|
|
168
|
+
clean(message, force?: boolean): string
|
|
152
169
|
|
|
153
170
|
/**
|
|
154
171
|
* Apply all colors necessary to message.
|