@orion-js/logger 3.11.1 → 3.11.6-alpha.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/lib/formats.js +31 -10
- package/package.json +3 -2
package/lib/formats.js
CHANGED
|
@@ -5,9 +5,26 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
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
|
-
const
|
|
8
|
+
const node_util_1 = __importDefault(require("node:util"));
|
|
9
9
|
const lodash_1 = require("lodash");
|
|
10
|
+
const api_1 = __importDefault(require("@opentelemetry/api"));
|
|
10
11
|
const { metadata, timestamp, json, colorize, combine, printf } = winston_1.format;
|
|
12
|
+
const opentelemetryContext = (0, winston_1.format)(info => {
|
|
13
|
+
const activeSpan = api_1.default.trace.getActiveSpan();
|
|
14
|
+
if (activeSpan) {
|
|
15
|
+
const spanContex = activeSpan.spanContext();
|
|
16
|
+
if (activeSpan.name && !info.context) {
|
|
17
|
+
info.context = activeSpan.name;
|
|
18
|
+
}
|
|
19
|
+
const fields = {
|
|
20
|
+
trace_id: spanContex.traceId,
|
|
21
|
+
span_id: spanContex.spanId,
|
|
22
|
+
trace_flags: `0${spanContex.traceFlags.toString(16)}`,
|
|
23
|
+
};
|
|
24
|
+
Object.assign(info, fields);
|
|
25
|
+
}
|
|
26
|
+
return info;
|
|
27
|
+
});
|
|
11
28
|
const metaError = (0, winston_1.format)(info => {
|
|
12
29
|
if (info?.metadata?.value?.error instanceof Error) {
|
|
13
30
|
info.stack = info?.metadata?.value?.error.stack;
|
|
@@ -27,8 +44,8 @@ exports.sentryFormat = (0, winston_1.format)(info => {
|
|
|
27
44
|
...extra,
|
|
28
45
|
tags: {
|
|
29
46
|
path: path || '',
|
|
30
|
-
request_id: label
|
|
31
|
-
}
|
|
47
|
+
request_id: label,
|
|
48
|
+
},
|
|
32
49
|
};
|
|
33
50
|
});
|
|
34
51
|
function getMetadataText(metadata) {
|
|
@@ -36,25 +53,29 @@ function getMetadataText(metadata) {
|
|
|
36
53
|
if ((0, lodash_1.isEmpty)(rest)) {
|
|
37
54
|
if (typeof value === 'undefined')
|
|
38
55
|
return '';
|
|
39
|
-
return
|
|
56
|
+
return node_util_1.default.inspect(value);
|
|
40
57
|
}
|
|
41
|
-
return `${
|
|
58
|
+
return `${node_util_1.default.inspect(value)} ${node_util_1.default.inspect(rest)}`;
|
|
42
59
|
}
|
|
43
|
-
exports.textConsoleFormat = combine(colorize(), metadata({ fillExcept: ['fileName', 'level', 'message', 'stack'] }), metaError(), timestamp(), printf(info => {
|
|
60
|
+
exports.textConsoleFormat = combine(colorize(), metadata({ fillExcept: ['fileName', 'level', 'message', 'stack'] }), opentelemetryContext(), metaError(), timestamp(), printf(info => {
|
|
44
61
|
// console.log(info)
|
|
45
62
|
const date = new Date(info.timestamp);
|
|
46
63
|
const timeLabel = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
|
|
47
64
|
const fileNameLabel = info.fileName ? `[${info.fileName}]` : '';
|
|
48
65
|
const stack = info.stack ? `\n${info.stack}` : '';
|
|
49
66
|
const value = getMetadataText(info.metadata);
|
|
50
|
-
|
|
67
|
+
const traceId = info.trace_id
|
|
68
|
+
? `${String(info.trace_id).substring(0, 8)}@${String(info.span_id).substring(0, 8)}`
|
|
69
|
+
: '';
|
|
70
|
+
const context = `${info.context || ''} ${traceId}`.trim();
|
|
71
|
+
return `[${info.level}] [${timeLabel}] [${context}] ${fileNameLabel} ${info.message} ${value} ${stack}`;
|
|
51
72
|
}));
|
|
52
73
|
exports.textConsoleTransport = new winston_1.transports.Console({
|
|
53
74
|
handleExceptions: true,
|
|
54
|
-
format: exports.textConsoleFormat
|
|
75
|
+
format: exports.textConsoleFormat,
|
|
55
76
|
});
|
|
56
|
-
exports.jsonConsoleFormat = combine(metadata({ fillExcept: ['fileName', 'level', 'message'] }), metaError(), timestamp(), json());
|
|
77
|
+
exports.jsonConsoleFormat = combine(metadata({ fillExcept: ['fileName', 'level', 'message'] }), opentelemetryContext(), metaError(), timestamp(), json());
|
|
57
78
|
exports.jsonConsoleTransport = new winston_1.transports.Console({
|
|
58
79
|
handleExceptions: true,
|
|
59
|
-
format: exports.jsonConsoleFormat
|
|
80
|
+
format: exports.jsonConsoleFormat,
|
|
60
81
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/logger",
|
|
3
|
-
"version": "3.11.
|
|
3
|
+
"version": "3.11.6-alpha.0",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"author": "nicolaslopezj",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"upgrade-interactive": "yarn upgrade-interactive"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
+
"@opentelemetry/api": "^1.9.0",
|
|
16
17
|
"color": "^4.2.3",
|
|
17
18
|
"lodash": "^4.17.21",
|
|
18
19
|
"object-hash": "^2.2.0",
|
|
@@ -29,5 +30,5 @@
|
|
|
29
30
|
"publishConfig": {
|
|
30
31
|
"access": "public"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "cdcf47aed25cb864126e624cd808c08d7959b8a4"
|
|
33
34
|
}
|