@mhmdhammoud/meritt-utils 1.4.1 → 1.5.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.
@@ -39,5 +39,5 @@ jobs:
39
39
  password: ${{ secrets.EMAIL_PASSWORD }}
40
40
  subject: ${{ github.event.head_commit.message }} ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
41
41
  body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
42
- to: mohammad.hammoud.lb@hotmail.com,steef12009@gmail.com,sawwas.omar@gmail.com
42
+ to: mohammad.hammoud.lb@hotmail.com,steef12009@gmail.com
43
43
  from: Github Action
@@ -11,7 +11,7 @@ jobs:
11
11
  with:
12
12
  node-version: 16
13
13
  - run: npm ci
14
- - run: npm run types
14
+ - run: npm run test:types
15
15
  notify:
16
16
  needs: [type-check]
17
17
  runs-on: ubuntu-latest
@@ -25,5 +25,5 @@ jobs:
25
25
  password: ${{ secrets.EMAIL_PASSWORD }}
26
26
  subject: ${{ github.event.head_commit.message }} ${{ github.job }} job of ${{ github.repository }} has ${{ job.status }}
27
27
  body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
28
- to: mohammad.hammoud.lb@hotmail.com,steef12009@gmail.com,sawwas.omar@gmail.com
28
+ to: mohammad.hammoud.lb@hotmail.com,steef12009@gmail.com
29
29
  from: Github Action
package/.husky/pre-commit CHANGED
@@ -45,7 +45,7 @@ echo -ne '\n'
45
45
 
46
46
  echo -e "${yellow}Running types...${clear}"
47
47
  echo -ne '\n'
48
- npm run types
48
+ npm run test:types
49
49
  echo -ne '\n'
50
50
 
51
51
  echo -e "${green}types passed...${clear} ✅"
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);
@@ -62,8 +63,8 @@ function getLogger(elasticConfig) {
62
63
  }
63
64
  else {
64
65
  transports.push(pino_1.pino.destination({
65
- minLength: 1024,
66
- sync: true,
66
+ minLength: 128,
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.5.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "private": false,
@@ -13,11 +13,11 @@
13
13
  "access": "public"
14
14
  },
15
15
  "scripts": {
16
- "dev-ts": "ts-node-dev --respawn --transpile-only src/index.ts | pino-pretty",
16
+ "start:dev": "ts-node-dev --respawn --transpile-only src/index.ts | pino-pretty",
17
17
  "dev": "nodemon ./dist/index.js",
18
18
  "watch": "tsc --watch",
19
19
  "build": "tsc",
20
- "types": "tsc --noemit",
20
+ "test:types": "tsc --noemit",
21
21
  "prepare": "husky install",
22
22
  "lint": "eslint src --fix",
23
23
  "prepublish": "npm run build",
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
- minLength: 1024,
41
- sync: true,
43
+ minLength: 128,
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