@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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changes
2
2
 
3
+ ## Version 1.4.1
4
+
5
+ - Json stringify the log message if its being pushed to Kibana
6
+
3
7
  ## Version 1.4.0
4
8
 
5
9
  - Changed winston logger to Pino logger to improve performance and reduce memory usage
@@ -1,4 +1,5 @@
1
- import { ElasticConfig, LOG_LEVEL, LogEvent } from '../types';
1
+ import { Options as ElasticConfig } from 'pino-elasticsearch';
2
+ import { LOG_LEVEL, LogEvent } from '../types';
2
3
  /**
3
4
  * Checks if a given log level is valid.
4
5
  * @param level - The log level to check.
@@ -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: 10000,
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: true,
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: args,
111
+ detail,
103
112
  });
104
113
  }
105
114
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhmdhammoud/meritt-utils",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
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 {ElasticConfig, LOG_LEVEL, LogEvent} from '../types'
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: 10000,
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: true,
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: args,
112
+ detail,
102
113
  })
103
114
  }
104
115