@mimik/sumologic-winston-logger 1.2.1 → 1.6.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/.eslintrc +16 -4
- package/.husky/pre-commit +4 -0
- package/.husky/pre-push +4 -0
- package/README.md +0 -164
- package/README_Supplement.md +139 -0
- package/configuration/config.js +108 -13
- package/index.js +57 -20
- package/lib/awsKinesisTransport.js +140 -0
- package/lib/awsS3Transport.js +54 -19
- package/lib/common.js +34 -13
- package/lib/formatLib.js +33 -11
- package/lib/sumologicTransport.js +43 -16
- package/manual-test/eventsMock.js +6 -5
- package/manual-test/testLog.js +8 -5
- package/manual-test/testLogAndQuit.js +10 -11
- package/manual-test/testManyLogs.js +26 -27
- package/package.json +37 -34
- package/test/filterConfig.json +18 -18
- package/test/logger.spec.js +19 -8
- package/test/testEnv.js +59 -7
- package/test/testEnvProdFilter.js +23 -0
- package/Gulpfile.js +0 -26
- package/manual-test/testNameValue.js +0 -27
- package/package.json.bak +0 -63
package/.eslintrc
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
|
-
// Use this file as a starting point for your project's .eslintrc.
|
|
2
|
-
// Copy this file, and add rule overrides as needed.
|
|
3
1
|
{
|
|
2
|
+
"plugins": [
|
|
3
|
+
"@mimik/document-env",
|
|
4
|
+
"@mimik/dependencies"
|
|
5
|
+
],
|
|
4
6
|
"env": {
|
|
5
7
|
"node": true
|
|
6
8
|
},
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"ecmaVersion": 2020
|
|
11
|
+
},
|
|
7
12
|
"extends": "airbnb",
|
|
8
13
|
"rules": {
|
|
14
|
+
"import/no-extraneous-dependencies": ["error", {"devDependencies": true}],
|
|
15
|
+
"import/no-unresolved": ["error", { "amd": true, "commonjs": true, "caseSensitiveStrict": true }],
|
|
9
16
|
"brace-style": [1, "stroustrup", {"allowSingleLine": true}],
|
|
10
17
|
"no-confusing-arrow": [0], // arrow isnt confusing
|
|
11
18
|
"max-len": [1, 180, { "ignoreComments": true }],
|
|
12
19
|
"linebreak-style": 0,
|
|
13
20
|
"quotes": [1, "single"],
|
|
14
|
-
"semi": [1, "always"]
|
|
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
|
|
15
27
|
},
|
|
16
28
|
"settings":{
|
|
17
29
|
"react": {
|
|
18
|
-
"version": "
|
|
30
|
+
"version": "detect"
|
|
19
31
|
}
|
|
20
32
|
},
|
|
21
33
|
"globals": {
|
package/.husky/pre-push
ADDED
package/README.md
CHANGED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
## Synopsis ##
|
|
2
|
-
|
|
3
|
-
Sumologic-Winston-Logger is a log wrapper that can write to multiple logging services.
|
|
4
|
-
Currently, Winston, SumoLogic, and AWS S2 are supported.
|
|
5
|
-
The package also adds strackTrace info.
|
|
6
|
-
StackTrace information gets tacked on to Sumologic calls, In addition and method, module, and line info or
|
|
7
|
-
concatenated is added to the end of winston lines. **Line formatting is not currently configrable.**
|
|
8
|
-
The package also allow some level of filtering.
|
|
9
|
-
|
|
10
|
-
## Motivation ##
|
|
11
|
-
To centralize logging in a single npm node package
|
|
12
|
-
|
|
13
|
-
## Installation ##
|
|
14
|
-
|
|
15
|
-
The logger is discoverable on npmjs.org.
|
|
16
|
-
|
|
17
|
-
To install:
|
|
18
|
-
```
|
|
19
|
-
npm install sumologic-winston-logger --save
|
|
20
|
-
|
|
21
|
-
## Configuration - Environment Variables: ##
|
|
22
|
-
|
|
23
|
-
The logger expects certain environment variables to be present in order to be operational. If they environment variables are not set, the logger will not load.
|
|
24
|
-
|
|
25
|
-
The expected environment variables are:
|
|
26
|
-
|
|
27
|
-
* `LOG_LEVEL`
|
|
28
|
-
* `LOG_MODE`
|
|
29
|
-
* `SUMO_LOGIC_ENDPOINT`
|
|
30
|
-
* `SUMO_LOGIC_COLLECTOR_CODE`
|
|
31
|
-
* `CONSOLE_LEVEL`
|
|
32
|
-
* `FILTER_FILE`
|
|
33
|
-
* `S3_AWS_ACCESS_KEY_ID`
|
|
34
|
-
* `S3_AWS_SECRET_ACCESS_KEY`
|
|
35
|
-
* `S3_AWS_BUCKET_NAME`
|
|
36
|
-
* `S3_AWS_REGION`
|
|
37
|
-
* `S3_AWS_TIMEOUT`
|
|
38
|
-
* `S3_AWS_MAX_SIZE`
|
|
39
|
-
* `S3_AWS_MAX_EVENTS`
|
|
40
|
-
* `NO_STACK`
|
|
41
|
-
|
|
42
|
-
`SUMOLOGIC_xxxx` is used to set up sumologic collector.
|
|
43
|
-
`S3_AWS_xxx` is used to setup S3 bucket.
|
|
44
|
-
`LOG_MODE` can be set to `sumologic` to only log to sumologic collector or `awsS3` to only log to S3 bucket or `all` to log in sumologic and S3 bucket. The default is `sumologic`.
|
|
45
|
-
`S3_AWS_xxx` are parameters to set when to send logs to S3 bucket.
|
|
46
|
-
* `S3_AWS_TIMEOUT` indicates in minutes that logs have to be send when timout expires, the default is `5 minutes`.
|
|
47
|
-
* `S3_AWS_MAX_SIZE` indicates the max memory size the block of logs can be before being sent to S3, the default is `5 Mb`.
|
|
48
|
-
* `S3_AWS_MAX_EVENTS` indicates the max amount of logs in a block of logs before being sent to S3, the default is `1000`.
|
|
49
|
-
|
|
50
|
-
The following sections decribe the details of each of the environment variables listed above.
|
|
51
|
-
|
|
52
|
-
### `LOG_LEVEL` ###
|
|
53
|
-
Log levels supported inclusively according to the following list, as borrowed from winston:
|
|
54
|
-
|
|
55
|
-
* silly
|
|
56
|
-
* verbose
|
|
57
|
-
* debug
|
|
58
|
-
* info
|
|
59
|
-
* warn
|
|
60
|
-
* error
|
|
61
|
-
|
|
62
|
-
Thus, if one declares a log level of silly, the levels error, warn, info, debug, and verbose are reported too.
|
|
63
|
-
|
|
64
|
-
|Example to set the environment variable `LOG_LEVEL`|
|
|
65
|
-
|---|
|
|
66
|
-
|`export LOG_LEVEL=error`|
|
|
67
|
-
|
|
68
|
-
### `SUMO_LOGIC_ENDPOINT` ###
|
|
69
|
-
The endpoint defined in SumoLogic to where log information will be sent. See the section, _Finding SumoLogic endpoint and collector code_, below to find the value to assign to this environment variable.
|
|
70
|
-
|
|
71
|
-
|Example to set the environment varible `SUMO_LOGIC_ENDPOINT`|
|
|
72
|
-
|---|
|
|
73
|
-
|`export SUMO_LOGIC_ENDPOINT=https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/`|
|
|
74
|
-
|
|
75
|
-
### `SUMO_LOGIC_COLLECTOR_CODE` ###
|
|
76
|
-
The collector code as defined in SumoLogic. The Collector Code is the Base64 string that appears after the last slash in the URL defined in the SumoLogic Control Panel.
|
|
77
|
-
|
|
78
|
-
|Example to set the environment varible `SUMO_LOGIC_COLLECTOR_CODE`|
|
|
79
|
-
|---|
|
|
80
|
-
|`export SUMO_LOGIC_COLLECTOR_CODE=AhfheisdcOllectorCodeInSumoLogicuZw==`|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
To learn more about setting this environment variable, see the section, _Finding SumoLogic endpoint and collector code_, below.
|
|
84
|
-
|
|
85
|
-
## Finding SumoLogic endpoint and collector code ##
|
|
86
|
-
|
|
87
|
-
To find the values that you will apply the environment variables, `SUMO_LOGIC_ENDPOINT` and `SUMO_LOGIC_COLLECTOR_CODE`, in the SumoLogic Control Panel, goto: Manage > Collection, and get the source category
|
|
88
|
-
|
|
89
|
-

|
|
90
|
-
|
|
91
|
-
**Figure 1: Select the Manage -> Collection to display a list of collectors in force**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-

|
|
95
|
-
|
|
96
|
-
**Figure 2: Click the link, Show URL to display the URL configuration for the given collector**
|
|
97
|
-
|
|
98
|
-

|
|
99
|
-
|
|
100
|
-
**Figure 3: The HTTP Source Address dialog shows collector's URL. The collector code is a Base64 string appended after the last slash in the Source Address URL**
|
|
101
|
-
|
|
102
|
-
The endpoint is the part of the url that ends with a slash. i.e.
|
|
103
|
-
`https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/`
|
|
104
|
-
|
|
105
|
-
The collector code is the Base64 encrypted part of the URL that follows the last slash in the url.
|
|
106
|
-
|
|
107
|
-
### `FILTER_FILE` ###
|
|
108
|
-
|
|
109
|
-
FILTER_FILE is the location where the definition of the filtering configuration is. The location has to be a full file name.
|
|
110
|
-
When the environment in which the logger is used is `prod` or `production`, the content of the log will be filtered according to the log filtering configuration included in the file refered by the FILTER_FILE valiable.
|
|
111
|
-
The filter will replace values of the designated property names to '-----'.
|
|
112
|
-
|
|
113
|
-
### Sample Use ###
|
|
114
|
-
|
|
115
|
-
The intent of this package is to support all the behavior common to console.log while also including support of multiple arguements and all data types.
|
|
116
|
-
|
|
117
|
-
Formatting console logs is left to winston, except that some stackTrace info is appended to each line.
|
|
118
|
-
|
|
119
|
-
Formatting of SumoLogic logs is handled by this module in the following ways:
|
|
120
|
-
|
|
121
|
-
* only the first is use for message
|
|
122
|
-
* only one object can be passed as parameter
|
|
123
|
-
* structured stackTrace info is added to every log except is `NO_STACK` is set the 'yes'
|
|
124
|
-
* if the last parameter is a string it will be considered as a `correlationId`
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
### Logging Examples ###
|
|
128
|
-
Listing 2 below show you how to declare a logger to run under ECMAScript 6 and then log using the various log levels supported by the Sumologic-Winston-Logger.
|
|
129
|
-
|
|
130
|
-
``` javascript
|
|
131
|
-
const logger = require('sumologic-winston-logger');
|
|
132
|
-
|
|
133
|
-
logger.log(debug', 'this is a debug statement using log');
|
|
134
|
-
logger.debug({ message: 'this is a debug statement using an object'});
|
|
135
|
-
logger.error('this is an error statement');
|
|
136
|
-
logger.error(new Error('this is an error statement'));
|
|
137
|
-
logger.warn('this is a warning statement', { meta: 'data' });
|
|
138
|
-
logger.info('this is an info statement', { meta: 'data' });
|
|
139
|
-
logger.verbose('this is a verbose statement');
|
|
140
|
-
logger.silly('this is a silly statement o_O');
|
|
141
|
-
logger.debug('this is a debug statement with 2 params', { meta: 'data' });
|
|
142
|
-
logger.debug('this is a debug statement with 2 params and a correlationId', { meta: 'data' }, '123456')
|
|
143
|
-
```
|
|
144
|
-
**Listing 2: Examples of using the logger to make a log entry, using the log levels, log, silly, verbose, debug, info, warn, and error**
|
|
145
|
-
|
|
146
|
-
By default, log entries are logged to console.
|
|
147
|
-
The log() method is also supported, and adds a level parameter in position 1.
|
|
148
|
-
|
|
149
|
-
### Tailing ###
|
|
150
|
-
|
|
151
|
-
Trailing allows you to scroll through log output in real time. You can trail log data in SumoLogic.
|
|
152
|
-
|
|
153
|
-
To trail in SumoLogic go to Search > Live Tail in the SumoLogic user interface and enter `sourceCategory=<source category>` in the search bar, where `<source category>` is the log you want to trail. Then click, Run
|
|
154
|
-
|
|
155
|
-
|Example|
|
|
156
|
-
|---|
|
|
157
|
-
|`sourceCategory=local/node/challengeAPI/logs`|
|
|
158
|
-
|
|
159
|
-
### Stack Trace ###
|
|
160
|
-
All logging to `error()` are added the stack trace.
|
|
161
|
-
All other log levels will include a line number and file name.
|
|
162
|
-
|
|
163
|
-
## License ##
|
|
164
|
-
ISC
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
|
|
2
|
+
## Synopsis ##
|
|
3
|
+
|
|
4
|
+
Sumologic-Winston-Logger is a log wrapper that can write to multiple logging services.
|
|
5
|
+
Currently, Winston, SumoLogic, AWS Kinesis and AWS S3 are supported.
|
|
6
|
+
The package also adds strackTrace info.
|
|
7
|
+
StackTrace information gets tacked on to Sumologic calls, In addition and method, module, and line info or
|
|
8
|
+
concatenated is added to the end of winston lines. **Line formatting is not currently configrable.**
|
|
9
|
+
The package also allow some level of filtering.
|
|
10
|
+
|
|
11
|
+
## Motivation ##
|
|
12
|
+
To centralize logging in a single npm node package
|
|
13
|
+
|
|
14
|
+
## Installation ##
|
|
15
|
+
|
|
16
|
+
The logger is discoverable on npmjs.org.
|
|
17
|
+
|
|
18
|
+
To install:
|
|
19
|
+
```
|
|
20
|
+
npm install sumologic-winston-logger --save
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Configuration - Details ##
|
|
24
|
+
|
|
25
|
+
The following sections decribe the details of each of the environment variables listed above.
|
|
26
|
+
|
|
27
|
+
### `LOG_LEVEL` ###
|
|
28
|
+
Log levels supported inclusively according to the following list, as borrowed from winston:
|
|
29
|
+
|
|
30
|
+
* silly
|
|
31
|
+
* verbose
|
|
32
|
+
* debug
|
|
33
|
+
* info
|
|
34
|
+
* warn
|
|
35
|
+
* error
|
|
36
|
+
|
|
37
|
+
Thus, if one declares a log level of silly, the levels error, warn, info, debug, and verbose are reported too.
|
|
38
|
+
|
|
39
|
+
|Example to set the environment variable `LOG_LEVEL`|
|
|
40
|
+
|---|
|
|
41
|
+
|`export LOG_LEVEL=error`|
|
|
42
|
+
|
|
43
|
+
### `SUMO_LOGIC_ENDPOINT` ###
|
|
44
|
+
The endpoint defined in SumoLogic to where log information will be sent. See the section, _Finding SumoLogic endpoint and collector code_, below to find the value to assign to this environment variable.
|
|
45
|
+
|
|
46
|
+
|Example to set the environment varible `SUMO_LOGIC_ENDPOINT`|
|
|
47
|
+
|---|
|
|
48
|
+
|`export SUMO_LOGIC_ENDPOINT=https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/`|
|
|
49
|
+
|
|
50
|
+
### `SUMO_LOGIC_COLLECTOR_CODE` ###
|
|
51
|
+
The collector code as defined in SumoLogic. The Collector Code is the Base64 string that appears after the last slash in the URL defined in the SumoLogic Control Panel.
|
|
52
|
+
|
|
53
|
+
|Example to set the environment varible `SUMO_LOGIC_COLLECTOR_CODE`|
|
|
54
|
+
|---|
|
|
55
|
+
|`export SUMO_LOGIC_COLLECTOR_CODE=AhfheisdcOllectorCodeInSumoLogicuZw==`|
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
To learn more about setting this environment variable, see the section, _Finding SumoLogic endpoint and collector code_, below.
|
|
59
|
+
|
|
60
|
+
#### Finding SumoLogic endpoint and collector code ####
|
|
61
|
+
|
|
62
|
+
To find the values that you will apply the environment variables, `SUMO_LOGIC_ENDPOINT` and `SUMO_LOGIC_COLLECTOR_CODE`, in the SumoLogic Control Panel, goto: Manage > Collection, and get the source category
|
|
63
|
+
|
|
64
|
+

|
|
65
|
+
|
|
66
|
+
**Figure 1: Select the Manage -> Collection to display a list of collectors in force**
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+

|
|
70
|
+
|
|
71
|
+
**Figure 2: Click the link, Show URL to display the URL configuration for the given collector**
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
**Figure 3: The HTTP Source Address dialog shows collector's URL. The collector code is a Base64 string appended after the last slash in the Source Address URL**
|
|
76
|
+
|
|
77
|
+
The endpoint is the part of the url that ends with a slash. i.e.
|
|
78
|
+
`https://endpoint1.collection.us2.sumologic.com/receiver/v1/http/`
|
|
79
|
+
|
|
80
|
+
The collector code is the Base64 encrypted part of the URL that follows the last slash in the url.
|
|
81
|
+
|
|
82
|
+
### `FILTER_FILE` ###
|
|
83
|
+
|
|
84
|
+
FILTER_FILE is the location where the definition of the filtering configuration is. The location has to be a full file name.
|
|
85
|
+
When the environment (NODE_ENV) in which the logger is used is `prod` or `production`, the content of the log will be filtered according to the log filtering configuration included in the file refered by the FILTER_FILE valiable.
|
|
86
|
+
The filter will replace values of the designated property names to '-----'.
|
|
87
|
+
|
|
88
|
+
## Sample Use ##
|
|
89
|
+
|
|
90
|
+
The intent of this package is to support all the behavior common to console.log while also including support of multiple arguements and all data types.
|
|
91
|
+
|
|
92
|
+
Formatting console logs is left to winston, except that some stackTrace info is appended to each line.
|
|
93
|
+
|
|
94
|
+
Formatting of SumoLogic logs is handled by this module in the following ways:
|
|
95
|
+
|
|
96
|
+
* only the first is use for message
|
|
97
|
+
* only one object can be passed as parameter
|
|
98
|
+
* structured stackTrace info is added to every log except is `NO_STACK` is set the 'yes'
|
|
99
|
+
* if the last parameter is a string it will be considered as a `correlationId`
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
### Logging Examples ###
|
|
103
|
+
Listing 2 below show you how to declare a logger to run under ECMAScript 6 and then log using the various log levels supported by the Sumologic-Winston-Logger.
|
|
104
|
+
|
|
105
|
+
``` javascript
|
|
106
|
+
const logger = require('sumologic-winston-logger');
|
|
107
|
+
|
|
108
|
+
logger.log(debug', 'this is a debug statement using log');
|
|
109
|
+
logger.debug({ message: 'this is a debug statement using an object'});
|
|
110
|
+
logger.error('this is an error statement');
|
|
111
|
+
logger.error(new Error('this is an error statement'));
|
|
112
|
+
logger.warn('this is a warning statement', { meta: 'data' });
|
|
113
|
+
logger.info('this is an info statement', { meta: 'data' });
|
|
114
|
+
logger.verbose('this is a verbose statement');
|
|
115
|
+
logger.silly('this is a silly statement o_O');
|
|
116
|
+
logger.debug('this is a debug statement with 2 params', { meta: 'data' });
|
|
117
|
+
logger.debug('this is a debug statement with 2 params and a correlationId', { meta: 'data' }, '123456')
|
|
118
|
+
```
|
|
119
|
+
**Listing 2: Examples of using the logger to make a log entry, using the log levels, log, silly, verbose, debug, info, warn, and error**
|
|
120
|
+
|
|
121
|
+
By default, log entries are logged to console.
|
|
122
|
+
The log() method is also supported, and adds a level parameter in position 1.
|
|
123
|
+
|
|
124
|
+
### Tailing ###
|
|
125
|
+
|
|
126
|
+
Trailing allows you to scroll through log output in real time. You can trail log data in SumoLogic.
|
|
127
|
+
|
|
128
|
+
To trail in SumoLogic go to Search > Live Tail in the SumoLogic user interface and enter `sourceCategory=<source category>` in the search bar, where `<source category>` is the log you want to trail. Then click, Run
|
|
129
|
+
|
|
130
|
+
|Example|
|
|
131
|
+
|---|
|
|
132
|
+
|`sourceCategory=local/node/challengeAPI/logs`|
|
|
133
|
+
|
|
134
|
+
### Stack Trace ###
|
|
135
|
+
All logging to `error()` are added the stack trace.
|
|
136
|
+
All other log levels will include a line number and file name.
|
|
137
|
+
|
|
138
|
+
## License ##
|
|
139
|
+
ISC
|
package/configuration/config.js
CHANGED
|
@@ -1,20 +1,87 @@
|
|
|
1
|
+
/* eslint no-process-env: "off" */
|
|
1
2
|
const _ = require('lodash');
|
|
2
3
|
const fs = require('fs');
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* logger Configuration.
|
|
8
|
+
*
|
|
9
|
+
* @function config
|
|
10
|
+
* @return {object} configuration - logger configuration.
|
|
11
|
+
* @description The following environment variables are needed to configure logger:
|
|
12
|
+
*
|
|
13
|
+
* | Env variable name | Description | Default | Comments |
|
|
14
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
15
|
+
* | SERVER_TYPE | type of the server that is logged | null
|
|
16
|
+
* | SERVER_ID |id of the servier that is logged | null
|
|
17
|
+
* | NODE_ENV | environment of the running instance | local | DEFAULT_ENV
|
|
18
|
+
* | LOG_LEVEL | log level of the running instance | debug | DEFAULT_LEVEL
|
|
19
|
+
* | CONSOLE_LEVEL | log level for the console of the running instance | debug | DEFAULT_LEVEL
|
|
20
|
+
* | FILTER_FILE | filename containing filter rules | null | DEFAULT_FILTER_FILE
|
|
21
|
+
* | EXIT_DELAY | delay when existing gracefully | 2000 | DEFAULT_EXIT_DELAY in ms
|
|
22
|
+
* | NO_STACK | indicatior to log th stack on all log message | no | DEFAULT_NO_STACK
|
|
23
|
+
* | LOG_MODE | string with comma separated words defining the logmode for the running instance | sumologic | DEFAULT_SUMOLOGIC (enum: awsS3, awsKinesis, sumologic, all, none)
|
|
24
|
+
*
|
|
25
|
+
* If `LOG_MODE` includes `sumologic` the following environment variables are needed:
|
|
26
|
+
*
|
|
27
|
+
* | Env variable name | Description | Default | Comments |
|
|
28
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
29
|
+
* | SUMO_LOGIC_ENDPOINT | url of the sumologic collector
|
|
30
|
+
* | SUMO_LOGIC_COLLECTOR_CODE | code of the sumologic collector
|
|
31
|
+
*
|
|
32
|
+
* If `LOG_MODE` includes `awsKinesis` the following environment variables are needed:
|
|
33
|
+
*
|
|
34
|
+
* | Env variable name | Description | Default | Comments |
|
|
35
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
36
|
+
* | KINESIS_AWS_STREAM_NAME_INFO | name of the stream for info level logs
|
|
37
|
+
* | KINESIS_AWS_STREAM_NAME_ERROR | name of the stream for error level logs
|
|
38
|
+
* | KINESIS_AWS_STREAM_NAME_OTHER | name of the stream for any other level logs
|
|
39
|
+
* | KINESIS_AWS_REGION | region of the stream
|
|
40
|
+
* | KINESIS_AWS_TIMEOUT | maximum time before flushing | 1000 | DEFAULT_KINESIS_TIMEOUT in ms
|
|
41
|
+
* | KINESIS_AWS_MAX_SIZE | maximum size of the accumulated logs before flushing | 5 | DEFAULT_KINESIS_MAX_SIZE in mB
|
|
42
|
+
* | KINESIS_AWS_MAX_EVENTS | maximum number of accumulated logs before flushing | 1000 | DEFAULT_KINESIS_MAX_EVENTS
|
|
43
|
+
* | KINESIS_AWS_ACCESS_KEY_ID | access key id of the stream
|
|
44
|
+
* | KINESIS_AWS_SECRET_ACCESS_KEY | access key secret of the stream
|
|
45
|
+
*
|
|
46
|
+
* If `LOG_MODE` includes `awsS3` the following environment variables are needed:
|
|
47
|
+
*
|
|
48
|
+
* | Env variable name | Description | Default | Comments |
|
|
49
|
+
* | ----------------- | ----------- | ------- | -------- |
|
|
50
|
+
* | S3_AWS_BUCKET_NAME | name of the bucket for storing the logs
|
|
51
|
+
* | S3_AWS_REGION | region of the bucket
|
|
52
|
+
* | S3_AWS_TIMEOUT | maximum time before flushing | 5 | DEFAULT_S3_TIMEOUT in minutes
|
|
53
|
+
* | S3_AWS_MAX_SIZE | maximum size of the accumulated logs before flushing | 5 | DEFAULT_S3_MAX_SIZE in mB
|
|
54
|
+
* | S3_AWS_MAX_EVENTS | maximum number of accumulated logs before flushing | 1000 | DEFAULT_S3_MAX_EVENTS
|
|
55
|
+
* | S3_AWS_ACCESS_KEY_ID | access key id of the bucket
|
|
56
|
+
* | S3_AWS_SECRET_ACCESS_KEY | access key secret of the bucket
|
|
57
|
+
*
|
|
58
|
+
* When `LOG_MODE` is `none` the logs will only be on `console`.
|
|
59
|
+
* When `LOG_MODE` is `all` LOG_MODE will be set to `sumologic, awsS3`.
|
|
60
|
+
*
|
|
61
|
+
* 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.
|
|
62
|
+
* If `global.serverType` is set, this value is used over SERVER_TYPE.
|
|
63
|
+
* If `global.serverType` is set, the value of `global.serverId` is used over `SERVER_ID`.
|
|
64
|
+
*/
|
|
4
65
|
const {
|
|
5
66
|
DEFAULT_LEVEL,
|
|
6
67
|
DEFAULT_ENV,
|
|
7
68
|
DEFAULT_FILTER_FILE,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
69
|
+
DEFAULT_S3_MAX_SIZE,
|
|
70
|
+
DEFAULT_S3_MAX_EVENTS,
|
|
71
|
+
DEFAULT_S3_TIMEOUT,
|
|
72
|
+
DEFAULT_KINESIS_MAX_SIZE,
|
|
73
|
+
DEFAULT_KINESIS_MAX_EVENTS,
|
|
74
|
+
DEFAULT_KINESIS_TIMEOUT,
|
|
11
75
|
DEFAULT_MODE,
|
|
12
76
|
DEFAULT_EXIT_DELAY,
|
|
13
77
|
DEFAULT_NO_STACK,
|
|
14
78
|
SUMOLOGIC,
|
|
15
79
|
AWS_S3,
|
|
80
|
+
AWS_KINESIS,
|
|
16
81
|
ALL,
|
|
17
|
-
|
|
82
|
+
NONE,
|
|
83
|
+
ALL_MODES,
|
|
84
|
+
} = require('../lib/common');
|
|
18
85
|
|
|
19
86
|
const checkConfig = (config) => {
|
|
20
87
|
const errs = [];
|
|
@@ -34,6 +101,19 @@ const checkConfig = (config) => {
|
|
|
34
101
|
}
|
|
35
102
|
};
|
|
36
103
|
|
|
104
|
+
const checkMode = (mode) => {
|
|
105
|
+
let logMode = null;
|
|
106
|
+
|
|
107
|
+
if (mode) {
|
|
108
|
+
logMode = _.split(_.trim(mode), /\s*,\s*/);
|
|
109
|
+
if (logMode.length === 0) throw new Error('Invalid LOG_MODE: cannot be an empty array');
|
|
110
|
+
if (_.difference(logMode, ALL_MODES).length !== 0) throw new Error(`Invalid items in LOG_MODE: ${mode}`);
|
|
111
|
+
if (logMode.includes(NONE) && logMode.length !== 1) throw new Error(`Cannot have multiple modes when ${NONE} is selected`);
|
|
112
|
+
if (logMode.includes(ALL)) logMode = [SUMOLOGIC, AWS_S3]; // legacy support
|
|
113
|
+
}
|
|
114
|
+
return logMode;
|
|
115
|
+
};
|
|
116
|
+
|
|
37
117
|
const configuration = {
|
|
38
118
|
server: {
|
|
39
119
|
type: process.env.SERVER_TYPE || null,
|
|
@@ -42,32 +122,47 @@ const configuration = {
|
|
|
42
122
|
env: process.env.NODE_ENV || DEFAULT_ENV,
|
|
43
123
|
level: {
|
|
44
124
|
log: process.env.LOG_LEVEL || DEFAULT_LEVEL,
|
|
45
|
-
console: process.env.CONSOLE_LEVEL ||
|
|
125
|
+
console: process.env.CONSOLE_LEVEL || DEFAULT_LEVEL,
|
|
46
126
|
},
|
|
47
|
-
mode: process.env.LOG_MODE || DEFAULT_MODE,
|
|
48
127
|
filter: {
|
|
49
128
|
file: process.env.FILTER_FILE || DEFAULT_FILTER_FILE,
|
|
50
129
|
},
|
|
51
130
|
exitDelay: parseInt(process.env.EXIT_DELAY, 10) || DEFAULT_EXIT_DELAY, // in ms
|
|
52
131
|
noStack: process.env.NO_STACK || DEFAULT_NO_STACK,
|
|
53
132
|
};
|
|
133
|
+
configuration.mode = checkMode(process.env.LOG_MODE) || DEFAULT_MODE;
|
|
54
134
|
|
|
55
|
-
if (configuration.mode
|
|
135
|
+
if (configuration.mode.includes(SUMOLOGIC)) {
|
|
56
136
|
configuration[SUMOLOGIC] = {
|
|
57
137
|
endpoint: process.env.SUMO_LOGIC_ENDPOINT,
|
|
58
138
|
code: process.env.SUMO_LOGIC_COLLECTOR_CODE,
|
|
59
139
|
};
|
|
60
140
|
}
|
|
61
|
-
if (configuration.mode
|
|
141
|
+
if (configuration.mode.includes(AWS_KINESIS)) {
|
|
142
|
+
configuration[AWS_KINESIS] = {
|
|
143
|
+
streamNameInfo: process.env.KINESIS_AWS_STREAM_NAME_INFO,
|
|
144
|
+
streamNameError: process.env.KINESIS_AWS_STREAM_NAME_ERROR,
|
|
145
|
+
streamNameOther: process.env.KINESIS_AWS_STREAM_NAME_OTHER,
|
|
146
|
+
region: process.env.KINESIS_AWS_REGION,
|
|
147
|
+
timeout: parseInt(process.env.KINESIS_AWS_TIMEOUT, 10) || DEFAULT_KINESIS_TIMEOUT, // in ms
|
|
148
|
+
maxSize: parseInt(process.env.KINESIS_AWS_MAX_SIZE, 10) || DEFAULT_KINESIS_MAX_SIZE, // in mB
|
|
149
|
+
maxEvents: parseInt(process.env.KINESIS_AWS_MAX_EVENTS, 10) || DEFAULT_KINESIS_MAX_EVENTS,
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
if (!_.isNil(process.env.KINESIS_AWS_ACCESS_KEY_ID)) configuration[AWS_KINESIS].accessKeyId = process.env.KINESIS_AWS_ACCESS_KEY_ID;
|
|
153
|
+
if (!_.isNil(process.env.KINESIS_AWS_SECRET_ACCESS_KEY)) configuration[AWS_KINESIS].secretAccessKey = process.env.KINESIS_AWS_SECRET_ACCESS_KEY;
|
|
154
|
+
}
|
|
155
|
+
if (configuration.mode.includes(AWS_S3)) {
|
|
62
156
|
configuration[AWS_S3] = {
|
|
63
|
-
accessKeyId: process.env.S3_AWS_ACCESS_KEY_ID,
|
|
64
|
-
secretAccessKey: process.env.S3_AWS_SECRET_ACCESS_KEY,
|
|
65
157
|
bucketname: process.env.S3_AWS_BUCKET_NAME,
|
|
66
158
|
region: process.env.S3_AWS_REGION,
|
|
67
|
-
timeout: parseInt(process.env.S3_AWS_TIMEOUT, 10) ||
|
|
68
|
-
maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, 10) ||
|
|
69
|
-
maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, 10) ||
|
|
159
|
+
timeout: parseInt(process.env.S3_AWS_TIMEOUT, 10) || DEFAULT_S3_TIMEOUT, // in minutes
|
|
160
|
+
maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, 10) || DEFAULT_S3_MAX_SIZE, // in mB
|
|
161
|
+
maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, 10) || DEFAULT_S3_MAX_EVENTS,
|
|
70
162
|
};
|
|
163
|
+
|
|
164
|
+
if (!_.isNil(process.env.S3_AWS_ACCESS_KEY_ID)) configuration[AWS_S3].accessKeyId = process.env.S3_AWS_ACCESS_KEY_ID;
|
|
165
|
+
if (!_.isNil(process.env.S3_AWS_SECRET_ACCESS_KEY)) configuration[AWS_S3].secretAccessKey = process.env.S3_AWS_SECRET_ACCESS_KEY;
|
|
71
166
|
}
|
|
72
167
|
const { filter } = configuration;
|
|
73
168
|
let filterConfig = [];
|
package/index.js
CHANGED
|
@@ -2,6 +2,7 @@ const { createLogger, format, transports } = require('winston');
|
|
|
2
2
|
|
|
3
3
|
const Sumologic = require('./lib/sumologicTransport');
|
|
4
4
|
const AwsS3 = require('./lib/awsS3Transport');
|
|
5
|
+
const AwsKinesis = require('./lib/awsKinesisTransport');
|
|
5
6
|
const {
|
|
6
7
|
stackInfo,
|
|
7
8
|
errorStack,
|
|
@@ -12,14 +13,16 @@ const config = require('./configuration/config');
|
|
|
12
13
|
const {
|
|
13
14
|
SUMOLOGIC,
|
|
14
15
|
AWS_S3,
|
|
15
|
-
|
|
16
|
+
AWS_KINESIS,
|
|
17
|
+
NONE,
|
|
16
18
|
WARN,
|
|
17
19
|
// LOG,
|
|
18
20
|
FLUSH,
|
|
19
21
|
} = require('./lib/common');
|
|
20
22
|
|
|
21
23
|
let sumo;
|
|
22
|
-
let
|
|
24
|
+
let awsS3;
|
|
25
|
+
let awsKinesis;
|
|
23
26
|
|
|
24
27
|
const miniLog = createLogger({
|
|
25
28
|
format: format.combine(format.metadata(), correlationId(), format.timestamp(), format.prettyPrint({ colorize: true })),
|
|
@@ -31,7 +34,13 @@ const miniLog = createLogger({
|
|
|
31
34
|
});
|
|
32
35
|
|
|
33
36
|
const logger = createLogger({
|
|
34
|
-
format: format.combine(
|
|
37
|
+
format: format.combine(
|
|
38
|
+
filterMeta({ env: config.env, config: config.filter.config }),
|
|
39
|
+
errorStack(),
|
|
40
|
+
format.metadata(),
|
|
41
|
+
stackInfo({ env: config.env, noStack: config.noStack }),
|
|
42
|
+
correlationId(),
|
|
43
|
+
),
|
|
35
44
|
transports: [
|
|
36
45
|
new transports.Console({
|
|
37
46
|
level: config.level.console,
|
|
@@ -40,19 +49,20 @@ const logger = createLogger({
|
|
|
40
49
|
],
|
|
41
50
|
});
|
|
42
51
|
|
|
43
|
-
if (config.mode
|
|
52
|
+
if (config.mode.includes(SUMOLOGIC)) {
|
|
44
53
|
sumo = new Sumologic({
|
|
45
54
|
level: config.level.log,
|
|
46
55
|
endpoint: config[SUMOLOGIC].endpoint,
|
|
47
56
|
code: config[SUMOLOGIC].code,
|
|
57
|
+
serverType: config.server.type,
|
|
58
|
+
serverId: config.server.id,
|
|
48
59
|
});
|
|
49
|
-
|
|
50
|
-
sumo.on(
|
|
51
|
-
// sumo.on(LOG, () => console.log('sumo done')); // miniLog.info('Information sent to sumologic: ', data));
|
|
60
|
+
sumo.on(WARN, (data) => miniLog.warn('Could not send logs: ', data, data.correlationId));
|
|
61
|
+
// sumo.on(LOG, (data) => console.log('sumo done')); // miniLog.info('Information sent: ', data));
|
|
52
62
|
logger.add(sumo);
|
|
53
63
|
}
|
|
54
|
-
if (config.mode
|
|
55
|
-
|
|
64
|
+
if (config.mode.includes(AWS_S3)) {
|
|
65
|
+
awsS3 = new AwsS3({
|
|
56
66
|
level: config.level.log,
|
|
57
67
|
bucketname: config[AWS_S3].bucketname,
|
|
58
68
|
region: config[AWS_S3].region,
|
|
@@ -65,33 +75,60 @@ if (config.mode === AWS_S3 || config.mode === ALL) {
|
|
|
65
75
|
serverId: config.server.id,
|
|
66
76
|
format: format.combine(format.timestamp(), format.json()),
|
|
67
77
|
});
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
awsS3.on(WARN, (data) => miniLog.warn('Could not send logs: ', data));
|
|
79
|
+
// awsS3.on(LOG, (data) => console.log('awsS3 done')); // miniLog.info('Information sent : ', data));
|
|
80
|
+
logger.add(awsS3);
|
|
81
|
+
}
|
|
82
|
+
if (config.mode.includes(AWS_KINESIS)) {
|
|
83
|
+
awsKinesis = new AwsKinesis({
|
|
84
|
+
level: config.level.log,
|
|
85
|
+
streamNameInfo: config[AWS_KINESIS].streamNameInfo,
|
|
86
|
+
streamNameError: config[AWS_KINESIS].streamNameError,
|
|
87
|
+
streamNameOther: config[AWS_KINESIS].streamNameOther,
|
|
88
|
+
region: config[AWS_KINESIS].region,
|
|
89
|
+
accessKeyId: config[AWS_KINESIS].accessKeyId,
|
|
90
|
+
secretAccessKey: config[AWS_KINESIS].secretAccessKey,
|
|
91
|
+
serverType: config.server.type,
|
|
92
|
+
serverId: config.server.id,
|
|
93
|
+
format: format.combine(format.timestamp(), format.json()),
|
|
94
|
+
});
|
|
95
|
+
awsKinesis.on(WARN, (data) => miniLog.warn('Could not send logs: ', data));
|
|
96
|
+
// awsKinesis.on(LOG, (data) => console.log('awsKinesis done')); // miniLog.info('Information sent: ', data));
|
|
97
|
+
logger.add(awsKinesis);
|
|
72
98
|
}
|
|
73
99
|
|
|
74
100
|
logger.flushAndExit = (code) => {
|
|
75
101
|
const flushing = () => {
|
|
76
102
|
let sumoDone = false;
|
|
77
|
-
let
|
|
103
|
+
let awsS3Done = false;
|
|
104
|
+
let awsKinesisDone = false;
|
|
78
105
|
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
106
|
+
if (config.mode.includes(NONE)) return process.exit(code);
|
|
107
|
+
if (awsS3) {
|
|
108
|
+
awsS3.flush();
|
|
109
|
+
awsS3.on(FLUSH, () => {
|
|
110
|
+
if ((!sumo || sumoDone) && (!awsKinesis || awsKinesisDone)) return process.exit(code);
|
|
111
|
+
awsS3Done = true;
|
|
84
112
|
return null;
|
|
85
113
|
});
|
|
86
114
|
}
|
|
87
115
|
if (sumo) {
|
|
88
116
|
sumo.flush();
|
|
89
117
|
sumo.on(FLUSH, () => {
|
|
90
|
-
if (!
|
|
118
|
+
if ((!awsS3 || awsS3Done) && (!awsKinesis || awsKinesisDone)) return process.exit(code);
|
|
91
119
|
sumoDone = true;
|
|
92
120
|
return null;
|
|
93
121
|
});
|
|
94
122
|
}
|
|
123
|
+
if (awsKinesis) {
|
|
124
|
+
awsKinesis.flush();
|
|
125
|
+
awsKinesis.on(FLUSH, () => {
|
|
126
|
+
if ((!awsS3 || awsS3Done) && (!sumo || sumoDone)) return process.exit(code);
|
|
127
|
+
awsKinesisDone = true;
|
|
128
|
+
return null;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
95
132
|
};
|
|
96
133
|
|
|
97
134
|
setTimeout(flushing, config.exitDelay);
|