@mhmdhammoud/meritt-utils 1.4.1 → 1.4.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/ReleaseNotes.md +4 -0
- package/dist/lib/logger.d.ts +2 -1
- package/dist/lib/logger.js +12 -3
- package/package.json +1 -1
- package/src/lib/logger.ts +16 -5
package/ReleaseNotes.md
CHANGED
package/dist/lib/logger.d.ts
CHANGED
package/dist/lib/logger.js
CHANGED
|
@@ -52,7 +52,8 @@ function getLogger(elasticConfig) {
|
|
|
52
52
|
username: process.env.ELASTICSEARCH_USERNAME,
|
|
53
53
|
password: process.env.ELASTICSEARCH_PASSWORD,
|
|
54
54
|
},
|
|
55
|
-
flushInterval:
|
|
55
|
+
flushInterval: 1000,
|
|
56
|
+
'flush-bytes': 1000,
|
|
56
57
|
};
|
|
57
58
|
if (elasticConfig) {
|
|
58
59
|
Object.assign(esConfig, elasticConfig);
|
|
@@ -63,7 +64,7 @@ function getLogger(elasticConfig) {
|
|
|
63
64
|
else {
|
|
64
65
|
transports.push(pino_1.pino.destination({
|
|
65
66
|
minLength: 1024,
|
|
66
|
-
sync:
|
|
67
|
+
sync: false,
|
|
67
68
|
}));
|
|
68
69
|
}
|
|
69
70
|
pinoLogger = (0, pino_1.pino)({
|
|
@@ -96,10 +97,18 @@ class Logger {
|
|
|
96
97
|
this._logger = getLogger(elasticConfig);
|
|
97
98
|
}
|
|
98
99
|
log(logLevel, logEvent, ...args) {
|
|
100
|
+
let detail;
|
|
101
|
+
if (process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'test') {
|
|
102
|
+
detail = args;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
//@ts-ignore
|
|
106
|
+
detail = JSON.stringify(...args);
|
|
107
|
+
}
|
|
99
108
|
this._logger[logLevel]({
|
|
100
109
|
component: this._name,
|
|
101
110
|
...logEvent,
|
|
102
|
-
detail
|
|
111
|
+
detail,
|
|
103
112
|
});
|
|
104
113
|
}
|
|
105
114
|
/**
|
package/package.json
CHANGED
package/src/lib/logger.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Logger as PinoLogger, pino, stdTimeFunctions} from 'pino'
|
|
2
2
|
import * as dotenv from 'dotenv'
|
|
3
|
-
import pinoElastic from 'pino-elasticsearch'
|
|
4
|
-
import {
|
|
3
|
+
import pinoElastic, {Options as ElasticConfig} from 'pino-elasticsearch'
|
|
4
|
+
import {LOG_LEVEL, LogEvent} from '../types'
|
|
5
5
|
|
|
6
6
|
dotenv.config()
|
|
7
7
|
|
|
@@ -27,21 +27,25 @@ function getLogger(elasticConfig?: ElasticConfig): PinoLogger {
|
|
|
27
27
|
username: process.env.ELASTICSEARCH_USERNAME,
|
|
28
28
|
password: process.env.ELASTICSEARCH_PASSWORD,
|
|
29
29
|
},
|
|
30
|
-
flushInterval:
|
|
30
|
+
flushInterval: 1000,
|
|
31
|
+
'flush-bytes': 1000,
|
|
31
32
|
}
|
|
32
33
|
if (elasticConfig) {
|
|
33
34
|
Object.assign(esConfig, elasticConfig)
|
|
34
35
|
}
|
|
36
|
+
|
|
35
37
|
const esTransport = pinoElastic(esConfig)
|
|
38
|
+
|
|
36
39
|
transports.push(esTransport)
|
|
37
40
|
} else {
|
|
38
41
|
transports.push(
|
|
39
42
|
pino.destination({
|
|
40
43
|
minLength: 1024,
|
|
41
|
-
sync:
|
|
44
|
+
sync: false,
|
|
42
45
|
})
|
|
43
46
|
)
|
|
44
47
|
}
|
|
48
|
+
|
|
45
49
|
pinoLogger = pino(
|
|
46
50
|
{
|
|
47
51
|
level: process.env.LOG_LEVEL,
|
|
@@ -95,10 +99,17 @@ class Logger {
|
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
private log(logLevel: LOG_LEVEL, logEvent: LogEvent, ...args: unknown[]) {
|
|
102
|
+
let detail
|
|
103
|
+
if (process.env.NODE_ENV === 'local' || process.env.NODE_ENV === 'test') {
|
|
104
|
+
detail = args
|
|
105
|
+
} else {
|
|
106
|
+
//@ts-ignore
|
|
107
|
+
detail = JSON.stringify(...args)
|
|
108
|
+
}
|
|
98
109
|
this._logger[logLevel]({
|
|
99
110
|
component: this._name,
|
|
100
111
|
...logEvent,
|
|
101
|
-
detail
|
|
112
|
+
detail,
|
|
102
113
|
})
|
|
103
114
|
}
|
|
104
115
|
|