@emartech/json-logger 8.1.1 → 9.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/dist/config.js +7 -7
- package/dist/index.js +6 -5
- package/dist/logger/logger.js +8 -6
- package/dist/logger/logger.spec.js +10 -8
- package/dist/timer/timer.js +2 -0
- package/package.json +24 -24
package/dist/config.js
CHANGED
|
@@ -4,28 +4,28 @@ exports.config = void 0;
|
|
|
4
4
|
const levels = {
|
|
5
5
|
trace: {
|
|
6
6
|
number: 10,
|
|
7
|
-
name: 'TRACE'
|
|
7
|
+
name: 'TRACE',
|
|
8
8
|
},
|
|
9
9
|
debug: {
|
|
10
10
|
number: 20,
|
|
11
|
-
name: 'DEBUG'
|
|
11
|
+
name: 'DEBUG',
|
|
12
12
|
},
|
|
13
13
|
info: {
|
|
14
14
|
number: 30,
|
|
15
|
-
name: 'INFO'
|
|
15
|
+
name: 'INFO',
|
|
16
16
|
},
|
|
17
17
|
warn: {
|
|
18
18
|
number: 40,
|
|
19
|
-
name: 'WARN'
|
|
19
|
+
name: 'WARN',
|
|
20
20
|
},
|
|
21
21
|
error: {
|
|
22
22
|
number: 50,
|
|
23
|
-
name: 'ERROR'
|
|
23
|
+
name: 'ERROR',
|
|
24
24
|
},
|
|
25
25
|
fatal: {
|
|
26
26
|
number: 60,
|
|
27
|
-
name: 'FATAL'
|
|
28
|
-
}
|
|
27
|
+
name: 'FATAL',
|
|
28
|
+
},
|
|
29
29
|
};
|
|
30
30
|
const availableLevels = Object.keys(levels);
|
|
31
31
|
exports.config = { levels, availableLevels };
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Timer = exports.Logger = void 0;
|
|
4
|
+
exports.createLogger = createLogger;
|
|
5
|
+
const enabled_1 = require("./enabled/enabled");
|
|
6
|
+
const formatter_1 = require("./formatter");
|
|
4
7
|
const logger_1 = require("./logger/logger");
|
|
5
8
|
var logger_2 = require("./logger/logger");
|
|
6
9
|
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_2.Logger; } });
|
|
7
10
|
var timer_1 = require("./timer/timer");
|
|
8
11
|
Object.defineProperty(exports, "Timer", { enumerable: true, get: function () { return timer_1.Timer; } });
|
|
9
|
-
|
|
10
|
-
const formatter_1 = require("./formatter");
|
|
12
|
+
// eslint-disable-next-line func-style
|
|
11
13
|
function createLogger(namespace) {
|
|
12
14
|
return new logger_1.Logger(namespace, (0, enabled_1.isNamespaceEnabled)(createLogger.getNamespaces(), namespace));
|
|
13
15
|
}
|
|
14
|
-
exports.createLogger = createLogger;
|
|
15
16
|
createLogger.getNamespaces = function () {
|
|
16
|
-
return process.env.DEBUG
|
|
17
|
+
return process.env.DEBUG ?? '';
|
|
17
18
|
};
|
|
18
19
|
createLogger.configure = function (options) {
|
|
19
20
|
logger_1.Logger.configure(options);
|
package/dist/logger/logger.js
CHANGED
|
@@ -10,6 +10,8 @@ const console_1 = require("../output/console");
|
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
11
|
const allowedKeys = ['output', 'formatter', 'transformers', 'outputFormat'];
|
|
12
12
|
class Logger {
|
|
13
|
+
namespace;
|
|
14
|
+
enabled;
|
|
13
15
|
constructor(namespace, enabled) {
|
|
14
16
|
this.namespace = namespace;
|
|
15
17
|
this.enabled = enabled;
|
|
@@ -25,6 +27,12 @@ class Logger {
|
|
|
25
27
|
}
|
|
26
28
|
});
|
|
27
29
|
}
|
|
30
|
+
static config = {
|
|
31
|
+
formatter: json_1.jsonFormatter,
|
|
32
|
+
output: console_1.consoleOutput,
|
|
33
|
+
transformers: [],
|
|
34
|
+
outputFormat: 'ecs',
|
|
35
|
+
};
|
|
28
36
|
isEnabled() {
|
|
29
37
|
return this.enabled;
|
|
30
38
|
}
|
|
@@ -163,9 +171,3 @@ class Logger {
|
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
exports.Logger = Logger;
|
|
166
|
-
Logger.config = {
|
|
167
|
-
formatter: json_1.jsonFormatter,
|
|
168
|
-
output: console_1.consoleOutput,
|
|
169
|
-
transformers: [],
|
|
170
|
-
outputFormat: 'ecs',
|
|
171
|
-
};
|
|
@@ -3,12 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const axios_1 = require("axios");
|
|
6
7
|
const chai_1 = require("chai");
|
|
7
8
|
const sinon_1 = __importDefault(require("sinon"));
|
|
8
|
-
const logger_1 = require("./logger");
|
|
9
9
|
const json_1 = require("../formatter/json");
|
|
10
10
|
const console_1 = require("../output/console");
|
|
11
|
-
const
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
12
|
describe('Logger', () => {
|
|
13
13
|
let logger;
|
|
14
14
|
let clock;
|
|
@@ -152,11 +152,12 @@ describe('Logger', () => {
|
|
|
152
152
|
statusText: 'Something horrible happened',
|
|
153
153
|
data: { useful_detail: 'important info' },
|
|
154
154
|
headers: {},
|
|
155
|
-
config: {},
|
|
155
|
+
config: { headers: {} },
|
|
156
156
|
};
|
|
157
157
|
error.config = {
|
|
158
158
|
url: 'http://amazinghost.com/beautiful-path',
|
|
159
159
|
method: 'get',
|
|
160
|
+
headers: {},
|
|
160
161
|
};
|
|
161
162
|
logger.fromError('hi', error, { details: 'here' });
|
|
162
163
|
const logArguments = JSON.parse(outputStub.args[0][0]);
|
|
@@ -180,11 +181,12 @@ describe('Logger', () => {
|
|
|
180
181
|
statusText: 'Something horrible happened',
|
|
181
182
|
data: { useful_detail: 'important info' },
|
|
182
183
|
headers: {},
|
|
183
|
-
config: {},
|
|
184
|
+
config: { headers: {} },
|
|
184
185
|
};
|
|
185
186
|
error.config = {
|
|
186
187
|
url: 'http://amazinghost.com/beautiful-path',
|
|
187
188
|
method: 'get',
|
|
189
|
+
headers: {},
|
|
188
190
|
};
|
|
189
191
|
error.code = 'ECONNREINVENTED';
|
|
190
192
|
logger.fromError('hi', error, { details: 'here' });
|
|
@@ -196,10 +198,10 @@ describe('Logger', () => {
|
|
|
196
198
|
(0, chai_1.expect)(logArguments.error.type).to.eql(error.name);
|
|
197
199
|
(0, chai_1.expect)(logArguments.error.stack_trace).to.eql(error.stack);
|
|
198
200
|
(0, chai_1.expect)(logArguments.error.message).to.eql(error.message);
|
|
199
|
-
(0, chai_1.expect)(logArguments.http.request.method).to.eql(error.config
|
|
200
|
-
(0, chai_1.expect)(logArguments.url.full).to.eql(error.config
|
|
201
|
-
(0, chai_1.expect)(logArguments.http.response.status_code).to.eql(error.response
|
|
202
|
-
(0, chai_1.expect)(logArguments.http.response.body.content).to.eql(JSON.stringify(error.response
|
|
201
|
+
(0, chai_1.expect)(logArguments.http.request.method).to.eql(error.config?.method);
|
|
202
|
+
(0, chai_1.expect)(logArguments.url.full).to.eql(error.config?.url);
|
|
203
|
+
(0, chai_1.expect)(logArguments.http.response.status_code).to.eql(error.response?.status);
|
|
204
|
+
(0, chai_1.expect)(logArguments.http.response.body.content).to.eql(JSON.stringify(error.response?.data));
|
|
203
205
|
});
|
|
204
206
|
describe('#customError', () => {
|
|
205
207
|
it('should log error as the given severity with action', () => {
|
package/dist/timer/timer.js
CHANGED
package/package.json
CHANGED
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"test": "mocha --require ts-node/register --extension ts ./src --recursive",
|
|
11
11
|
"test:watch": "mocha --require ts-node/register --extension ts ./src --recursive --watch",
|
|
12
|
-
"lint": "eslint
|
|
13
|
-
"lint:fix": "eslint
|
|
12
|
+
"lint": "eslint .",
|
|
13
|
+
"lint:fix": "eslint . --fix",
|
|
14
14
|
"build": "rm -rf dist && tsc --project ./tsconfig.json",
|
|
15
15
|
"release": "CI=true semantic-release",
|
|
16
16
|
"example-js": "DEBUG=* node examples/index-js.js",
|
|
@@ -36,35 +36,35 @@
|
|
|
36
36
|
"json"
|
|
37
37
|
],
|
|
38
38
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
39
|
+
"node": ">=20"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"lodash": "^4.17.21"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@types/chai": "4.3.
|
|
46
|
-
"@types/lodash": "4.
|
|
47
|
-
"@types/mocha": "10.0.
|
|
48
|
-
"@types/node": "
|
|
49
|
-
"@types/sinon": "
|
|
50
|
-
"@types/sinon-chai": "3.2.
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "
|
|
52
|
-
"@typescript-eslint/parser": "
|
|
53
|
-
"axios": "
|
|
54
|
-
"chai": "4.
|
|
55
|
-
"eslint": "8.
|
|
45
|
+
"@types/chai": "4.3.20",
|
|
46
|
+
"@types/lodash": "4.17.20",
|
|
47
|
+
"@types/mocha": "10.0.10",
|
|
48
|
+
"@types/node": "20.19.22",
|
|
49
|
+
"@types/sinon": "17.0.4",
|
|
50
|
+
"@types/sinon-chai": "3.2.12",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "6.21.0",
|
|
52
|
+
"@typescript-eslint/parser": "6.21.0",
|
|
53
|
+
"axios": "1.11.0",
|
|
54
|
+
"chai": "4.5.0",
|
|
55
|
+
"eslint": "8.57.1",
|
|
56
56
|
"eslint-config-emarsys": "5.1.0",
|
|
57
|
-
"eslint-config-prettier": "
|
|
58
|
-
"eslint-plugin-no-only-tests": "3.
|
|
59
|
-
"eslint-plugin-prettier": "
|
|
60
|
-
"eslint-plugin-security": "1.
|
|
61
|
-
"mocha": "10.
|
|
62
|
-
"prettier": "
|
|
57
|
+
"eslint-config-prettier": "10.1.8",
|
|
58
|
+
"eslint-plugin-no-only-tests": "3.3.0",
|
|
59
|
+
"eslint-plugin-prettier": "5.5.4",
|
|
60
|
+
"eslint-plugin-security": "2.1.1",
|
|
61
|
+
"mocha": "10.8.2",
|
|
62
|
+
"prettier": "3.6.2",
|
|
63
63
|
"semantic-release": "19.0.5",
|
|
64
|
-
"sinon": "
|
|
64
|
+
"sinon": "21.0.0",
|
|
65
65
|
"sinon-chai": "3.7.0",
|
|
66
|
-
"ts-node": "10.9.
|
|
67
|
-
"typescript": "
|
|
66
|
+
"ts-node": "10.9.2",
|
|
67
|
+
"typescript": "5.9.3"
|
|
68
68
|
},
|
|
69
|
-
"version": "
|
|
69
|
+
"version": "9.0.0"
|
|
70
70
|
}
|