elasticio-sailor-nodejs 2.7.1-dev3 → 2.7.1-dev4

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/lib/logging.js CHANGED
@@ -1,97 +1,97 @@
1
- 'use strict';
2
-
3
- const bunyan = require('bunyan');
4
- const _ = require('lodash');
5
-
6
- let level;
7
-
8
- if (process.env.NODE_ENV === 'test') {
9
- level = process.env.LOG_LEVEL || (bunyan.FATAL + 1); // turn off logging by default
10
- } else {
11
- level = process.env.LOG_LEVEL || 'info';
12
- }
13
-
14
- const data = Object.assign(
15
- _.pick(process.env, [
16
- 'ELASTICIO_API_USERNAME',
17
- 'ELASTICIO_COMP_ID',
18
- 'ELASTICIO_COMP_NAME',
19
- 'ELASTICIO_CONTAINER_ID',
20
- 'ELASTICIO_CONTRACT_ID',
21
- 'ELASTICIO_EXEC_ID',
22
- 'ELASTICIO_EXEC_TYPE',
23
- 'ELASTICIO_EXECUTION_RESULT_ID',
24
- 'ELASTICIO_FLOW_ID',
25
- 'ELASTICIO_FLOW_VERSION',
26
- 'ELASTICIO_FUNCTION',
27
- 'ELASTICIO_STEP_ID',
28
- 'ELASTICIO_TASK_USER_EMAIL',
29
- 'ELASTICIO_TENANT_ID',
30
- 'ELASTICIO_USER_ID',
31
- 'ELASTICIO_WORKSPACE_ID'
32
- ]),
33
- { tag: process.env.ELASTICIO_FLOW_ID }
34
- );
35
-
36
- const log = bunyan.createLogger({
37
- name: 'sailor',
38
- level: level,
39
- serializers: bunyan.stdSerializers
40
- })
41
- .child(data);
42
-
43
- _.bindAll(log, [
44
- 'fatal',
45
- 'error',
46
- 'warn',
47
- 'info',
48
- 'debug',
49
- 'trace'
50
- ]);
51
-
52
- function criticalErrorAndExit(reason, err) {
53
- if (err instanceof Error) {
54
- log.fatal(err, reason);
55
- } else {
56
- log.fatal({ err, reason }, 'Error happened');
57
- }
58
-
59
- process.exit(1);
60
- }
61
-
62
- function ComponentLogger(options) {
63
- const logger = bunyan.createLogger({
64
- name: 'component',
65
- level: level,
66
- serializers: bunyan.stdSerializers
67
- })
68
- .child(data)
69
- .child(options);
70
-
71
- function decorateLogger(destination, logger) {
72
- for (let type of ['trace', 'debug', 'info', 'warn', 'error', 'fatal']) {
73
- const originalMethod = logger[type];
74
- destination[type] = function log() {
75
- const args = Array.prototype.slice.call(arguments);
76
-
77
- if (args.length && typeof args[0] !== 'string') {
78
- args[0] = String(args[0]);
79
- }
80
-
81
- return originalMethod.call(logger, ...args);
82
- };
83
- }
84
- const originalMethod = logger.child;
85
- destination.child = function child(...args) {
86
- const childLogger = originalMethod.call(logger, ...args);
87
- decorateLogger(childLogger, childLogger);
88
- return childLogger;
89
- };
90
- }
91
- decorateLogger(this, logger);
92
- }
93
-
94
-
95
- module.exports = log;
96
- module.exports.ComponentLogger = ComponentLogger;
97
- module.exports.criticalErrorAndExit = criticalErrorAndExit;
1
+ 'use strict';
2
+
3
+ const bunyan = require('bunyan');
4
+ const _ = require('lodash');
5
+
6
+ let level;
7
+
8
+ if (process.env.NODE_ENV === 'test') {
9
+ level = process.env.LOG_LEVEL || (bunyan.FATAL + 1); // turn off logging by default
10
+ } else {
11
+ level = process.env.LOG_LEVEL || 'info';
12
+ }
13
+
14
+ const data = Object.assign(
15
+ _.pick(process.env, [
16
+ 'ELASTICIO_API_USERNAME',
17
+ 'ELASTICIO_COMP_ID',
18
+ 'ELASTICIO_COMP_NAME',
19
+ 'ELASTICIO_CONTAINER_ID',
20
+ 'ELASTICIO_CONTRACT_ID',
21
+ 'ELASTICIO_EXEC_ID',
22
+ 'ELASTICIO_EXEC_TYPE',
23
+ 'ELASTICIO_EXECUTION_RESULT_ID',
24
+ 'ELASTICIO_FLOW_ID',
25
+ 'ELASTICIO_FLOW_VERSION',
26
+ 'ELASTICIO_FUNCTION',
27
+ 'ELASTICIO_STEP_ID',
28
+ 'ELASTICIO_TASK_USER_EMAIL',
29
+ 'ELASTICIO_TENANT_ID',
30
+ 'ELASTICIO_USER_ID',
31
+ 'ELASTICIO_WORKSPACE_ID'
32
+ ]),
33
+ { tag: process.env.ELASTICIO_FLOW_ID }
34
+ );
35
+
36
+ const log = bunyan.createLogger({
37
+ name: 'sailor',
38
+ level: level,
39
+ serializers: bunyan.stdSerializers
40
+ })
41
+ .child(data);
42
+
43
+ _.bindAll(log, [
44
+ 'fatal',
45
+ 'error',
46
+ 'warn',
47
+ 'info',
48
+ 'debug',
49
+ 'trace'
50
+ ]);
51
+
52
+ function criticalErrorAndExit(reason, err) {
53
+ if (err instanceof Error) {
54
+ log.fatal(err, reason);
55
+ } else {
56
+ log.fatal({ err, reason }, 'Error happened');
57
+ }
58
+
59
+ process.exit(1);
60
+ }
61
+
62
+ function ComponentLogger(options) {
63
+ const logger = bunyan.createLogger({
64
+ name: 'component',
65
+ level: level,
66
+ serializers: bunyan.stdSerializers
67
+ })
68
+ .child(data)
69
+ .child(options);
70
+
71
+ function decorateLogger(destination, logger) {
72
+ for (let type of ['trace', 'debug', 'info', 'warn', 'error', 'fatal']) {
73
+ const originalMethod = logger[type];
74
+ destination[type] = function log() {
75
+ const args = Array.prototype.slice.call(arguments);
76
+
77
+ if (args.length && typeof args[0] !== 'string') {
78
+ args[0] = String(args[0]);
79
+ }
80
+
81
+ return originalMethod.call(logger, ...args);
82
+ };
83
+ }
84
+ const originalMethod = logger.child;
85
+ destination.child = function child(...args) {
86
+ const childLogger = originalMethod.call(logger, ...args);
87
+ decorateLogger(childLogger, childLogger);
88
+ return childLogger;
89
+ };
90
+ }
91
+ decorateLogger(this, logger);
92
+ }
93
+
94
+
95
+ module.exports = log;
96
+ module.exports.ComponentLogger = ComponentLogger;
97
+ module.exports.criticalErrorAndExit = criticalErrorAndExit;