@interopio/log4js-otel 0.0.3

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.
@@ -0,0 +1,2 @@
1
+ import { LoggingEvent } from "./types";
2
+ export declare function configure(config: any, layouts: any): (loggingEvent: LoggingEvent) => void;
package/dist/index.js ADDED
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ // https://log4js-node.github.io/log4js-node/writing-appenders.html
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.configure = configure;
5
+ const otel_1 = require("@interopio/otel");
6
+ function configure(config, layouts) {
7
+ let layout = layouts.colouredLayout;
8
+ if (config.layout) {
9
+ layout = layouts.layout(config.layout.type, config.layout);
10
+ }
11
+ return (loggingEvent) => {
12
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
13
+ if (config.breakInDebugger) {
14
+ debugger;
15
+ }
16
+ const attributes = Object.assign(Object.assign({ level: (_a = loggingEvent.level) === null || _a === void 0 ? void 0 : _a.levelStr, startTime: loggingEvent.startTime.getTime(), categoryName: loggingEvent.categoryName, callStack: loggingEvent.callStack, columnNumber: loggingEvent.columnNumber, error: (_b = loggingEvent.error) === null || _b === void 0 ? void 0 : _b.message, errorStack: (_c = loggingEvent.error) === null || _c === void 0 ? void 0 : _c.stack, errorName: (_d = loggingEvent.error) === null || _d === void 0 ? void 0 : _d.name, lineNumber: loggingEvent.lineNumber, pid: loggingEvent.pid, fileName: loggingEvent.fileName, functionName: loggingEvent.functionName, clusterWorkerId: (_e = loggingEvent.cluster) === null || _e === void 0 ? void 0 : _e.workerId, clusterWorker: (_f = loggingEvent.cluster) === null || _f === void 0 ? void 0 : _f.worker }, (_g = otel_1.Container.instance) === null || _g === void 0 ? void 0 : _g.settings.additionalAttributes), (_h = otel_1.Logs.instance) === null || _h === void 0 ? void 0 : _h.settings.additionalAttributes);
17
+ otel_1.Logs.emit({
18
+ body: layout(loggingEvent, config.timezoneOffset),
19
+ severityText: mapLogJsLevelString(loggingEvent.level.levelStr),
20
+ severityNumber: mapLogJsLevelNumber(loggingEvent.level.level),
21
+ observedTimestamp: loggingEvent.startTime,
22
+ timestamp: loggingEvent.startTime,
23
+ context: (_j = otel_1.Traces.currentTracingState) === null || _j === void 0 ? void 0 : _j.context,
24
+ attributes
25
+ });
26
+ };
27
+ }
28
+ function mapLogJsLevelString(levelStr) {
29
+ // https://opentelemetry.io/docs/specs/otel/logs/data-model/#severity-fields
30
+ if (!levelStr) {
31
+ return "ERROR";
32
+ }
33
+ levelStr = levelStr.toUpperCase();
34
+ if (levelStr === "ALL" ||
35
+ levelStr === "TRACE") {
36
+ return "TRACE";
37
+ }
38
+ if (levelStr === "DEBUG") {
39
+ return "DEBUG";
40
+ }
41
+ if (levelStr === "INFO") {
42
+ return "INFO";
43
+ }
44
+ if (levelStr === "WARN") {
45
+ return "WARN";
46
+ }
47
+ if (levelStr === "ERROR") {
48
+ return "ERROR";
49
+ }
50
+ if (levelStr === "FATAL") {
51
+ return "FATAL";
52
+ }
53
+ if (levelStr === "MARK" ||
54
+ levelStr === "OFF") {
55
+ return "ERROR";
56
+ }
57
+ return "ERROR";
58
+ }
59
+ function mapLogJsLevelNumber(level) {
60
+ /*
61
+ https://github.com/log4js-node/log4js-node/blob/master/lib/levels.js
62
+ ALL: { value: Number.MIN_VALUE, colour: 'grey' },
63
+ TRACE: { value: 5000, colour: 'blue' },
64
+ DEBUG: { value: 10000, colour: 'cyan' },
65
+ INFO: { value: 20000, colour: 'green' },
66
+ WARN: { value: 30000, colour: 'yellow' },
67
+ ERROR: { value: 40000, colour: 'red' },
68
+ FATAL: { value: 50000, colour: 'magenta' },
69
+ MARK: { value: 9007199254740992, colour: 'grey' }, // 2^53
70
+ OFF: { value: Number.MAX_VALUE, colour: 'grey' },
71
+ */
72
+ /*
73
+ https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitynumber
74
+ 1-4 TRACE A fine-grained debugging event. Typically disabled in default configurations.
75
+ 5-8 DEBUG A debugging event.
76
+ 9-12 INFO An informational event. Indicates that an event happened.
77
+ 13-16 WARN A warning event. Not an error but is likely more important than an informational event.
78
+ 17-20 ERROR An error event. Something went wrong.
79
+ 21-24 FATAL A fatal error such as application or system crash.
80
+ */
81
+ if (level < 10000) {
82
+ // 0-10000 to 1-4
83
+ return 1 + Math.floor(level * 4 / 10000);
84
+ }
85
+ if (level < 20000) {
86
+ // 10000-20000 to 5-8
87
+ return 5 + Math.floor((level - 10000) * 4 / 10000);
88
+ }
89
+ if (level < 30000) {
90
+ // 20000-30000 to 9-12
91
+ return 9 + Math.floor((level - 20000) * 4 / 10000);
92
+ }
93
+ if (level < 40000) {
94
+ // 30000-40000 to 13-16
95
+ return 13 + Math.floor((level - 30000) * 4 / 10000);
96
+ }
97
+ if (level < 50000) {
98
+ // 40000-50000 to 13-16
99
+ return 17 + Math.floor((level - 40000) * 4 / 10000);
100
+ }
101
+ // 50000+ to 21-24
102
+ return 21 + Math.min(Math.floor((level - 50000) * 4 / 10000), 24);
103
+ }
104
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,mEAAmE;;AAKnE,8BAuCC;AA1CD,0CAAgF;AAGhF,SAAgB,SAAS,CAAC,MAAW,EAAE,OAAY;IACjD,IAAI,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IACpC,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAClB,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;IACD,OAAO,CAAC,YAA0B,EAAE,EAAE;;QACpC,IAAI,MAAM,CAAC,eAAe,EAAE,CAAC;YAC3B,QAAQ,CAAC;QACX,CAAC;QACD,MAAM,UAAU,iCACd,KAAK,EAAE,MAAA,YAAY,CAAC,KAAK,0CAAE,QAAQ,EACnC,SAAS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C,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACrD,CAAC;IACD,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;QAClB,uBAAuB;QACvB,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;QAClB,uBAAuB;QACvB,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,kBAAkB;IAClB,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,52 @@
1
+ export interface Level {
2
+ isEqualTo(other: string): boolean;
3
+ isEqualTo(otherLevel: Level): boolean;
4
+ isLessThanOrEqualTo(other: string): boolean;
5
+ isLessThanOrEqualTo(otherLevel: Level): boolean;
6
+ isGreaterThanOrEqualTo(other: string): boolean;
7
+ isGreaterThanOrEqualTo(otherLevel: Level): boolean;
8
+ colour: string;
9
+ level: number;
10
+ levelStr: string;
11
+ }
12
+ export interface Levels {
13
+ ALL: Level;
14
+ MARK: Level;
15
+ TRACE: Level;
16
+ DEBUG: Level;
17
+ INFO: Level;
18
+ WARN: Level;
19
+ ERROR: Level;
20
+ FATAL: Level;
21
+ OFF: Level;
22
+ levels: Level[];
23
+ getLevel(level: Level | string, defaultLevel?: Level): Level;
24
+ addLevels(customLevels: object): void;
25
+ }
26
+ export interface CallStack {
27
+ functionName: string;
28
+ fileName: string;
29
+ lineNumber: number;
30
+ columnNumber: number;
31
+ /**
32
+ * The stack string after the skipped lines
33
+ */
34
+ callStack: string;
35
+ }
36
+ export interface LoggingEvent extends Partial<CallStack> {
37
+ categoryName: string;
38
+ level: Level;
39
+ data: any[];
40
+ startTime: Date;
41
+ pid: number;
42
+ context: any;
43
+ cluster?: {
44
+ workerId: number;
45
+ worker: number;
46
+ };
47
+ /**
48
+ * The first Error object in the data if there is one
49
+ */
50
+ error?: Error;
51
+ serialise(): string;
52
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "@interopio/log4js-otel",
3
+ "version": "0.0.3",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "author": "interop.io",
7
+ "scripts": {
8
+ "build": "rimraf dist && tsc -p ./tsconfig.json"
9
+ },
10
+ "keywords": [],
11
+ "license": "MIT",
12
+ "description": "log4js binding for @interopio/otel logging",
13
+ "devDependencies": {
14
+ "rimraf": "^6.0.1",
15
+ "typescript": "^5.8.3"
16
+ },
17
+ "peerDependencies": {
18
+ "@interopio/otel": "<2.0.0",
19
+ "log4js": "*"
20
+ },
21
+ "publishConfig": {
22
+ "registry": "https://registry.npmjs.org",
23
+ "access": "public"
24
+ }
25
+ }
package/src/index.ts ADDED
@@ -0,0 +1,181 @@
1
+ // https://log4js-node.github.io/log4js-node/writing-appenders.html
2
+
3
+ import { Container, Logs, Traces } from "@interopio/otel";
4
+ import { LoggingEvent } from "./types";
5
+ import { Layout, LayoutsParam, PatternToken } from "log4js";
6
+
7
+ interface Log4JSToOTELAppenderConfig
8
+ {
9
+ layout?: Layout;
10
+ maxRecordsBeforeOTELActive?: number;
11
+ maxTimeBeforeOTELActiveMs?: number;
12
+ breakInDebugger?: boolean;
13
+ logErrorsInConsole?: boolean;
14
+ rawLayout?: boolean;
15
+ }
16
+
17
+ export function configure(config: Log4JSToOTELAppenderConfig, layouts: LayoutsParam) {
18
+ let layout = layouts.messagePassThroughLayout;
19
+ if (config.layout) {
20
+ layout = layouts.layout(config.layout.type, config.layout as unknown as PatternToken);
21
+ }
22
+ if (config.breakInDebugger) {
23
+ debugger;
24
+ }
25
+ const maxRecordsBeforeOTELActive = config.maxRecordsBeforeOTELActive || 10000;
26
+ const maxTimeBeforeOTELActiveMs = config.maxTimeBeforeOTELActiveMs || -1;
27
+ const recordsBeforeOTELActive: Parameters<typeof Logs.emit>[0][] = [];
28
+ const startTime = new Date().getTime();
29
+
30
+ return (loggingEvent: LoggingEvent) => {
31
+ try {
32
+ const attributes = {
33
+ level: loggingEvent.level?.levelStr,
34
+ startTime: loggingEvent.startTime.getTime(),
35
+ categoryName: loggingEvent.categoryName,
36
+ callStack: loggingEvent.callStack,
37
+ columnNumber: loggingEvent.columnNumber,
38
+ error: loggingEvent.error?.message,
39
+ errorStack: loggingEvent.error?.stack,
40
+ errorName: loggingEvent.error?.name,
41
+ lineNumber: loggingEvent.lineNumber,
42
+ pid: loggingEvent.pid,
43
+ fileName: loggingEvent.fileName,
44
+ functionName: loggingEvent.functionName,
45
+ clusterWorkerId: loggingEvent.cluster?.workerId,
46
+ clusterWorker: loggingEvent.cluster?.worker,
47
+ ...Container.instance?.settings.additionalAttributes,
48
+ ...Logs.instance?.settings.additionalAttributes,
49
+ // data: loggingEvent.data?.length ? flattenOtelAtributes({ data: loggingEvent.data }, Logs.instance.settings.maxAttributeDepth ?? 5) : undefined
50
+ };
51
+ const record = {
52
+ body: layout(loggingEvent),
53
+ severityText: mapLogJsLevelString(loggingEvent.level.levelStr),
54
+ severityNumber: mapLogJsLevelNumber(loggingEvent.level.level),
55
+ observedTimestamp: loggingEvent.startTime,
56
+ timestamp: loggingEvent.startTime,
57
+ context: Traces.currentTracingState?.context,
58
+ attributes
59
+ };
60
+ if (!Logs.instance?.started) {
61
+ if (maxRecordsBeforeOTELActive !== -1 &&
62
+ recordsBeforeOTELActive.length >= maxRecordsBeforeOTELActive) {
63
+ recordsBeforeOTELActive.length = 0;
64
+ return;
65
+ }
66
+ if (maxTimeBeforeOTELActiveMs !== -1 &&
67
+ (new Date().getTime() - startTime) > maxTimeBeforeOTELActiveMs) {
68
+ recordsBeforeOTELActive.length = 0;
69
+ return;
70
+ }
71
+ recordsBeforeOTELActive.push(record);
72
+ return;
73
+ }
74
+
75
+ for (const recordBeforeOTELActive of recordsBeforeOTELActive) {
76
+ try {
77
+ Logs.emit(recordBeforeOTELActive);
78
+ } catch (err) {
79
+ if (config.logErrorsInConsole ?? true) {
80
+ console.error(err);
81
+ }
82
+ }
83
+ }
84
+ recordsBeforeOTELActive.length = 0;
85
+ try {
86
+ Logs.emit(record);
87
+ } catch (err) {
88
+ if (config.logErrorsInConsole ?? true) {
89
+ console.error(err);
90
+ }
91
+ }
92
+ }
93
+ catch (err) {
94
+ if (config.logErrorsInConsole ?? true) {
95
+ console.error(err);
96
+ }
97
+ }
98
+ };
99
+ }
100
+
101
+ function mapLogJsLevelString(levelStr: string): string | undefined {
102
+ // https://opentelemetry.io/docs/specs/otel/logs/data-model/#severity-fields
103
+
104
+ if (!levelStr) {
105
+ return "ERROR";
106
+ }
107
+ levelStr = levelStr.toUpperCase();
108
+ if (levelStr === "ALL" ||
109
+ levelStr === "TRACE") {
110
+ return "TRACE";
111
+ }
112
+ if (levelStr === "DEBUG") {
113
+ return "DEBUG";
114
+ }
115
+ if (levelStr === "INFO") {
116
+ return "INFO";
117
+ }
118
+ if (levelStr === "WARN") {
119
+ return "WARN";
120
+ }
121
+ if (levelStr === "ERROR") {
122
+ return "ERROR";
123
+ }
124
+ if (levelStr === "FATAL") {
125
+ return "FATAL";
126
+ }
127
+ if (levelStr === "MARK" ||
128
+ levelStr === "OFF") {
129
+ return "ERROR";
130
+ }
131
+ return "ERROR";
132
+ }
133
+
134
+ function mapLogJsLevelNumber(level: number) {
135
+ /*
136
+ https://github.com/log4js-node/log4js-node/blob/master/lib/levels.js
137
+ ALL: { value: Number.MIN_VALUE, colour: 'grey' },
138
+ TRACE: { value: 5000, colour: 'blue' },
139
+ DEBUG: { value: 10000, colour: 'cyan' },
140
+ INFO: { value: 20000, colour: 'green' },
141
+ WARN: { value: 30000, colour: 'yellow' },
142
+ ERROR: { value: 40000, colour: 'red' },
143
+ FATAL: { value: 50000, colour: 'magenta' },
144
+ MARK: { value: 9007199254740992, colour: 'grey' }, // 2^53
145
+ OFF: { value: Number.MAX_VALUE, colour: 'grey' },
146
+ */
147
+ /*
148
+ https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitynumber
149
+ 1-4 TRACE A fine-grained debugging event. Typically disabled in default configurations.
150
+ 5-8 DEBUG A debugging event.
151
+ 9-12 INFO An informational event. Indicates that an event happened.
152
+ 13-16 WARN A warning event. Not an error but is likely more important than an informational event.
153
+ 17-20 ERROR An error event. Something went wrong.
154
+ 21-24 FATAL A fatal error such as application or system crash.
155
+ */
156
+
157
+ if (level < 10000) {
158
+ // 0-10000 to 1-4
159
+ return 1 + Math.floor(level * 4 / 10000);
160
+ }
161
+ if (level < 20000) {
162
+ // 10000-20000 to 5-8
163
+ return 5 + Math.floor((level - 10000) * 4 / 10000);
164
+ }
165
+ if (level < 30000) {
166
+ // 20000-30000 to 9-12
167
+ return 9 + Math.floor((level - 20000) * 4 / 10000);
168
+ }
169
+ if (level < 40000) {
170
+ // 30000-40000 to 13-16
171
+ return 13 + Math.floor((level - 30000) * 4 / 10000);
172
+ }
173
+ if (level < 50000) {
174
+ // 40000-50000 to 13-16
175
+ return 17 + Math.floor((level - 40000) * 4 / 10000);
176
+ }
177
+
178
+ // 50000+ to 21-24
179
+ return 21 + Math.min(Math.floor((level - 50000) * 4 / 10000), 24);
180
+ }
181
+
package/src/types.ts ADDED
@@ -0,0 +1,56 @@
1
+ // https://github.com/log4js-node/log4js-node/blob/master/types/log4js.d.ts
2
+ export interface Level {
3
+ isEqualTo(other: string): boolean;
4
+ isEqualTo(otherLevel: Level): boolean;
5
+ isLessThanOrEqualTo(other: string): boolean;
6
+ isLessThanOrEqualTo(otherLevel: Level): boolean;
7
+ isGreaterThanOrEqualTo(other: string): boolean;
8
+ isGreaterThanOrEqualTo(otherLevel: Level): boolean;
9
+ colour: string;
10
+ level: number;
11
+ levelStr: string;
12
+ }
13
+
14
+ export interface Levels {
15
+ ALL: Level;
16
+ MARK: Level;
17
+ TRACE: Level;
18
+ DEBUG: Level;
19
+ INFO: Level;
20
+ WARN: Level;
21
+ ERROR: Level;
22
+ FATAL: Level;
23
+ OFF: Level;
24
+ levels: Level[];
25
+ getLevel(level: Level | string, defaultLevel?: Level): Level;
26
+ addLevels(customLevels: object): void;
27
+ }
28
+
29
+ export interface CallStack {
30
+ functionName: string;
31
+ fileName: string;
32
+ lineNumber: number;
33
+ columnNumber: number;
34
+ /**
35
+ * The stack string after the skipped lines
36
+ */
37
+ callStack: string;
38
+ }
39
+
40
+ export interface LoggingEvent extends Partial<CallStack> {
41
+ categoryName: string; // name of category
42
+ level: Level; // level of message
43
+ data: any[]; // objects to log
44
+ startTime: Date;
45
+ pid: number;
46
+ context: any;
47
+ cluster?: {
48
+ workerId: number;
49
+ worker: number;
50
+ };
51
+ /**
52
+ * The first Error object in the data if there is one
53
+ */
54
+ error?: Error;
55
+ serialise(): string;
56
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "outDir": "dist",
4
+ "target": "ES6",
5
+ "module": "commonjs",
6
+ "declaration": true,
7
+ "moduleResolution": "node",
8
+ "esModuleInterop": true,
9
+ "experimentalDecorators": true,
10
+ "emitDecoratorMetadata": true,
11
+ "resolveJsonModule": true,
12
+ "strict": true,
13
+ "sourceMap": true,
14
+ "allowSyntheticDefaultImports": true
15
+ },
16
+ "include": [
17
+ "./src/**/*"
18
+ ],
19
+ "exclude": [
20
+ "node_modules"
21
+ ]
22
+ }