@orion-js/logger 3.2.0 → 3.2.36
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/formats.js +2 -1
- package/lib/helpers/getFileName.d.ts +0 -1
- package/lib/helpers/getFileName.js +2 -8
- package/lib/index.test.js +9 -0
- package/lib/logger.js +13 -13
- package/package.json +4 -2
package/lib/formats.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.jsonConsoleTransport = exports.jsonConsoleFormat = exports.textConsoleTransport = exports.textConsoleFormat = exports.sentryFormat = void 0;
|
|
7
7
|
const winston_1 = require("winston");
|
|
8
8
|
const util_1 = __importDefault(require("util"));
|
|
9
|
+
const lodash_1 = require("lodash");
|
|
9
10
|
const { metadata, timestamp, json, colorize, combine, printf } = winston_1.format;
|
|
10
11
|
const metaError = (0, winston_1.format)(info => {
|
|
11
12
|
if (info.metadata && info.metadata.error && info.metadata.error instanceof Error) {
|
|
@@ -25,7 +26,7 @@ exports.sentryFormat = (0, winston_1.format)(info => {
|
|
|
25
26
|
};
|
|
26
27
|
});
|
|
27
28
|
exports.textConsoleFormat = combine(colorize(), metadata({ fillExcept: ['fileName', 'level', 'message', 'stack'] }), metaError(), timestamp(), printf(info => {
|
|
28
|
-
return `[${info.level}] [${info.timestamp}] ${info.fileName ? `[${info.fileName}]` : ''} ${info.message} ${info.stack ? `\n${info.stack}` : ''} ${util_1.default.inspect(info.metadata)}`;
|
|
29
|
+
return `[${info.level}] [${info.timestamp}] ${info.fileName ? `[${info.fileName}]` : ''} ${info.message} ${info.stack ? `\n${info.stack}` : ''} ${(0, lodash_1.isEmpty)(info.metadata?.value) ? '' : util_1.default.inspect(info.metadata?.value)} ${(0, lodash_1.isEmpty)(info.metadata?.parent) ? '' : util_1.default.inspect(info.metadata?.parent)}`;
|
|
29
30
|
}));
|
|
30
31
|
exports.textConsoleTransport = new winston_1.transports.Console({
|
|
31
32
|
handleExceptions: true,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.improveFileName = exports.getFileName = void 0;
|
|
4
4
|
const getFileName = () => {
|
|
5
5
|
try {
|
|
6
6
|
const stack = new Error().stack;
|
|
7
7
|
const lines = stack.split('\n');
|
|
8
|
-
const filePath = lines[
|
|
8
|
+
const filePath = lines[3].split('(')[1].split(')')[0];
|
|
9
9
|
return (0, exports.improveFileName)(filePath);
|
|
10
10
|
}
|
|
11
11
|
catch (error) {
|
|
@@ -33,9 +33,3 @@ const improveFileName = (path) => {
|
|
|
33
33
|
return path;
|
|
34
34
|
};
|
|
35
35
|
exports.improveFileName = improveFileName;
|
|
36
|
-
const setFileName = (metadata) => {
|
|
37
|
-
if (metadata.fileName)
|
|
38
|
-
return;
|
|
39
|
-
metadata.fileName = (0, exports.getFileName)();
|
|
40
|
-
};
|
|
41
|
-
exports.setFileName = setFileName;
|
package/lib/index.test.js
CHANGED
|
@@ -7,5 +7,14 @@ describe('Log', () => {
|
|
|
7
7
|
logger_1.logger.debug('debug');
|
|
8
8
|
logger_1.logger.info('info');
|
|
9
9
|
logger_1.logger.warn('warn');
|
|
10
|
+
logger_1.logger.warn('warn', { info: 'of the log' });
|
|
11
|
+
});
|
|
12
|
+
it('shouldnt fail when passing a non object to the metadata', () => {
|
|
13
|
+
logger_1.logger.info('info', 'a string');
|
|
14
|
+
logger_1.logger.info('info', ['array']);
|
|
15
|
+
});
|
|
16
|
+
it('should pass the context', () => {
|
|
17
|
+
const withMeta = logger_1.logger.addMetadata({ context: 'context' });
|
|
18
|
+
withMeta.info('info', { notContext: 'notContext' });
|
|
10
19
|
});
|
|
11
20
|
});
|
package/lib/logger.js
CHANGED
|
@@ -31,21 +31,21 @@ const getLogger = (context) => {
|
|
|
31
31
|
exports.getLogger = getLogger;
|
|
32
32
|
const createLogger = (logger) => {
|
|
33
33
|
return {
|
|
34
|
-
debug: (message,
|
|
35
|
-
(0, getFileName_1.
|
|
36
|
-
return logger.debug(message,
|
|
34
|
+
debug: (message, value = {}) => {
|
|
35
|
+
const fileName = (0, getFileName_1.getFileName)();
|
|
36
|
+
return logger.debug(message, { value, fileName });
|
|
37
37
|
},
|
|
38
|
-
info: (message,
|
|
39
|
-
(0, getFileName_1.
|
|
40
|
-
return logger.info(message,
|
|
38
|
+
info: (message, value = {}) => {
|
|
39
|
+
const fileName = (0, getFileName_1.getFileName)();
|
|
40
|
+
return logger.info(message, { value, fileName });
|
|
41
41
|
},
|
|
42
|
-
warn: (message,
|
|
43
|
-
(0, getFileName_1.
|
|
44
|
-
return logger.warn(message,
|
|
42
|
+
warn: (message, value = {}) => {
|
|
43
|
+
const fileName = (0, getFileName_1.getFileName)();
|
|
44
|
+
return logger.warn(message, { value, fileName });
|
|
45
45
|
},
|
|
46
|
-
error: (message,
|
|
47
|
-
(0, getFileName_1.
|
|
48
|
-
return logger.error(message,
|
|
46
|
+
error: (message, value = {}) => {
|
|
47
|
+
const fileName = (0, getFileName_1.getFileName)();
|
|
48
|
+
return logger.error(message, { value, fileName });
|
|
49
49
|
},
|
|
50
50
|
addContext: (module) => {
|
|
51
51
|
if (module.id) {
|
|
@@ -56,7 +56,7 @@ const createLogger = (logger) => {
|
|
|
56
56
|
return createLogger(logger.child({}));
|
|
57
57
|
},
|
|
58
58
|
addMetadata: (metadata) => {
|
|
59
|
-
return createLogger(logger.child(metadata));
|
|
59
|
+
return createLogger(logger.child({ parent: metadata }));
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
62
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/logger",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.36",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
"upgrade-interactive": "yarn upgrade-interactive"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"lodash": "^4.17.21",
|
|
16
17
|
"object-hash": "^2.2.0",
|
|
17
18
|
"winston": "^3.6.0"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"@types/jest": "^27.0.2",
|
|
22
|
+
"@types/lodash": "^4.14.182",
|
|
21
23
|
"jest": "27.3.1",
|
|
22
24
|
"ts-jest": "27.0.7",
|
|
23
25
|
"typescript": "^4.4.4"
|
|
@@ -25,5 +27,5 @@
|
|
|
25
27
|
"publishConfig": {
|
|
26
28
|
"access": "public"
|
|
27
29
|
},
|
|
28
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "892890d7fed7597fa41d18c113c4d18aa58546bc"
|
|
29
31
|
}
|