@townco/core 0.0.25 → 0.0.27
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/logger.js +27 -0
- package/package.json +6 -2
package/dist/logger.js
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import * as fs from "node:fs";
|
|
8
8
|
import * as path from "node:path";
|
|
9
|
+
import { context, trace } from "@opentelemetry/api";
|
|
10
|
+
import { logs, SeverityNumber } from "@opentelemetry/api-logs";
|
|
9
11
|
// Check if running in Node.js
|
|
10
12
|
const isNode = typeof process !== "undefined" && process.versions?.node;
|
|
11
13
|
// Global logs directory configuration (set once at app startup for TUI)
|
|
@@ -50,6 +52,15 @@ const LOG_LEVELS = {
|
|
|
50
52
|
error: 4,
|
|
51
53
|
fatal: 5,
|
|
52
54
|
};
|
|
55
|
+
// Map log levels to OTEL severity numbers
|
|
56
|
+
const OTEL_SEVERITY = {
|
|
57
|
+
trace: SeverityNumber.TRACE,
|
|
58
|
+
debug: SeverityNumber.DEBUG,
|
|
59
|
+
info: SeverityNumber.INFO,
|
|
60
|
+
warn: SeverityNumber.WARN,
|
|
61
|
+
error: SeverityNumber.ERROR,
|
|
62
|
+
fatal: SeverityNumber.FATAL,
|
|
63
|
+
};
|
|
53
64
|
const _LOG_COLORS = {
|
|
54
65
|
trace: "#6B7280", // gray
|
|
55
66
|
debug: "#3B82F6", // blue
|
|
@@ -177,6 +188,22 @@ export class Logger {
|
|
|
177
188
|
}
|
|
178
189
|
// Note: Logs are captured and displayed in UI for TUI mode
|
|
179
190
|
// Console output only enabled when TOWN_LOG_CONSOLE=true
|
|
191
|
+
// Emit to OTEL (no-op if no provider registered)
|
|
192
|
+
const otelLogger = logs.getLogger(this.service);
|
|
193
|
+
const activeSpan = trace.getSpan(context.active());
|
|
194
|
+
otelLogger.emit({
|
|
195
|
+
severityNumber: OTEL_SEVERITY[level],
|
|
196
|
+
severityText: level.toUpperCase(),
|
|
197
|
+
body: message,
|
|
198
|
+
attributes: {
|
|
199
|
+
service: this.service,
|
|
200
|
+
...(metadata && { "log.metadata": JSON.stringify(metadata) }),
|
|
201
|
+
...(activeSpan && {
|
|
202
|
+
trace_id: activeSpan.spanContext().traceId,
|
|
203
|
+
span_id: activeSpan.spanContext().spanId,
|
|
204
|
+
}),
|
|
205
|
+
},
|
|
206
|
+
});
|
|
180
207
|
}
|
|
181
208
|
trace(message, metadata) {
|
|
182
209
|
this.log("trace", message, metadata);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@townco/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.27",
|
|
5
5
|
"description": "core",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -16,9 +16,13 @@
|
|
|
16
16
|
"require": "./dist/index.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@opentelemetry/api": "^1.9.0",
|
|
21
|
+
"@opentelemetry/api-logs": "^0.56.0"
|
|
22
|
+
},
|
|
19
23
|
"devDependencies": {
|
|
20
24
|
"typescript": "^5.9.3",
|
|
21
|
-
"@townco/tsconfig": "0.1.
|
|
25
|
+
"@townco/tsconfig": "0.1.46"
|
|
22
26
|
},
|
|
23
27
|
"scripts": {
|
|
24
28
|
"build": "tsc",
|