@mimik/sumologic-winston-logger 1.1.2 → 1.6.6

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 CHANGED
@@ -1,17 +1,34 @@
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}],
9
15
  "brace-style": [1, "stroustrup", {"allowSingleLine": true}],
10
16
  "no-confusing-arrow": [0], // arrow isnt confusing
11
17
  "max-len": [1, 180, { "ignoreComments": true }],
12
18
  "linebreak-style": 0,
13
19
  "quotes": [1, "single"],
14
- "semi": [1, "always"]
20
+ "semi": [1, "always"],
21
+ "no-process-env": ["error"],
22
+ "@mimik/document-env/validate-document-env": 2,
23
+ "@mimik/dependencies/case-sensitive": 2,
24
+ "@mimik/dependencies/no-cycles": 2,
25
+ "@mimik/dependencies/no-unresolved": 2,
26
+ "@mimik/dependencies/require-json-ext": 2
27
+ },
28
+ "settings":{
29
+ "react": {
30
+ "version": "latest"
31
+ }
15
32
  },
16
33
  "globals": {
17
34
  "module": true,
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run commit-ready
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm run test
package/.nycrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "exclude": ["gulpfile.js"],
3
+ "reporter": ["lcov", "text"]
4
+ }
package/Gulpfile.js CHANGED
@@ -1,34 +1,49 @@
1
1
  /* eslint-disable import/no-extraneous-dependencies */
2
- const mocha = require('gulp-spawn-mocha');
3
- const istanbul = require('gulp-istanbul');
4
- const gulp = require('gulp');
5
2
  const eslint = require('gulp-eslint');
3
+ const fs = require('fs');
4
+ const git = require('gulp-git');
5
+ const gulp = require('gulp');
6
+ const jsdoc2md = require('jsdoc-to-markdown');
7
+ const log = require('fancy-log');
8
+ const mocha = require('gulp-spawn-mocha');
6
9
 
7
10
  const files = [
8
11
  'index.js',
9
12
  'Gulpfile.js',
10
13
  'configuration/*.js',
11
- 'test/*.spec.js',
14
+ 'test/**.js',
12
15
  'lib/**.js',
13
16
  ];
14
17
 
18
+ const createDocs = (done) => {
19
+ jsdoc2md.render({ files: 'configuration/config.js' })
20
+ .then((output) => {
21
+ let supplement;
22
+
23
+ if (fs.existsSync('README_Supplement.md')) {
24
+ supplement = fs.readFileSync('README_Supplement.md').toString();
25
+ }
26
+ fs.writeFileSync('README.md', output.concat(supplement));
27
+ })
28
+ .catch((err) => log.error('docs creation failed:', err.message))
29
+ .finally(() => done());
30
+ };
31
+
15
32
  const lint = () => gulp.src(files)
16
33
  .pipe(eslint({}))
17
- .pipe(eslint.format())
18
- .pipe(eslint.failOnError());
34
+ .pipe(eslint.format());
19
35
 
20
- const presetTest = () => gulp.src(files)
21
- .pipe(istanbul({ includeUntested: true }))
22
- .pipe(istanbul.hookRequire());
36
+ const add = () => gulp.src('README.md')
37
+ .pipe(git.add({ quiet: true }));
23
38
 
24
- const runTest = () => gulp.src('test/*.spec.js')
39
+ const test = () => gulp.src(['test/*.spec.js'])
25
40
  .pipe(mocha({
26
41
  reporter: 'mochawesome',
27
- istanbul: true,
28
42
  exit: true,
29
43
  }));
30
44
 
31
- const test = gulp.series(presetTest, runTest);
45
+ const docs = gulp.series(createDocs, add);
32
46
 
47
+ gulp.task('docs', docs);
33
48
  gulp.task('lint', lint);
34
49
  gulp.task('test', test);
package/README.md CHANGED
@@ -1,7 +1,67 @@
1
+ <a name="config"></a>
2
+
3
+ ## config() ⇒ <code>object</code>
4
+ The following environment variables are needed to configure logger:
5
+
6
+ | Env variable name | Description | Default | Comments |
7
+ | ----------------- | ----------- | ------- | -------- |
8
+ | SERVER_TYPE | type of the server that is logged | null
9
+ | SERVER_ID |id of the servier that is logged | null
10
+ | NODE_ENV | environment of the running instance | local | DEFAULT_ENV
11
+ | LOG_LEVEL | log level of the running instance | debug | DEFAULT_LEVEL
12
+ | CONSOLE_LEVEL | log level for the console of the running instance | debug | DEFAULT_LEVEL
13
+ | FILTER_FILE | filename containing filter rules | null | DEFAULT_FILTER_FILE
14
+ | EXIT_DELAY | delay when existing gracefully | 2000 | DEFAULT_EXIT_DELAY in ms
15
+ | NO_STACK | indicatior to log th stack on all log message | no | DEFAULT_NO_STACK
16
+ | LOG_MODE | string with comma separated words defining the logmode for the running instance | sumologic | DEFAULT_SUMOLOGIC (enum: awsS3, awsKinesis, sumologic, all, none)
17
+
18
+ If `LOG_MODE` includes `sumologic` the following environment variables are needed:
19
+
20
+ | Env variable name | Description | Default | Comments |
21
+ | ----------------- | ----------- | ------- | -------- |
22
+ | SUMO_LOGIC_ENDPOINT | url of the sumologic collector
23
+ | SUMO_LOGIC_COLLECTOR_CODE | code of the sumologic collector
24
+
25
+ If `LOG_MODE` includes `awsKinesis` the following environment variables are needed:
26
+
27
+ | Env variable name | Description | Default | Comments |
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 | DEFAULT_KINESIS_TIMEOUT in ms
34
+ | KINESIS_AWS_MAX_SIZE | maximum size of the accumulated logs before flushing | 5 | DEFAULT_KINESIS_MAX_SIZE in mB
35
+ | KINESIS_AWS_MAX_EVENTS | maximum number of accumulated logs before flushing | 1000 | DEFAULT_KINESIS_MAX_EVENTS
36
+ | KINESIS_AWS_ACCESS_KEY_ID | access key id of the stream
37
+ | KINESIS_AWS_SECRET_ACCESS_KEY | access key secret of the stream
38
+
39
+ If `LOG_MODE` includes `awsS3` the following environment variables are needed:
40
+
41
+ | Env variable name | Description | Default | Comments |
42
+ | ----------------- | ----------- | ------- | -------- |
43
+ | S3_AWS_BUCKET_NAME | name of the bucket for storing the logs
44
+ | S3_AWS_REGION | region of the bucket
45
+ | S3_AWS_TIMEOUT | maximum time before flushing | 5 | DEFAULT_S3_TIMEOUT in minutes
46
+ | S3_AWS_MAX_SIZE | maximum size of the accumulated logs before flushing | 5 | DEFAULT_S3_MAX_SIZE in mB
47
+ | S3_AWS_MAX_EVENTS | maximum number of accumulated logs before flushing | 1000 | DEFAULT_S3_MAX_EVENTS
48
+ | S3_AWS_ACCESS_KEY_ID | access key id of the bucket
49
+ | S3_AWS_SECRET_ACCESS_KEY | access key secret of the bucket
50
+
51
+ When `LOG_MODE` is `none` the logs will only be on `console`.
52
+ When `LOG_MODE` is `all` LOG_MODE will be set to `sumologic, awsS3`.
53
+
54
+ 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.
55
+ If `global.serverType` is set, this value is used over SERVER_TYPE.
56
+ If `global.serverType` is set, the value of `global.serverId` is used over `SERVER_ID`.
57
+
58
+ **Kind**: global function
59
+ **Returns**: <code>object</code> - configuration - logger configuration.
60
+
1
61
  ## Synopsis ##
2
62
 
3
63
  Sumologic-Winston-Logger is a log wrapper that can write to multiple logging services.
4
- Currently, Winston, SumoLogic, and AWS S2 are supported.
64
+ Currently, Winston, SumoLogic, AWS Kinesis and AWS S3 are supported.
5
65
  The package also adds strackTrace info.
6
66
  StackTrace information gets tacked on to Sumologic calls, In addition and method, module, and line info or
7
67
  concatenated is added to the end of winston lines. **Line formatting is not currently configrable.**
@@ -17,35 +77,9 @@ The logger is discoverable on npmjs.org.
17
77
  To install:
18
78
  ```
19
79
  npm install sumologic-winston-logger --save
80
+ ```
20
81
 
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`.
82
+ ## Configuration - Details ##
49
83
 
50
84
  The following sections decribe the details of each of the environment variables listed above.
51
85
 
@@ -82,7 +116,7 @@ The collector code as defined in SumoLogic. The Collector Code is the Base64 str
82
116
 
83
117
  To learn more about setting this environment variable, see the section, _Finding SumoLogic endpoint and collector code_, below.
84
118
 
85
- ## Finding SumoLogic endpoint and collector code ##
119
+ #### Finding SumoLogic endpoint and collector code ####
86
120
 
87
121
  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
122
 
@@ -107,10 +141,10 @@ The collector code is the Base64 encrypted part of the URL that follows the last
107
141
  ### `FILTER_FILE` ###
108
142
 
109
143
  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.
144
+ 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.
111
145
  The filter will replace values of the designated property names to '-----'.
112
146
 
113
- ### Sample Use ###
147
+ ## Sample Use ##
114
148
 
115
149
  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
150
 
@@ -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
+ ![Screen Shot 2016-10-10 at 2.03.31 PM.png](https://bitbucket.org/repo/xbXGRo/images/3258406172-Screen%20Shot%202016-10-10%20at%202.03.31%20PM.png)
65
+
66
+ **Figure 1: Select the Manage -> Collection to display a list of collectors in force**
67
+
68
+
69
+ ![Screen Shot 2016-10-10 at 2.03.57 PM.png](https://bitbucket.org/repo/xbXGRo/images/1501199325-Screen%20Shot%202016-10-10%20at%202.03.57%20PM.png)
70
+
71
+ **Figure 2: Click the link, Show URL to display the URL configuration for the given collector**
72
+
73
+ ![Screen Shot 2016-10-10 at 2.04.18 PM.png](https://bitbucket.org/repo/xbXGRo/images/1913524258-Screen%20Shot%202016-10-10%20at%202.04.18%20PM.png)
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
@@ -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
- DEFAULT_MAX_SIZE,
9
- DEFAULT_MAX_EVENTS,
10
- DEFAULT_TIMEOUT,
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
- } = require('../lib/common.js');
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 || process.env.LOG_LEVEL || DEFAULT_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 === SUMOLOGIC || configuration.mode === ALL) {
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 === AWS_S3 || configuration.mode === ALL) {
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) || DEFAULT_TIMEOUT, // in minutes
68
- maxSize: parseInt(process.env.S3_AWS_MAX_SIZE, 10) || DEFAULT_MAX_SIZE, // in mB
69
- maxEvents: parseInt(process.env.S3_AWS_MAX_EVENTS, 10) || DEFAULT_MAX_EVENTS,
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 = [];