@mimik/sumologic-winston-logger 1.6.22 → 2.0.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.
- package/configuration/config.js +52 -43
- package/eslint.config.js +60 -0
- package/index.js +46 -40
- package/lib/awsKinesisTransport.js +33 -25
- package/lib/awsS3Transport.js +39 -27
- package/lib/common.js +30 -30
- package/lib/formatLib.js +27 -24
- package/lib/stackLib.js +33 -18
- package/lib/sumologicTransport.js +24 -18
- package/manual-test/eventsMock.js +5 -3
- package/manual-test/testLog.js +7 -6
- package/manual-test/testLogAndQuit.js +11 -9
- package/manual-test/testLogError.js +4 -4
- package/manual-test/testManyLogs.js +16 -15
- package/package.json +24 -26
- package/test/filterConfig.json +3 -18
- package/test/logger.spec.js +20 -77
- package/test/loggerProd.spec.js +90 -0
- package/test/testEnv.js +2 -1
- package/test/testEnvProdFilter.js +8 -1
- package/.eslintrc +0 -43
package/test/logger.spec.js
CHANGED
|
@@ -1,71 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
require('./testEnvProdFilter');
|
|
14
|
-
const loggerProd = require('../index');
|
|
1
|
+
import './testEnv.js';
|
|
2
|
+
import { before, describe, it } from 'mocha';
|
|
3
|
+
import { getCorrelationId } from '@mimik/request-helper';
|
|
4
|
+
import logger from '../index.js';
|
|
5
|
+
import process from 'process';
|
|
6
|
+
import { setTimeout } from 'timers';
|
|
7
|
+
import { should } from 'chai';
|
|
8
|
+
import { stub } from 'sinon';
|
|
9
|
+
|
|
10
|
+
const START_TIMEOUT = 30000;
|
|
11
|
+
const FLUSH_TIMEOUT = 1000;
|
|
12
|
+
const OK_EXIT = 0;
|
|
15
13
|
|
|
16
14
|
const correlationId = getCorrelationId('--sumologic-winston-logger-test--');
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
externalIds: [
|
|
20
|
-
'2584799985283928064',
|
|
21
|
-
],
|
|
22
|
-
appIds: [],
|
|
23
|
-
_id: '5d28b615a97b3605636a9e17',
|
|
24
|
-
id: '2584799985283928064',
|
|
25
|
-
email: 'lauraawarr+mimik5@gmail.com',
|
|
26
|
-
attributes: [{
|
|
27
|
-
name: 'nickname',
|
|
28
|
-
value: 'User 5',
|
|
29
|
-
}],
|
|
30
|
-
references: [{
|
|
31
|
-
serverType: 'mFD',
|
|
32
|
-
resourceName: 'requestFriendLists',
|
|
33
|
-
include: 'requestFriends',
|
|
34
|
-
id: '2584799985283928064',
|
|
35
|
-
self: 'https://mfd.mimik360.com/mFD/v1/requestFriendLists/2584799985283928064',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
serverType: 'mFD',
|
|
39
|
-
resourceName: 'friendRequestLists',
|
|
40
|
-
include: 'friendRequests',
|
|
41
|
-
id: '2584799985283928064',
|
|
42
|
-
self: 'https://mfd.mimik360.com/mFD/v1/friendRequestLists/2584799985283928064',
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
serverType: 'mFD',
|
|
46
|
-
resourceName: 'friendLists',
|
|
47
|
-
include: 'friends',
|
|
48
|
-
id: '2584799985283928064',
|
|
49
|
-
self: 'https://mfd.mimik360.com/mFD/v1/friendLists/2584799985283928064',
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
serverType: 'mDS',
|
|
53
|
-
resourceName: 'nodes',
|
|
54
|
-
include: 'devices',
|
|
55
|
-
id: '2584799985283928064',
|
|
56
|
-
self: 'https://mds.mimik360.com/mDS/v1/nodes?accountId=2584799985283928064',
|
|
57
|
-
}],
|
|
58
|
-
createdAt: '2019-07-12T16:32:21.709Z',
|
|
59
|
-
self: 'https://mpo.mimik360.com/mPO/v1/users/2584799985283928064',
|
|
60
|
-
__v: 1,
|
|
61
|
-
avatar: 'https://mts.mimik360.com/mTS/v1/thumbnails/9a86220f-9d76-48e4-98a3-1a51c22fc49a',
|
|
62
|
-
updatedAt: '2019-07-12T16:35:39.195Z',
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
chai.should();
|
|
16
|
+
should();
|
|
66
17
|
|
|
67
|
-
describe('sumologic-winston-logger Unit Tests', function
|
|
68
|
-
this.timeout(
|
|
18
|
+
describe('sumologic-winston-logger Unit Tests', function LoggerTests() {
|
|
19
|
+
this.timeout(START_TIMEOUT);
|
|
69
20
|
it('Can log an debug message without a correlationId and info', (done) => {
|
|
70
21
|
logger.debug('this is an debug statement');
|
|
71
22
|
done();
|
|
@@ -94,25 +45,17 @@ describe('sumologic-winston-logger Unit Tests', function loggerTests() {
|
|
|
94
45
|
logger.debug('this is a debug statement');
|
|
95
46
|
done();
|
|
96
47
|
});
|
|
97
|
-
it('
|
|
98
|
-
|
|
99
|
-
done();
|
|
100
|
-
});
|
|
101
|
-
it('Changing the environment to prod to cover filters and see filtered result', (done) => {
|
|
102
|
-
loggerProd.info('this is an info statement on prod', { user }, correlationId);
|
|
103
|
-
done();
|
|
104
|
-
});
|
|
105
|
-
it('Can log a debug statement without correlationId and info on production', (done) => {
|
|
106
|
-
loggerProd.debug('this is a debug statement');
|
|
48
|
+
it('can flush logs', (done) => {
|
|
49
|
+
logger.flush();
|
|
107
50
|
done();
|
|
108
51
|
});
|
|
109
52
|
it('Can flush and exit', (done) => {
|
|
110
53
|
logger.debug('this is a debug statement');
|
|
111
|
-
|
|
112
|
-
logger.flushAndExit(
|
|
54
|
+
stub(process, 'exit');
|
|
55
|
+
logger.flushAndExit(OK_EXIT);
|
|
113
56
|
done();
|
|
114
57
|
});
|
|
115
|
-
before(
|
|
58
|
+
before(done => setTimeout(done, FLUSH_TIMEOUT)); // adding a delay to make sure that the fush is done
|
|
116
59
|
it('Cleanup', (done) => {
|
|
117
60
|
process.exit.restore();
|
|
118
61
|
done();
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import './testEnvProdFilter.js';
|
|
2
|
+
import { before, describe, it } from 'mocha';
|
|
3
|
+
import { getCorrelationId } from '@mimik/request-helper';
|
|
4
|
+
import logger from '../index.js';
|
|
5
|
+
import process from 'process';
|
|
6
|
+
import { setTimeout } from 'timers';
|
|
7
|
+
import { should } from 'chai';
|
|
8
|
+
import { stub } from 'sinon';
|
|
9
|
+
|
|
10
|
+
const START_TIMEOUT = 30000;
|
|
11
|
+
const FLUSH_TIMEOUT = 1000;
|
|
12
|
+
const OK_EXIT = 0;
|
|
13
|
+
|
|
14
|
+
const correlationId = getCorrelationId('--sumologic-winston-logger-prod-test--');
|
|
15
|
+
|
|
16
|
+
const user = {
|
|
17
|
+
__v: 1,
|
|
18
|
+
_id: '5d28b615a97b3605636a9e17',
|
|
19
|
+
appIds: [],
|
|
20
|
+
attributes: [{
|
|
21
|
+
name: 'nickname',
|
|
22
|
+
value: 'User 5',
|
|
23
|
+
}],
|
|
24
|
+
avatar: 'https://mts.mimik360.com/mTS/v1/thumbnails/9a86220f-9d76-48e4-98a3-1a51c22fc49a',
|
|
25
|
+
createdAt: '2019-07-12T16:32:21.709Z',
|
|
26
|
+
email: 'lauraawarr+mimik5@gmail.com',
|
|
27
|
+
externalIds: [
|
|
28
|
+
'2584799985283928064',
|
|
29
|
+
],
|
|
30
|
+
id: '2584799985283928064',
|
|
31
|
+
references: [{
|
|
32
|
+
serverType: 'mFD',
|
|
33
|
+
resourceName: 'requestFriendLists',
|
|
34
|
+
include: 'requestFriends',
|
|
35
|
+
id: '2584799985283928064',
|
|
36
|
+
self: 'https://mfd.mimik360.com/mFD/v1/requestFriendLists/2584799985283928064',
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
serverType: 'mFD',
|
|
40
|
+
resourceName: 'friendRequestLists',
|
|
41
|
+
include: 'friendRequests',
|
|
42
|
+
id: '2584799985283928064',
|
|
43
|
+
self: 'https://mfd.mimik360.com/mFD/v1/friendRequestLists/2584799985283928064',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
serverType: 'mFD',
|
|
47
|
+
resourceName: 'friendLists',
|
|
48
|
+
include: 'friends',
|
|
49
|
+
id: '2584799985283928064',
|
|
50
|
+
self: 'https://mfd.mimik360.com/mFD/v1/friendLists/2584799985283928064',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
serverType: 'mDS',
|
|
54
|
+
resourceName: 'nodes',
|
|
55
|
+
include: 'devices',
|
|
56
|
+
id: '2584799985283928064',
|
|
57
|
+
self: 'https://mds.mimik360.com/mDS/v1/nodes?accountId=2584799985283928064',
|
|
58
|
+
}],
|
|
59
|
+
self: 'https://mpo.mimik360.com/mPO/v1/users/2584799985283928064',
|
|
60
|
+
updatedAt: '2019-07-12T16:35:39.195Z',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
should();
|
|
64
|
+
|
|
65
|
+
describe('sumologic-winston-logger prod Unit Tests', function LoggerTests() {
|
|
66
|
+
this.timeout(START_TIMEOUT);
|
|
67
|
+
it('Changing the environment to prod to cover filters', (done) => {
|
|
68
|
+
logger.info('this is an info statement on prod', { meta: 'data' });
|
|
69
|
+
done();
|
|
70
|
+
});
|
|
71
|
+
it('Changing the environment to prod to cover filters and see filtered result', (done) => {
|
|
72
|
+
logger.info('this is an info statement on prod', { user }, correlationId);
|
|
73
|
+
done();
|
|
74
|
+
});
|
|
75
|
+
it('Can log a debug statement without correlationId and info on production', (done) => {
|
|
76
|
+
logger.debug('this is a debug statement');
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
it('Can flush and exit', (done) => {
|
|
80
|
+
logger.debug('this is a debug statement');
|
|
81
|
+
stub(process, 'exit');
|
|
82
|
+
logger.flushAndExit(OK_EXIT);
|
|
83
|
+
done();
|
|
84
|
+
});
|
|
85
|
+
before(done => setTimeout(done, FLUSH_TIMEOUT)); // adding a delay to make sure that the fush is done
|
|
86
|
+
it('Cleanup', (done) => {
|
|
87
|
+
process.exit.restore();
|
|
88
|
+
done();
|
|
89
|
+
});
|
|
90
|
+
});
|
package/test/testEnv.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint no-process-env: "off" */
|
|
2
2
|
|
|
3
|
+
import process from 'process';
|
|
3
4
|
/**
|
|
4
5
|
*
|
|
5
6
|
* Test logger Configuration.
|
|
@@ -55,7 +56,7 @@ process.env.KINESIS_AWS_STREAM_NAME_OTHER = 'a kinesis stream name for other';
|
|
|
55
56
|
// process.env.KINESIS_AWS_TIMEOUT = 10;
|
|
56
57
|
// process.env.KINESIS_AWS_MAX_SIZE = 1;
|
|
57
58
|
process.env.EXIT_DELAY = 1;
|
|
58
|
-
process.env.LOG_MODE = '
|
|
59
|
+
process.env.LOG_MODE = 'all';
|
|
59
60
|
// process.env.LOG_MODE = 'awsS3';
|
|
60
61
|
// process.env.LOG_MODE = 'awsS3, sumologic, awsKinesis';
|
|
61
62
|
// process.env.LOG_MODE = 'all';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/* eslint no-process-env: "off" */
|
|
2
2
|
|
|
3
|
+
import process from 'process';
|
|
3
4
|
/**
|
|
4
5
|
*
|
|
5
6
|
* Test logger prod with filter Configuration.
|
|
@@ -14,10 +15,16 @@
|
|
|
14
15
|
* | FILTER_FILE | filename containing filter rules
|
|
15
16
|
* | NO_STACK | indicatior to log th stack on all log message
|
|
16
17
|
* | LOG_MODE | loge mode for the running instance
|
|
18
|
+
* | SUMO_LOGIC_ENDPOINT | url of the sumologic collector
|
|
19
|
+
* | SUMO_LOGIC_COLLECTOR_CODE | code of the sumologic collector
|
|
17
20
|
*/
|
|
21
|
+
// process.env.SUMO_LOGIC_ENDPOINT = 'http://localhost:9080/logs/';
|
|
22
|
+
// process.env.SUMO_LOGIC_COLLECTOR_CODE = '1234';
|
|
23
|
+
process.env.SUMO_LOGIC_ENDPOINT = 'https://a sumologic endpoint url';
|
|
24
|
+
process.env.SUMO_LOGIC_COLLECTOR_CODE = 'a sumologic collector code';
|
|
18
25
|
process.env.NODE_ENV = 'prod';
|
|
19
26
|
process.env.FILTER_FILE = './test/filterConfig.json';
|
|
20
27
|
process.env.NO_STACK = 'yes';
|
|
21
|
-
process.env.LOG_MODE = '
|
|
28
|
+
process.env.LOG_MODE = 'none';
|
|
22
29
|
process.env.CONSOLE_LEVEL = 'debug';
|
|
23
30
|
process.env.LOG_LEVEL = 'debug';
|
package/.eslintrc
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"plugins": [
|
|
3
|
-
"@mimik/document-env",
|
|
4
|
-
"@mimik/dependencies"
|
|
5
|
-
],
|
|
6
|
-
"env": {
|
|
7
|
-
"node": true
|
|
8
|
-
},
|
|
9
|
-
"parserOptions": {
|
|
10
|
-
"ecmaVersion": 2020
|
|
11
|
-
},
|
|
12
|
-
"extends": "airbnb",
|
|
13
|
-
"rules": {
|
|
14
|
-
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
|
|
15
|
-
"import/no-unresolved": ["error", { "amd": true, "commonjs": true, "caseSensitiveStrict": true }],
|
|
16
|
-
"brace-style": [1, "stroustrup", {"allowSingleLine": true}],
|
|
17
|
-
"no-confusing-arrow": [0], // arrow isnt confusing
|
|
18
|
-
"max-len": [1, 180, { "ignoreComments": true }],
|
|
19
|
-
"linebreak-style": 0,
|
|
20
|
-
"quotes": [1, "single"],
|
|
21
|
-
"semi": [1, "always"],
|
|
22
|
-
"no-process-env": ["error"],
|
|
23
|
-
"@mimik/document-env/validate-document-env": 2,
|
|
24
|
-
"@mimik/dependencies/case-sensitive": 2,
|
|
25
|
-
"@mimik/dependencies/no-cycles": 2,
|
|
26
|
-
"@mimik/dependencies/require-json-ext": 2
|
|
27
|
-
},
|
|
28
|
-
"settings":{
|
|
29
|
-
"react": {
|
|
30
|
-
"version": "detect"
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
"globals": {
|
|
34
|
-
"module": true,
|
|
35
|
-
"require": true,
|
|
36
|
-
"const": false,
|
|
37
|
-
"it": false,
|
|
38
|
-
"describe": false,
|
|
39
|
-
"before": true,
|
|
40
|
-
"after": true,
|
|
41
|
-
"JSON": true
|
|
42
|
-
}
|
|
43
|
-
}
|