@mimik/sumologic-winston-logger 2.1.5 → 2.1.7

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/README.md CHANGED
@@ -1,65 +1,66 @@
1
1
  <a name="config"></a>
2
2
 
3
3
  ## config() ⇒ <code>object</code>
4
- The following environment variables are needed to configure logger:
4
+ The following environment variables are used to configure the logger:
5
5
 
6
6
  | Env variable name | Description | Default | Comments |
7
7
  | ----------------- | ----------- | ------- | -------- |
8
- | SERVER_TYPE | Type of the server that is logged | null
9
- | SERVER_ID | Id of the server that is logged | null
10
- | NODE_ENV | Environment of the running instance | local
11
- | LOG_LEVEL | Log level of the running instance | debug
12
- | CONSOLE_LEVEL | Log level for the console of the running instance | debug
13
- | FILTER_FILE | Filename containing filter rules | null
14
- | EXIT_DELAY | Delay when exiting gracefully | 2000 | in millisecond
15
- | NO_STACK | Indicator to log the call stack on all log messages | no
16
- | LOG_MODE | String with comma separated words defining the log mode for the running instance | sumologic | (enum: awsS3, awsKinesis, sumologic, all, none)
17
-
18
- If `LOG_MODE` includes `sumologic` the following environment variables are needed:
8
+ | SERVER_TYPE | Type of the server being logged | null | |
9
+ | SERVER_ID | ID of the server being logged | null | |
10
+ | NODE_ENV | Environment of the running instance | local | |
11
+ | LOG_LEVEL | Log level for the running instance | debug | |
12
+ | CONSOLE_LEVEL | Console log level | debug | |
13
+ | FILTER_FILE | Filename containing filter rules | null | |
14
+ | EXIT_DELAY | Delay before exiting gracefully | 2000 | in milliseconds |
15
+ | NO_STACK | Whether to include call stacks in all log messages | no | expected: yes/no |
16
+ | LOG_MODE | Comma-separated list defining the log mode/backends | sumologic | enum: awsS3, awsKinesis, sumologic, all, none |
17
+
18
+ If `LOG_MODE` includes `sumologic`, the following environment variables are required:
19
19
 
20
20
  | Env variable name | Description | Default | Comments |
21
21
  | ----------------- | ----------- | ------- | -------- |
22
- | SUMO_LOGIC_ENDPOINT | URL of the sumologic collector
23
- | SUMO_LOGIC_COLLECTOR_CODE | Code of the sumologic collector
22
+ | SUMO_LOGIC_ENDPOINT | URL of the Sumo Logic collector | | |
23
+ | SUMO_LOGIC_COLLECTOR_CODE | Code of the Sumo Logic collector | | |
24
24
 
25
- If `LOG_MODE` includes `awsKinesis` the following environment variables are needed:
25
+ If `LOG_MODE` includes `awsKinesis`, the following environment variables are required:
26
26
 
27
27
  | Env variable name | Description | Default | Comments |
28
28
  | ----------------- | ----------- | ------- | -------- |
29
- | KINESIS_AWS_STREAM_NAME_INFO | Name of the stream for info level logs
30
- | KINESIS_AWS_STREAM_NAME_ERROR | Name of the stream for error level logs
31
- | KINESIS_AWS_STREAM_NAME_OTHER | Name of the stream for any other level logs
32
- | KINESIS_AWS_REGION | Region of the stream
33
- | KINESIS_AWS_TIMEOUT | Maximum time before flushing | 1000 | in millisecond
34
- | KINESIS_AWS_MAX_SIZE | Maximum size of the accumulated logs before flushing | 5 | in mByte
35
- | KINESIS_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000
36
- | KINESIS_AWS_MAX_RETRIES | Maximum retries to connect to Kinesis | 4
37
- | KINESIS_AWS_ACCESS_KEY_ID | Access key id of the stream
38
- | KINESIS_AWS_SECRET_ACCESS_KEY | Access key secret of the stream
39
- | KINESIS_AWS_HTTP_OPTIONS_SOCKET_TIMEOUT | Socket timeout for the http handler | 5000 | in millisecond
40
- | KINESIS_AWS_HTTP_OPTIONS_CONNECTION_TIMEOUT | Connection timeout for the http handler | 5000 | in millisecond
41
-
42
- If `LOG_MODE` includes `awsS3` the following environment variables are needed:
29
+ | KINESIS_AWS_STREAM_NAME_INFO | Stream name for `info` level logs | | |
30
+ | KINESIS_AWS_STREAM_NAME_ERROR | Stream name for `error` level logs | | |
31
+ | KINESIS_AWS_STREAM_NAME_OTHER | Stream name for any other level | | |
32
+ | KINESIS_AWS_REGION | AWS region of the stream | | |
33
+ | KINESIS_AWS_TIMEOUT | Maximum time before flushing | 1000 | in millisecond |
34
+ | KINESIS_AWS_MAX_SIZE | Maximum accumulated log size before flushing | 5 | in MB |
35
+ | KINESIS_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000 | |
36
+ | KINESIS_AWS_MAX_RETRIES | Maximum connection retries | 4 | |
37
+ | KINESIS_AWS_ACCESS_KEY_ID | AWS access key ID | | |
38
+ | KINESIS_AWS_SECRET_ACCESS_KEY | AWS secret access key | | |
39
+ | KINESIS_AWS_HTTP_OPTIONS_SOCKET_TIMEOUT | HTTP handler socket timeout | 5000 | in millisecond |
40
+ | KINESIS_AWS_HTTP_OPTIONS_CONNECTION_TIMEOUT | HTTP handler connection timeout | 5000 | in millisecond |
41
+
42
+ If `LOG_MODE` includes `awsS3`, the following environment variables are required:
43
43
 
44
44
  | Env variable name | Description | Default | Comments |
45
45
  | ----------------- | ----------- | ------- | -------- |
46
- | S3_AWS_BUCKET_NAME | Name of the bucket for storing the logs
47
- | S3_AWS_REGION | Region of the bucket
48
- | S3_AWS_TIMEOUT | Maximum time before flushing | 5 | in minute
49
- | S3_AWS_MAX_SIZE | Maximum size of the accumulated logs before flushing | 5 | in mByte
50
- | S3_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000
51
- | S3_AWS_ACCESS_KEY_ID | Access key id of the bucket
52
- | S3_AWS_SECRET_ACCESS_KEY | Access key secret of the bucket
53
-
54
- When `LOG_MODE` is `none` the logs will only be on `console`.
55
- When `LOG_MODE` is `all` LOG_MODE will be set to `sumologic, awsS3`.
56
-
57
- The SERVER_TYPE and SERVER_ID are used to create the S3 filename and are inserted in the payload of the log for S3 and Kinesis.
58
- If `global.serverType` is set, this value is used over SERVER_TYPE.
59
- If `global.serverType` is set, the value of `global.serverId` is used over `SERVER_ID`.
46
+ | S3_AWS_BUCKET_NAME | S3 bucket name for storing logs | | |
47
+ | S3_AWS_REGION | AWS region of the bucket | | |
48
+ | S3_AWS_TIMEOUT | Maximum time before flushing | 5 | in minute |
49
+ | S3_AWS_MAX_SIZE | Maximum accumulated log size before flushing | 5 | in MB |
50
+ | S3_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000 | |
51
+ | S3_AWS_ACCESS_KEY_ID | AWS access key ID | | |
52
+ | S3_AWS_SECRET_ACCESS_KEY | AWS secret access key | | |
53
+
54
+ When `LOG_MODE` is `none`, logs are written to the console only.
55
+ When `LOG_MODE` is `all`, it is equivalent to `sumologic,awsS3`.
56
+
57
+ `SERVER_TYPE` and `SERVER_ID` are used to build the S3 filename and are included in the
58
+ log payload for S3 and Kinesis.
59
+ If `global.serverType` is set, it overrides `SERVER_TYPE`.
60
+ If `global.serverId` is set, it overrides `SERVER_ID`.
60
61
 
61
62
  **Kind**: global function
62
- **Returns**: <code>object</code> - configuration - logger configuration.
63
+ **Returns**: <code>object</code> - configuration - Logger configuration.
63
64
 
64
65
  ## Synopsis ##
65
66
 
@@ -4,95 +4,82 @@ import {
4
4
  ALL_MODES,
5
5
  AWS_KINESIS,
6
6
  AWS_S3,
7
- DEFAULT_ENV,
8
- DEFAULT_EXIT_DELAY,
9
- DEFAULT_FILTER_FILE,
10
- DEFAULT_KINESIS_HTTP_OPTIONS_CONNECTION_TIMEOUT,
11
- DEFAULT_KINESIS_HTTP_OPTIONS_SOCKET_TIMEOUT,
12
- DEFAULT_KINESIS_MAX_EVENTS,
13
- DEFAULT_KINESIS_MAX_RETRIES,
14
- DEFAULT_KINESIS_MAX_SIZE,
15
- DEFAULT_KINESIS_TIMEOUT,
16
- DEFAULT_LEVEL,
17
- DEFAULT_MODE,
18
- DEFAULT_NO_STACK,
19
- DEFAULT_S3_MAX_EVENTS,
20
- DEFAULT_S3_MAX_SIZE,
21
- DEFAULT_S3_TIMEOUT,
7
+ DEFAULT,
22
8
  NONE_MODE,
23
9
  SUMOLOGIC,
24
10
  } from '../lib/common.js';
25
11
  import difference from 'lodash.difference';
26
- import fs from 'fs';
27
12
  import isNil from 'lodash.isnil';
28
13
  import isUndefined from 'lodash.isundefined';
29
- import process from 'process';
14
+ import process from 'node:process';
15
+ import { readFileSync } from 'node:fs';
30
16
  import split from 'lodash.split';
31
17
 
32
18
  const DECIMAL = 10;
33
19
 
34
20
  /**
35
21
  *
36
- * logger Configuration.
22
+ * Logger configuration.
37
23
  *
38
24
  * @function config
39
- * @return {object} configuration - logger configuration.
40
- * @description The following environment variables are needed to configure logger:
25
+ * @return {object} configuration - Logger configuration.
26
+ * @description The following environment variables are used to configure the logger:
41
27
  *
42
28
  * | Env variable name | Description | Default | Comments |
43
29
  * | ----------------- | ----------- | ------- | -------- |
44
- * | SERVER_TYPE | Type of the server that is logged | null
45
- * | SERVER_ID | Id of the server that is logged | null
46
- * | NODE_ENV | Environment of the running instance | local
47
- * | LOG_LEVEL | Log level of the running instance | debug
48
- * | CONSOLE_LEVEL | Log level for the console of the running instance | debug
49
- * | FILTER_FILE | Filename containing filter rules | null
50
- * | EXIT_DELAY | Delay when exiting gracefully | 2000 | in millisecond
51
- * | NO_STACK | Indicator to log the call stack on all log messages | no
52
- * | LOG_MODE | String with comma separated words defining the log mode for the running instance | sumologic | (enum: awsS3, awsKinesis, sumologic, all, none)
30
+ * | SERVER_TYPE | Type of the server being logged | null | |
31
+ * | SERVER_ID | ID of the server being logged | null | |
32
+ * | NODE_ENV | Environment of the running instance | local | |
33
+ * | LOG_LEVEL | Log level for the running instance | debug | |
34
+ * | CONSOLE_LEVEL | Console log level | debug | |
35
+ * | FILTER_FILE | Filename containing filter rules | null | |
36
+ * | EXIT_DELAY | Delay before exiting gracefully | 2000 | in milliseconds |
37
+ * | NO_STACK | Whether to include call stacks in all log messages | no | expected: yes/no |
38
+ * | LOG_MODE | Comma-separated list defining the log mode/backends | sumologic | enum: awsS3, awsKinesis, sumologic, all, none |
53
39
  *
54
- * If `LOG_MODE` includes `sumologic` the following environment variables are needed:
40
+ * If `LOG_MODE` includes `sumologic`, the following environment variables are required:
55
41
  *
56
42
  * | Env variable name | Description | Default | Comments |
57
43
  * | ----------------- | ----------- | ------- | -------- |
58
- * | SUMO_LOGIC_ENDPOINT | URL of the sumologic collector
59
- * | SUMO_LOGIC_COLLECTOR_CODE | Code of the sumologic collector
44
+ * | SUMO_LOGIC_ENDPOINT | URL of the Sumo Logic collector | | |
45
+ * | SUMO_LOGIC_COLLECTOR_CODE | Code of the Sumo Logic collector | | |
60
46
  *
61
- * If `LOG_MODE` includes `awsKinesis` the following environment variables are needed:
47
+ * If `LOG_MODE` includes `awsKinesis`, the following environment variables are required:
62
48
  *
63
49
  * | Env variable name | Description | Default | Comments |
64
50
  * | ----------------- | ----------- | ------- | -------- |
65
- * | KINESIS_AWS_STREAM_NAME_INFO | Name of the stream for info level logs
66
- * | KINESIS_AWS_STREAM_NAME_ERROR | Name of the stream for error level logs
67
- * | KINESIS_AWS_STREAM_NAME_OTHER | Name of the stream for any other level logs
68
- * | KINESIS_AWS_REGION | Region of the stream
69
- * | KINESIS_AWS_TIMEOUT | Maximum time before flushing | 1000 | in millisecond
70
- * | KINESIS_AWS_MAX_SIZE | Maximum size of the accumulated logs before flushing | 5 | in mByte
71
- * | KINESIS_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000
72
- * | KINESIS_AWS_MAX_RETRIES | Maximum retries to connect to Kinesis | 4
73
- * | KINESIS_AWS_ACCESS_KEY_ID | Access key id of the stream
74
- * | KINESIS_AWS_SECRET_ACCESS_KEY | Access key secret of the stream
75
- * | KINESIS_AWS_HTTP_OPTIONS_SOCKET_TIMEOUT | Socket timeout for the http handler | 5000 | in millisecond
76
- * | KINESIS_AWS_HTTP_OPTIONS_CONNECTION_TIMEOUT | Connection timeout for the http handler | 5000 | in millisecond
51
+ * | KINESIS_AWS_STREAM_NAME_INFO | Stream name for `info` level logs | | |
52
+ * | KINESIS_AWS_STREAM_NAME_ERROR | Stream name for `error` level logs | | |
53
+ * | KINESIS_AWS_STREAM_NAME_OTHER | Stream name for any other level | | |
54
+ * | KINESIS_AWS_REGION | AWS region of the stream | | |
55
+ * | KINESIS_AWS_TIMEOUT | Maximum time before flushing | 1000 | in millisecond |
56
+ * | KINESIS_AWS_MAX_SIZE | Maximum accumulated log size before flushing | 5 | in MB |
57
+ * | KINESIS_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000 | |
58
+ * | KINESIS_AWS_MAX_RETRIES | Maximum connection retries | 4 | |
59
+ * | KINESIS_AWS_ACCESS_KEY_ID | AWS access key ID | | |
60
+ * | KINESIS_AWS_SECRET_ACCESS_KEY | AWS secret access key | | |
61
+ * | KINESIS_AWS_HTTP_OPTIONS_SOCKET_TIMEOUT | HTTP handler socket timeout | 5000 | in millisecond |
62
+ * | KINESIS_AWS_HTTP_OPTIONS_CONNECTION_TIMEOUT | HTTP handler connection timeout | 5000 | in millisecond |
77
63
  *
78
- * If `LOG_MODE` includes `awsS3` the following environment variables are needed:
64
+ * If `LOG_MODE` includes `awsS3`, the following environment variables are required:
79
65
  *
80
66
  * | Env variable name | Description | Default | Comments |
81
67
  * | ----------------- | ----------- | ------- | -------- |
82
- * | S3_AWS_BUCKET_NAME | Name of the bucket for storing the logs
83
- * | S3_AWS_REGION | Region of the bucket
84
- * | S3_AWS_TIMEOUT | Maximum time before flushing | 5 | in minute
85
- * | S3_AWS_MAX_SIZE | Maximum size of the accumulated logs before flushing | 5 | in mByte
86
- * | S3_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000
87
- * | S3_AWS_ACCESS_KEY_ID | Access key id of the bucket
88
- * | S3_AWS_SECRET_ACCESS_KEY | Access key secret of the bucket
68
+ * | S3_AWS_BUCKET_NAME | S3 bucket name for storing logs | | |
69
+ * | S3_AWS_REGION | AWS region of the bucket | | |
70
+ * | S3_AWS_TIMEOUT | Maximum time before flushing | 5 | in minute |
71
+ * | S3_AWS_MAX_SIZE | Maximum accumulated log size before flushing | 5 | in MB |
72
+ * | S3_AWS_MAX_EVENTS | Maximum number of accumulated logs before flushing | 1000 | |
73
+ * | S3_AWS_ACCESS_KEY_ID | AWS access key ID | | |
74
+ * | S3_AWS_SECRET_ACCESS_KEY | AWS secret access key | | |
89
75
  *
90
- * When `LOG_MODE` is `none` the logs will only be on `console`.
91
- * When `LOG_MODE` is `all` LOG_MODE will be set to `sumologic, awsS3`.
76
+ * When `LOG_MODE` is `none`, logs are written to the console only.
77
+ * When `LOG_MODE` is `all`, it is equivalent to `sumologic,awsS3`.
92
78
  *
93
- * The SERVER_TYPE and SERVER_ID are used to create the S3 filename and are inserted in the payload of the log for S3 and Kinesis.
94
- * If `global.serverType` is set, this value is used over SERVER_TYPE.
95
- * If `global.serverType` is set, the value of `global.serverId` is used over `SERVER_ID`.
79
+ * `SERVER_TYPE` and `SERVER_ID` are used to build the S3 filename and are included in the
80
+ * log payload for S3 and Kinesis.
81
+ * If `global.serverType` is set, it overrides `SERVER_TYPE`.
82
+ * If `global.serverId` is set, it overrides `SERVER_ID`.
96
83
  */
97
84
 
98
85
  const checkConfig = (config) => {
@@ -131,18 +118,18 @@ const configuration = {
131
118
  type: process.env.SERVER_TYPE || null,
132
119
  id: process.env.SERVER_ID || null,
133
120
  },
134
- env: process.env.NODE_ENV || DEFAULT_ENV,
121
+ env: process.env.NODE_ENV || DEFAULT.ENV,
135
122
  level: {
136
- log: process.env.LOG_LEVEL || DEFAULT_LEVEL,
137
- console: process.env.CONSOLE_LEVEL || DEFAULT_LEVEL,
123
+ log: process.env.LOG_LEVEL || DEFAULT.LEVEL,
124
+ console: process.env.CONSOLE_LEVEL || DEFAULT.LEVEL,
138
125
  },
139
126
  filter: {
140
- file: process.env.FILTER_FILE || DEFAULT_FILTER_FILE,
127
+ file: process.env.FILTER_FILE || DEFAULT.FILTER_FILE,
141
128
  },
142
- exitDelay: parseInt(process.env.EXIT_DELAY, DECIMAL) || DEFAULT_EXIT_DELAY, // in millisecond
143
- noStack: process.env.NO_STACK || DEFAULT_NO_STACK,
129
+ exitDelay: parseInt(process.env.EXIT_DELAY, DECIMAL) || DEFAULT.EXIT_DELAY, // in millisecond
130
+ noStack: process.env.NO_STACK || DEFAULT.NO_STACK,
144
131
  };
145
- configuration.mode = checkMode(process.env.LOG_MODE) || DEFAULT_MODE;
132
+ configuration.mode = checkMode(process.env.LOG_MODE) || DEFAULT.MODE;
146
133
 
147
134
  if (configuration.mode.includes(SUMOLOGIC)) {
148
135
  configuration[SUMOLOGIC] = {
@@ -156,13 +143,13 @@ if (configuration.mode.includes(AWS_KINESIS)) {
156
143
  streamNameError: process.env.KINESIS_AWS_STREAM_NAME_ERROR,
157
144
  streamNameOther: process.env.KINESIS_AWS_STREAM_NAME_OTHER,
158
145
  region: process.env.KINESIS_AWS_REGION,
159
- timeout: parseInt(process.env.KINESIS_AWS_TIMEOUT, DECIMAL) || DEFAULT_KINESIS_TIMEOUT, // in millisecond
160
- maxSize: parseInt(process.env.KINESIS_AWS_MAX_SIZE, DECIMAL) || DEFAULT_KINESIS_MAX_SIZE, // in mByte
161
- maxEvents: parseInt(process.env.KINESIS_AWS_MAX_EVENTS, DECIMAL) || DEFAULT_KINESIS_MAX_EVENTS,
162
- maxRetries: parseInt(process.env.KINESIS_AWS_MAX_RETRIES, DECIMAL) || DEFAULT_KINESIS_MAX_RETRIES,
146
+ timeout: parseInt(process.env.KINESIS_AWS_TIMEOUT, DECIMAL) || DEFAULT.KINESIS_TIMEOUT, // in millisecond
147
+ maxSize: parseInt(process.env.KINESIS_AWS_MAX_SIZE, DECIMAL) || DEFAULT.KINESIS_MAX_SIZE, // in mByte
148
+ maxEvents: parseInt(process.env.KINESIS_AWS_MAX_EVENTS, DECIMAL) || DEFAULT.KINESIS_MAX_EVENTS,
149
+ maxRetries: parseInt(process.env.KINESIS_AWS_MAX_RETRIES, DECIMAL) || DEFAULT.KINESIS_MAX_RETRIES,
163
150
  httpOptions: {
164
- socketTimeout: parseInt(process.env.KINESIS_AWS_HTTP_OPTIONS_SOCKET_TIMEOUT, DECIMAL) || DEFAULT_KINESIS_HTTP_OPTIONS_SOCKET_TIMEOUT,
165
- connectionTimeout: parseInt(process.env.KINESIS_AWS_HTTP_OPTIONS_CONNECTION_TIMEOUT, DECIMAL) || DEFAULT_KINESIS_HTTP_OPTIONS_CONNECTION_TIMEOUT,
151
+ socketTimeout: parseInt(process.env.KINESIS_AWS_HTTP_OPTIONS_SOCKET_TIMEOUT, DECIMAL) || DEFAULT.KINESIS_HTTP_OPTIONS_SOCKET_TIMEOUT,
152
+ connectionTimeout: parseInt(process.env.KINESIS_AWS_HTTP_OPTIONS_CONNECTION_TIMEOUT, DECIMAL) || DEFAULT.KINESIS_HTTP_OPTIONS_CONNECTION_TIMEOUT,
166
153
  },
167
154
  };
168
155
 
@@ -173,9 +160,9 @@ if (configuration.mode.includes(AWS_S3)) {
173
160
  configuration[AWS_S3] = {
174
161
  bucketname: process.env.S3_AWS_BUCKET_NAME,
175
162
  region: process.env.S3_AWS_REGION,
176
- timeout: parseInt(process.env.S3_AWS_TIMEOUT, DECIMAL) || DEFAULT_S3_TIMEOUT, // in minute
177
- maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, DECIMAL) || DEFAULT_S3_MAX_SIZE, // in mByte
178
- maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, DECIMAL) || DEFAULT_S3_MAX_EVENTS,
163
+ timeout: parseInt(process.env.S3_AWS_TIMEOUT, DECIMAL) || DEFAULT.S3_TIMEOUT, // in minute
164
+ maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, DECIMAL) || DEFAULT.S3_MAX_SIZE, // in mByte
165
+ maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, DECIMAL) || DEFAULT.S3_MAX_EVENTS,
179
166
  };
180
167
 
181
168
  if (!isNil(process.env.S3_AWS_ACCESS_KEY_ID)) configuration[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
@@ -186,10 +173,10 @@ let filterConfig = [];
186
173
 
187
174
  if (filter.file) {
188
175
  try {
189
- filterConfig = JSON.parse(fs.readFileSync(filter.file).toString());
176
+ filterConfig = JSON.parse(readFileSync(filter.file).toString());
190
177
  }
191
178
  catch (err) {
192
- throw new Error(`Invalid file for logger config: ${filter.file}, error: ${err.message}`);
179
+ throw new Error(`Invalid file for logger config: ${filter.file}`, { cause: err });
193
180
  }
194
181
  }
195
182
  filter.config = filterConfig;
package/eslint.config.js CHANGED
@@ -11,6 +11,7 @@ const MAX_STATEMENTS_IN_FUNCTION = 45;
11
11
  const MIN_KEYS_IN_OBJECT = 10;
12
12
  const MAX_COMPLEXITY = 30;
13
13
  const ECMA_VERSION = 2022;
14
+ const MAX_DEPTH = 6;
14
15
  const ALLOWED_CONSTANTS = [0, 1, -1];
15
16
 
16
17
  export default [
@@ -37,6 +38,7 @@ export default [
37
38
  rules: {
38
39
  '@stylistic/brace-style': ['warn', 'stroustrup', { allowSingleLine: true }],
39
40
  '@stylistic/line-comment-position': ['off'],
41
+ '@stylistic/max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreStrings: true, ignoreRegExpLiterals: true }],
40
42
  '@stylistic/semi': ['error', 'always'],
41
43
  'capitalized-comments': ['off'],
42
44
  'complexity': ['error', MAX_COMPLEXITY],
@@ -46,9 +48,9 @@ export default [
46
48
  'import/no-unresolved': ['error', { amd: true, caseSensitiveStrict: true, commonjs: true }],
47
49
  'init-declarations': ['off'],
48
50
  'linebreak-style': ['off'],
49
- 'max-len': ['warn', MAX_LENGTH_LINE, { ignoreComments: true, ignoreRegExpLiterals: true }],
50
- 'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true }],
51
- 'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true }],
51
+ 'max-depth': ['error', MAX_DEPTH],
52
+ 'max-lines': ['warn', { max: MAX_LINES_IN_FILES, skipComments: true, skipBlankLines: true }],
53
+ 'max-lines-per-function': ['warn', { max: MAX_LINES_IN_FUNCTION, skipComments: true, skipBlankLines: true }],
52
54
  'max-params': ['error', MAX_FUNCTION_PARAMETERS],
53
55
  'max-statements': ['warn', MAX_STATEMENTS_IN_FUNCTION],
54
56
  'no-confusing-arrow': ['off'],
@@ -60,7 +62,8 @@ export default [
60
62
  'one-var': ['error', 'never'],
61
63
  'processDoc/validate-document-env': ['error'],
62
64
  'quotes': ['warn', 'single'],
63
- 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false }],
65
+ 'sort-imports': ['error', { allowSeparatedGroups: true }],
66
+ 'sort-keys': ['error', 'asc', { caseSensitive: true, minKeys: MIN_KEYS_IN_OBJECT, natural: false, allowLineSeparatedGroups: true }],
64
67
  },
65
68
  },
66
69
  ];
package/index.js CHANGED
@@ -18,13 +18,12 @@ import {
18
18
  format,
19
19
  transports,
20
20
  } from 'winston';
21
-
22
21
  import AwsKinesis from './lib/awsKinesisTransport.js';
23
22
  import AwsS3 from './lib/awsS3Transport.js';
24
23
  import Sumologic from './lib/sumologicTransport.js';
25
24
  import config from './configuration/config.js';
26
- import process from 'process';
27
- import { setTimeout } from 'timers';
25
+ import process from 'node:process';
26
+ import { setTimeout } from 'node:timers';
28
27
 
29
28
  let sumo;
30
29
  let awsS3;
@@ -4,6 +4,7 @@ import {
4
4
  ERROR,
5
5
  INFO,
6
6
  LOG,
7
+ MEGA,
7
8
  MESSAGE,
8
9
  OTHER,
9
10
  PARTITION_KEY,
@@ -19,15 +20,14 @@ import {
19
20
  import {
20
21
  setImmediate,
21
22
  setInterval,
22
- } from 'timers';
23
- import { Buffer } from 'buffer';
23
+ } from 'node:timers';
24
+ import { Buffer } from 'node:buffer';
24
25
  import { NodeHttpHandler } from '@smithy/node-http-handler';
25
26
  import Promise from 'bluebird';
26
27
  import Transport from 'winston-transport';
27
28
 
28
29
  const RANDOM_MIN = 0;
29
30
  const RANDOM_LIMIT = 100;
30
- const MEGA = 1048576; // 2^20 conversion to mega
31
31
 
32
32
  const events = {};
33
33
 
@@ -2,6 +2,7 @@ import {
2
2
  AWS_S3,
3
3
  CLIENTS,
4
4
  LOG,
5
+ MEGA,
5
6
  MESSAGE,
6
7
  SYSTEM_ERROR,
7
8
  UNKNOWN_ID,
@@ -15,14 +16,13 @@ import {
15
16
  import {
16
17
  setImmediate,
17
18
  setInterval,
18
- } from 'timers';
19
+ } from 'node:timers';
19
20
  import Promise from 'bluebird';
20
21
  import Transport from 'winston-transport';
21
22
 
22
23
  const events = {};
23
24
  const typeEvents = {};
24
25
 
25
- const MEGA = 1048576; // 2^20 conversion to mega
26
26
  const MILLI_MIN = 60000; // 1000*60 conversion to minute
27
27
 
28
28
  export default class AwsS3 extends Transport {
package/lib/common.js CHANGED
@@ -1,30 +1,32 @@
1
+ /* eslint-disable no-magic-numbers */
1
2
  const ENV_DEV = ['development', 'dev'];
2
3
  const ENV_LOCAL = 'local';
3
4
 
4
- const DEFAULT_LEVEL = 'debug';
5
- const DEFAULT_ENV = ENV_LOCAL;
6
- const DEFAULT_FILTER_FILE = null;
7
-
8
5
  const ALL_MODE = 'all'; // legacy support
9
6
  const NONE_MODE = 'none';
10
7
  const AWS_S3 = 'awsS3';
11
8
  const SUMOLOGIC = 'sumologic';
12
9
  const AWS_KINESIS = 'awsKinesis';
13
- const DEFAULT_MODE = [NONE_MODE];
14
10
  const ALL_MODES = [AWS_S3, SUMOLOGIC, AWS_KINESIS, ALL_MODE, NONE_MODE];
15
11
 
16
- const DEFAULT_S3_MAX_SIZE = 5; // max size of the data before sending to S3, in mByte
17
- const DEFAULT_S3_MAX_EVENTS = 1000; // max number of events before sending to S3
18
- const DEFAULT_S3_TIMEOUT = 5; // max time before sending events to S3, in minute
19
- const DEFAULT_KINESIS_HTTP_OPTIONS_SOCKET_TIMEOUT = 5000; // socket timeout for the http handler, in millisecond
20
- const DEFAULT_KINESIS_HTTP_OPTIONS_CONNECTION_TIMEOUT = 5000; // connection timeout for the http handler, in millisecond
21
- const DEFAULT_KINESIS_MAX_SIZE = 5; // max size of the data before sending to Kinesis, in mByte
22
- const DEFAULT_KINESIS_MAX_EVENTS = 1000; // max number of events before sending to Kinesis
23
- const DEFAULT_KINESIS_MAX_RETRIES = 4; // max retries to connect to Kinesis
24
- const DEFAULT_KINESIS_TIMEOUT = 1000; // max time before sending events to Kinesis, in millisecond
12
+ const DEFAULT = {
13
+ ENV: ENV_LOCAL,
14
+ FILTER_FILE: null,
15
+ LEVEL: 'debug',
16
+ MODE: [NONE_MODE],
17
+ NO_STACK: 'yes',
25
18
 
26
- const DEFAULT_EXIT_DELAY = 2000; // delay for flushing the transports and exiting, in millisecond
27
- const DEFAULT_NO_STACK = 'yes';
19
+ EXIT_DELAY: 2000, // delay for flushing the transports and exiting, in millisecond
20
+ KINESIS_HTTP_OPTIONS_CONNECTION_TIMEOUT: 5000, // connection timeout for the http handler, in millisecond
21
+ KINESIS_HTTP_OPTIONS_SOCKET_TIMEOUT: 5000, // socket timeout for the http handler, in millisecond
22
+ KINESIS_MAX_EVENTS: 1000, // max number of events before sending to Kinesis
23
+ KINESIS_MAX_RETRIES: 4, // max retries to connect to Kinesis
24
+ KINESIS_MAX_SIZE: 5, // max size of the data before sending to Kinesis, in mByte
25
+ KINESIS_TIMEOUT: 1000, // max time before sending events to Kinesis, in millisecond
26
+ S3_MAX_EVENTS: 1000, // max number of events before sending to S3
27
+ S3_MAX_SIZE: 5, // max size of the data before sending to S3, in mByte
28
+ S3_TIMEOUT: 5, // max time before sending events to S3, in minute
29
+ };
28
30
 
29
31
  const SPLAT = Symbol.for('splat');
30
32
  const LEVEL = Symbol.for('level');
@@ -44,44 +46,44 @@ const INFO = 'info';
44
46
  const ERROR = 'error';
45
47
  const OTHER = 'other';
46
48
 
49
+ const UNAUTHORIZED_ERROR = 401;
50
+ const NOT_FOUND_ERROR = 404;
47
51
  const SYSTEM_ERROR = 500;
48
52
 
53
+ const START_TIMEOUT = 30000; // in millisecond
54
+ const FLUSH_TIMEOUT = 1000; // in millisecond
55
+ const OK_EXIT = 0;
56
+
57
+ const MEGA = 1048576; // 2^20 conversion to mega
58
+
49
59
  export {
50
60
  ALL_MODE,
51
61
  ALL_MODES,
52
62
  AWS_KINESIS,
53
63
  AWS_S3,
54
64
  CLIENTS,
55
- DEFAULT_ENV,
56
- DEFAULT_EXIT_DELAY,
57
- DEFAULT_FILTER_FILE,
58
- DEFAULT_KINESIS_MAX_EVENTS,
59
- DEFAULT_KINESIS_MAX_RETRIES,
60
- DEFAULT_KINESIS_MAX_SIZE,
61
- DEFAULT_KINESIS_TIMEOUT,
62
- DEFAULT_KINESIS_HTTP_OPTIONS_SOCKET_TIMEOUT,
63
- DEFAULT_KINESIS_HTTP_OPTIONS_CONNECTION_TIMEOUT,
64
- DEFAULT_LEVEL,
65
- DEFAULT_MODE,
66
- DEFAULT_NO_STACK,
67
- DEFAULT_S3_MAX_EVENTS,
68
- DEFAULT_S3_MAX_SIZE,
69
- DEFAULT_S3_TIMEOUT,
65
+ DEFAULT,
70
66
  ENV_DEV,
71
67
  ENV_LOCAL,
72
68
  ERROR,
73
69
  FLUSH,
74
70
  FLUSH_EXIT,
71
+ FLUSH_TIMEOUT,
75
72
  INFO,
76
73
  LEVEL,
77
74
  LOG,
75
+ MEGA,
78
76
  MESSAGE,
79
77
  NONE_MODE,
78
+ NOT_FOUND_ERROR,
79
+ OK_EXIT,
80
80
  OTHER,
81
81
  PARTITION_KEY,
82
82
  SPLAT,
83
+ START_TIMEOUT,
83
84
  SUMOLOGIC,
84
85
  SYSTEM_ERROR,
86
+ UNAUTHORIZED_ERROR,
85
87
  UNKNOWN_TYPE,
86
88
  UNKNOWN_ID,
87
89
  WARN,
package/lib/stackLib.js CHANGED
@@ -1,8 +1,6 @@
1
- import crypto from 'crypto';
2
- import {
3
- fileURLToPath,
4
- } from 'url';
5
- import path from 'path';
1
+ import { basename } from 'node:path';
2
+ import { createHash } from 'node:crypto';
3
+ import { fileURLToPath } from 'node:url';
6
4
  import reject from 'lodash.reject';
7
5
 
8
6
  // Stack trace format :
@@ -43,10 +41,10 @@ const parseStack = (newError) => {
43
41
  path: stackParts[PATH],
44
42
  line: stackParts[LINE],
45
43
  pos: stackParts[POSITION],
46
- file: path.basename(stackParts[PATH]),
44
+ file: basename(stackParts[PATH]),
47
45
  stack: `${SHIFT}${truncatedList.join('\n').trimStart()}`,
48
46
  };
49
- stackInfo.hash = crypto.createHash('sha256', SECRET)
47
+ stackInfo.hash = createHash('sha256', SECRET)
50
48
  .update(stackInfo.stack)
51
49
  .digest('hex');
52
50
  // this is a hash of the stacktrace for easier searching for the stacktrace
@@ -1,21 +1,18 @@
1
1
  import {
2
2
  CLIENTS,
3
3
  LOG,
4
+ NOT_FOUND_ERROR,
4
5
  SPLAT,
5
6
  SUMOLOGIC,
7
+ SYSTEM_ERROR,
8
+ UNAUTHORIZED_ERROR,
6
9
  UNKNOWN_ID,
7
10
  UNKNOWN_TYPE,
8
11
  WARN,
9
12
  } from './common.js';
10
13
  import Transport from 'winston-transport';
11
14
  import axios from 'axios';
12
- import {
13
- setImmediate,
14
- } from 'timers';
15
-
16
- const UNAUTHORIZED_ERROR = 401;
17
- const NOTFOUND_ERROR = 404;
18
- const SYSTEM_ERROR = 500;
15
+ import { setImmediate } from 'node:timers';
19
16
 
20
17
  export default class Sumo extends Transport {
21
18
  constructor(options = {}) {
@@ -65,7 +62,7 @@ export default class Sumo extends Transport {
65
62
  resp.error.message = `invalid ${SUMOLOGIC} code`;
66
63
  resp.code = this.code;
67
64
  }
68
- else if (status === NOTFOUND_ERROR) resp.error.message = `invalid ${SUMOLOGIC} endpoint`;
65
+ else if (status === NOT_FOUND_ERROR) resp.error.message = `invalid ${SUMOLOGIC} endpoint`;
69
66
  else resp.error.message = `could not log to ${SUMOLOGIC}`;
70
67
  return this.emit(WARN, resp);
71
68
  });
@@ -1,9 +1,8 @@
1
1
  /* eslint-disable no-console */
2
2
  import '../test/testEnv.js';
3
- import clone from 'lodash.clone';
4
3
  import { getCorrelationId } from '@mimik/request-helper';
5
4
  import logger from '../index.js';
6
- import process from 'process';
5
+ import process from 'node:process';
7
6
 
8
7
  const user = {
9
8
  name: 'a name',
@@ -28,7 +27,7 @@ logger.debug('This is a test with error', { user }, correlationId);
28
27
  logger.error('This is a test, error', { user }, correlationId);
29
28
 
30
29
  stdin.addListener('data', () => {
31
- const clonedObject = clone(user);
30
+ const clonedObject = { ...user };
32
31
 
33
32
  clonedObject.index = 'manual';
34
33
  console.log('manual logging');
@@ -1,7 +1,6 @@
1
1
  /* eslint-disable no-console */
2
2
  import '../test/testEnv.js';
3
3
  import Promise from 'bluebird';
4
- import clone from 'lodash.clone';
5
4
  import { getCorrelationId } from '@mimik/request-helper';
6
5
  import logger from '../index.js';
7
6
 
@@ -28,7 +27,7 @@ const object = {
28
27
  const objects = [];
29
28
 
30
29
  for (let i = 0; i < MAX_ITEMS; i += 1) {
31
- const clonedObject = clone(object);
30
+ const clonedObject = { ...object };
32
31
 
33
32
  clonedObject.index = i;
34
33
  objects.push(clonedObject);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mimik/sumologic-winston-logger",
3
- "version": "2.1.5",
3
+ "version": "2.1.7",
4
4
  "description": "Log wrapper for sumo, s3, kinesis and winston",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -34,10 +34,10 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@mimik/lib-filters": "^2.0.4",
37
- "@aws-sdk/client-s3": "3.878.0",
38
- "@aws-sdk/client-kinesis": "3.876.0",
39
- "@smithy/node-http-handler": "4.1.1",
40
- "axios": "1.11.0",
37
+ "@aws-sdk/client-s3": "3.888.0",
38
+ "@aws-sdk/client-kinesis": "3.888.0",
39
+ "@smithy/node-http-handler": "4.2.1",
40
+ "axios": "1.12.2",
41
41
  "bluebird": "3.7.2",
42
42
  "lodash.difference": "4.5.0",
43
43
  "lodash.foreach": "4.5.0",
@@ -51,20 +51,19 @@
51
51
  "winston-transport": "4.9.0"
52
52
  },
53
53
  "devDependencies": {
54
- "@eslint/js": "9.34.0",
54
+ "@eslint/js": "9.35.0",
55
55
  "@mimik/eslint-plugin-document-env": "^2.0.8",
56
56
  "@mimik/request-helper": "^2.0.2",
57
- "@stylistic/eslint-plugin": "5.2.3",
57
+ "@stylistic/eslint-plugin": "5.3.1",
58
58
  "body-parser": "2.2.0",
59
59
  "c8": "10.1.3",
60
60
  "chai": "6.0.1",
61
- "eslint": "9.34.0",
61
+ "eslint": "9.35.0",
62
62
  "eslint-plugin-import": "2.32.0",
63
63
  "express": "5.1.0",
64
64
  "husky": "9.1.7",
65
65
  "jsdoc-to-markdown": "9.1.2",
66
- "lodash.clone": "4.5.0",
67
- "mocha": "11.7.1",
66
+ "mocha": "11.7.2",
68
67
  "mochawesome": "7.1.3",
69
68
  "sinon": "21.0.0",
70
69
  "supertest": "7.1.4"
@@ -1,16 +1,13 @@
1
1
  import './testEnv.js';
2
+ import { FLUSH_TIMEOUT, OK_EXIT, START_TIMEOUT } from '../lib/common.js';
2
3
  import { before, describe, it } from 'mocha';
3
4
  import { getCorrelationId } from '@mimik/request-helper';
4
5
  import logger from '../index.js';
5
- import process from 'process';
6
- import { setTimeout } from 'timers';
6
+ import process from 'node:process';
7
+ import { setTimeout } from 'node:timers';
7
8
  import { should } from 'chai';
8
9
  import { stub } from 'sinon';
9
10
 
10
- const START_TIMEOUT = 30000;
11
- const FLUSH_TIMEOUT = 1000;
12
- const OK_EXIT = 0;
13
-
14
11
  const correlationId = getCorrelationId('--sumologic-winston-logger-test--');
15
12
 
16
13
  should();
@@ -1,16 +1,13 @@
1
1
  import './testEnvProdFilter.js';
2
+ import { FLUSH_TIMEOUT, OK_EXIT, START_TIMEOUT } from '../lib/common.js';
2
3
  import { before, describe, it } from 'mocha';
3
4
  import { getCorrelationId } from '@mimik/request-helper';
4
5
  import logger from '../index.js';
5
- import process from 'process';
6
- import { setTimeout } from 'timers';
6
+ import process from 'node:process';
7
+ import { setTimeout } from 'node:timers';
7
8
  import { should } from 'chai';
8
9
  import { stub } from 'sinon';
9
10
 
10
- const START_TIMEOUT = 30000;
11
- const FLUSH_TIMEOUT = 1000;
12
- const OK_EXIT = 0;
13
-
14
11
  const correlationId = getCorrelationId('--sumologic-winston-logger-prod-test--');
15
12
 
16
13
  const user = {
package/test/testEnv.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint no-process-env: "off" */
2
+ import process from 'node:process';
2
3
 
3
- import process from 'process';
4
4
  /**
5
5
  *
6
6
  * Test logger Configuration.
@@ -1,6 +1,6 @@
1
1
  /* eslint no-process-env: "off" */
2
+ import process from 'node:process';
2
3
 
3
- import process from 'process';
4
4
  /**
5
5
  *
6
6
  * Test logger prod with filter Configuration.