@mimik/sumologic-winston-logger 2.2.2 → 2.2.3
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/configuration/config.js +5 -0
- package/index.js +2 -0
- package/lib/awsKinesisTransport.js +2 -0
- package/lib/awsS3Transport.js +2 -0
- package/package.json +7 -7
- package/manual-test/eventsMock.js +0 -26
- package/manual-test/testLog.js +0 -35
- package/manual-test/testLogAndQuit.js +0 -42
- package/manual-test/testLogError.js +0 -12
- package/manual-test/testManyLogs.js +0 -40
package/configuration/config.js
CHANGED
|
@@ -140,6 +140,7 @@ const configuration = {
|
|
|
140
140
|
noStack: process.env.NO_STACK || 'yes',
|
|
141
141
|
};
|
|
142
142
|
configuration.mode = checkMode(process.env.LOG_MODE) || [NONE_MODE];
|
|
143
|
+
/* c8 ignore stop */
|
|
143
144
|
|
|
144
145
|
if (configuration.mode.includes(SUMOLOGIC)) {
|
|
145
146
|
configuration[SUMOLOGIC] = {
|
|
@@ -163,6 +164,7 @@ if (configuration.mode.includes(AWS_KINESIS)) {
|
|
|
163
164
|
},
|
|
164
165
|
};
|
|
165
166
|
|
|
167
|
+
/* c8 ignore next 2 -- optional env vars not set in test */
|
|
166
168
|
if (process.env.KINESIS_AWS_ACCESS_KEY_ID !== undefined) configuration[AWS_KINESIS].accessKeyId = process.env.KINESIS_AWS_ACCESS_KEY_ID;
|
|
167
169
|
if (process.env.KINESIS_AWS_SECRET_ACCESS_KEY !== undefined) configuration[AWS_KINESIS].secretAccessKey = process.env.KINESIS_AWS_SECRET_ACCESS_KEY;
|
|
168
170
|
}
|
|
@@ -175,12 +177,14 @@ if (configuration.mode.includes(AWS_S3)) {
|
|
|
175
177
|
maxEvents: toInt(process.env.S3_AWS_MAX_EVENTS, 1000),
|
|
176
178
|
};
|
|
177
179
|
|
|
180
|
+
/* c8 ignore next 2 -- optional env vars not set in test */
|
|
178
181
|
if (process.env.S3_AWS_ACCESS_KEY_ID !== undefined) configuration[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
|
|
179
182
|
if (process.env.S3_AWS_SECRET_ACCESS_KEY !== undefined) configuration[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
|
|
180
183
|
}
|
|
181
184
|
const { filter } = configuration;
|
|
182
185
|
let filterConfig = [];
|
|
183
186
|
|
|
187
|
+
/* c8 ignore start -- FILTER_FILE only set in prod env, module singleton prevents re-evaluation */
|
|
184
188
|
if (filter.file) {
|
|
185
189
|
try {
|
|
186
190
|
filterConfig = JSON.parse(readFileSync(filter.file).toString());
|
|
@@ -189,6 +193,7 @@ if (filter.file) {
|
|
|
189
193
|
throw new Error(`Invalid file for logger config: ${filter.file}`, { cause: err });
|
|
190
194
|
}
|
|
191
195
|
}
|
|
196
|
+
/* c8 ignore stop */
|
|
192
197
|
filter.config = filterConfig;
|
|
193
198
|
checkConfig(configuration);
|
|
194
199
|
|
package/index.js
CHANGED
|
@@ -111,6 +111,7 @@ if (config.mode.includes(AWS_KINESIS)) {
|
|
|
111
111
|
logger.add(awsKinesis);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
/* c8 ignore start -- flush race-condition branches depend on async transport completion order */
|
|
114
115
|
logger.flushAndExit = (code) => {
|
|
115
116
|
const flushing = () => {
|
|
116
117
|
let sumoDone = false;
|
|
@@ -190,6 +191,7 @@ logger.flush = () => {
|
|
|
190
191
|
|
|
191
192
|
setTimeout(flushing, config.flushExitDelay);
|
|
192
193
|
};
|
|
194
|
+
/* c8 ignore stop */
|
|
193
195
|
|
|
194
196
|
logger.LEVELS = ['error', 'warn', 'info', 'verbose', 'debug', 'silly'];
|
|
195
197
|
|
|
@@ -65,6 +65,7 @@ export default class AwsKinesis extends Transport {
|
|
|
65
65
|
);
|
|
66
66
|
this.kinesis = new KinesisClient(this.kinesisClientConfig);
|
|
67
67
|
|
|
68
|
+
/* c8 ignore start -- timer-based flush; exercised in production, not in unit tests */
|
|
68
69
|
this.time = setInterval(() => {
|
|
69
70
|
Object.keys(events).forEach((level) => {
|
|
70
71
|
if (events[level].Records.length) {
|
|
@@ -74,6 +75,7 @@ export default class AwsKinesis extends Transport {
|
|
|
74
75
|
}
|
|
75
76
|
});
|
|
76
77
|
}, this.timeInterval).unref();
|
|
78
|
+
/* c8 ignore stop */
|
|
77
79
|
}
|
|
78
80
|
|
|
79
81
|
put(Records, lvl) {
|
package/lib/awsS3Transport.js
CHANGED
|
@@ -46,6 +46,7 @@ export default class AwsS3 extends Transport {
|
|
|
46
46
|
}
|
|
47
47
|
this.s3 = new S3Client(this.s3ClientConfig);
|
|
48
48
|
|
|
49
|
+
/* c8 ignore start -- timer-based flush; exercised in production, not in unit tests */
|
|
49
50
|
this.time = setInterval(() => {
|
|
50
51
|
Object.keys(events).forEach((level) => {
|
|
51
52
|
if (events[level].data.length) {
|
|
@@ -63,6 +64,7 @@ export default class AwsS3 extends Transport {
|
|
|
63
64
|
}
|
|
64
65
|
});
|
|
65
66
|
}, this.timeInterval).unref();
|
|
67
|
+
/* c8 ignore stop */
|
|
66
68
|
}
|
|
67
69
|
|
|
68
70
|
put(data, lvl, date) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mimik/sumologic-winston-logger",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "Log wrapper for sumo, s3, kinesis and winston",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
"scripts": {
|
|
12
12
|
"docs": "jsdoc2md --template docs/README.hbs configuration/config.js > README.md",
|
|
13
13
|
"lint": "eslint . --no-error-on-unmatched-pattern",
|
|
14
|
-
"test": "mocha
|
|
15
|
-
"test-ci": "c8
|
|
14
|
+
"test": "mocha",
|
|
15
|
+
"test-ci": "c8 npm test",
|
|
16
16
|
"prepublishOnly": "npm run docs && npm run lint && npm run test-ci",
|
|
17
17
|
"commit-ready": "npm run docs && npm run lint && npm run test-ci"
|
|
18
18
|
},
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"winston-transport": "4.9.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@eslint/js": "
|
|
43
|
+
"@eslint/js": "10.0.1",
|
|
44
44
|
"@mimik/eslint-plugin-document-env": "^2.0.9",
|
|
45
45
|
"@mimik/eslint-plugin-logger": "^1.0.3",
|
|
46
46
|
"@mimik/request-helper": "^2.0.6",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
"aws-sdk-client-mock": "4.1.0",
|
|
49
49
|
"c8": "11.0.0",
|
|
50
50
|
"chai": "6.2.2",
|
|
51
|
-
"eslint": "
|
|
52
|
-
"eslint-plugin-import": "
|
|
51
|
+
"eslint": "10.1.0",
|
|
52
|
+
"eslint-plugin-import-x": "4.16.2",
|
|
53
53
|
"express": "5.2.1",
|
|
54
54
|
"globals": "17.4.0",
|
|
55
55
|
"husky": "9.1.7",
|
|
56
56
|
"jsdoc-to-markdown": "9.1.3",
|
|
57
57
|
"mocha": "11.7.5",
|
|
58
58
|
"mochawesome": "7.1.4",
|
|
59
|
-
"sinon": "21.0.
|
|
59
|
+
"sinon": "21.0.3"
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import express from 'express';
|
|
3
|
-
|
|
4
|
-
let i = 0;
|
|
5
|
-
const MOCK_PORT = 9000;
|
|
6
|
-
const CREATED_RESPONSE = 201;
|
|
7
|
-
|
|
8
|
-
const app = express();
|
|
9
|
-
const config = {
|
|
10
|
-
port: MOCK_PORT,
|
|
11
|
-
base: '/checkthat',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
app.post(`${config.base}`, (req, res) => {
|
|
15
|
-
i += 1;
|
|
16
|
-
console.log('Recieved a POST:', i);
|
|
17
|
-
// console.log('headers:', req.headers)
|
|
18
|
-
console.log(req.body);
|
|
19
|
-
|
|
20
|
-
res.statusCode = CREATED_RESPONSE;
|
|
21
|
-
res.send(req.body);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
app.listen(config.port, () => {
|
|
25
|
-
console.log(`event mock at ${config.port}`);
|
|
26
|
-
});
|
package/manual-test/testLog.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import '../test/testEnv.js';
|
|
3
|
-
import { getCorrelationId } from '@mimik/request-helper';
|
|
4
|
-
import logger from '../index.js';
|
|
5
|
-
import process from 'node:process';
|
|
6
|
-
|
|
7
|
-
const user = {
|
|
8
|
-
name: 'a name',
|
|
9
|
-
password: 'a password',
|
|
10
|
-
address: {
|
|
11
|
-
street: ' a street',
|
|
12
|
-
test2: 'this is a test2',
|
|
13
|
-
city: 'a city',
|
|
14
|
-
},
|
|
15
|
-
test1: 'this is a test1',
|
|
16
|
-
test2: 'this is a test2',
|
|
17
|
-
};
|
|
18
|
-
const correlationId = getCorrelationId('test-12345');
|
|
19
|
-
const stdin = process.openStdin();
|
|
20
|
-
|
|
21
|
-
logger.info('This is a test, info', {
|
|
22
|
-
user, test: 'this is a test', test2: 'this is a test2', test1: 'this is a test1',
|
|
23
|
-
}, correlationId);
|
|
24
|
-
|
|
25
|
-
logger.debug('This is a test with error', { user }, correlationId);
|
|
26
|
-
|
|
27
|
-
logger.error('This is a test, error', { user }, correlationId);
|
|
28
|
-
|
|
29
|
-
stdin.addListener('data', () => {
|
|
30
|
-
const clonedObject = { ...user };
|
|
31
|
-
|
|
32
|
-
clonedObject.index = 'manual';
|
|
33
|
-
console.log('manual logging');
|
|
34
|
-
logger.info('this is a test', { data: clonedObject }, correlationId);
|
|
35
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import '../test/testEnv';
|
|
2
|
-
import { SYSTEM_ERROR } from '../lib/common.js';
|
|
3
|
-
import logger from '../index.js';
|
|
4
|
-
|
|
5
|
-
const ISSUE_EXIT = 1;
|
|
6
|
-
|
|
7
|
-
const complexObject = {
|
|
8
|
-
key: 'property a',
|
|
9
|
-
propB: {
|
|
10
|
-
propC: 'property c',
|
|
11
|
-
propD: 'property d',
|
|
12
|
-
propE: {
|
|
13
|
-
propF: 'property f',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
};
|
|
17
|
-
complexObject.propG = complexObject;
|
|
18
|
-
const error = new Error('an error');
|
|
19
|
-
error.name = 'this is a complex error';
|
|
20
|
-
error.statusCode = SYSTEM_ERROR;
|
|
21
|
-
error.title = 'System error';
|
|
22
|
-
|
|
23
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
24
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
25
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
26
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
27
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
28
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
29
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
30
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
31
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
32
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
33
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
34
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
35
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
36
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
37
|
-
logger.info('this is a test', { user: complexObject }, '12345678');
|
|
38
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
39
|
-
logger.error('this is an error message', { user: complexObject, error, correlationId: '123344' }, '34567');
|
|
40
|
-
logger.flushAndExit(ISSUE_EXIT);
|
|
41
|
-
// setTimeout(() => console.log('done'), 4000);
|
|
42
|
-
// logger.error(error, { user: complexObject }, '6795949');
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import '../test/testEnv.js';
|
|
2
|
-
import { getCorrelationId } from '@mimik/request-helper';
|
|
3
|
-
import logger from '../index.js';
|
|
4
|
-
|
|
5
|
-
const error = new Error('this is a simple error');
|
|
6
|
-
const errorCause = new Error('this is an error with cause', { cause: error });
|
|
7
|
-
const errorCauseInfo = new Error('this is an error with cause and info', { cause: errorCause });
|
|
8
|
-
errorCauseInfo.info = 'this is an info';
|
|
9
|
-
const correlationId = getCorrelationId('test-12345');
|
|
10
|
-
|
|
11
|
-
// logger.error('This is an error in object', { errorCauseInfo }, correlationId);
|
|
12
|
-
logger.error('This is an error object ', errorCauseInfo, correlationId);
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import '../test/testEnv.js';
|
|
3
|
-
import { getCorrelationId } from '@mimik/request-helper';
|
|
4
|
-
import logger from '../index.js';
|
|
5
|
-
|
|
6
|
-
const MAX_ITEMS = 100000;
|
|
7
|
-
|
|
8
|
-
const complexObject = {
|
|
9
|
-
key: 'property a',
|
|
10
|
-
propB: {
|
|
11
|
-
propC: 'property c',
|
|
12
|
-
propD: 'property d',
|
|
13
|
-
propE: {
|
|
14
|
-
propF: 'property f',
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
complexObject.propG = complexObject;
|
|
19
|
-
const object = {
|
|
20
|
-
user: {
|
|
21
|
-
userId: 'a long userid simulating a uuid',
|
|
22
|
-
info: 'this is a test',
|
|
23
|
-
correlationId: getCorrelationId('a long uuid to simulate a correlationId'),
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
const objects = [];
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < MAX_ITEMS; i += 1) {
|
|
29
|
-
const clonedObject = { ...object };
|
|
30
|
-
|
|
31
|
-
clonedObject.index = i;
|
|
32
|
-
objects.push(clonedObject);
|
|
33
|
-
}
|
|
34
|
-
const startDate = new Date();
|
|
35
|
-
|
|
36
|
-
console.log('Test start at:', startDate.toISOString(), 'with:', MAX_ITEMS, 'items');
|
|
37
|
-
Promise.all(objects.map(obj => logger.info('This is a test', { data: obj }, getCorrelationId('test-correlation-id')))).then(() => {
|
|
38
|
-
const endDate = new Date();
|
|
39
|
-
console.log('Test end at:', endDate.toISOString(), 'duration:', endDate - startDate, 'with:', MAX_ITEMS, 'items');
|
|
40
|
-
});
|