@townco/core 0.0.76 → 0.0.78
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.d.ts +1 -3
- package/dist/logger.js +16 -14
- package/package.json +2 -2
package/dist/logger.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* In Node.js environment with logsDir option, also writes to .logs/ directory
|
|
6
6
|
*/
|
|
7
7
|
export type LogLevel = "trace" | "debug" | "info" | "warn" | "error" | "fatal";
|
|
8
|
+
export declare const LOG_FILE_NAME = "agent.log";
|
|
8
9
|
export interface LogEntry {
|
|
9
10
|
id: string;
|
|
10
11
|
timestamp: string;
|
|
@@ -34,10 +35,7 @@ export declare function configureLogsDir(logsDir: string): void;
|
|
|
34
35
|
export declare class Logger {
|
|
35
36
|
private service;
|
|
36
37
|
private minLevel;
|
|
37
|
-
private logFilePath?;
|
|
38
38
|
private logsDir?;
|
|
39
|
-
private writeQueue;
|
|
40
|
-
private isWriting;
|
|
41
39
|
private enableConsoleOutput;
|
|
42
40
|
constructor(service: string, minLevel?: LogLevel);
|
|
43
41
|
private setupFileLogging;
|
package/dist/logger.js
CHANGED
|
@@ -12,6 +12,11 @@ let nodeFs = null;
|
|
|
12
12
|
let nodePath = null;
|
|
13
13
|
// Global logs directory configuration (set once at app startup for TUI)
|
|
14
14
|
let globalLogsDir;
|
|
15
|
+
// Unified log file name - all services write to single file
|
|
16
|
+
export const LOG_FILE_NAME = "agent.log";
|
|
17
|
+
// Module-level shared write queue for all loggers
|
|
18
|
+
const globalWriteQueue = [];
|
|
19
|
+
let isGlobalWriting = false;
|
|
15
20
|
// Global log store
|
|
16
21
|
const globalLogStore = [];
|
|
17
22
|
let logIdCounter = 0;
|
|
@@ -80,10 +85,7 @@ const _LOG_STYLES = {
|
|
|
80
85
|
export class Logger {
|
|
81
86
|
service;
|
|
82
87
|
minLevel;
|
|
83
|
-
logFilePath;
|
|
84
88
|
logsDir;
|
|
85
|
-
writeQueue = [];
|
|
86
|
-
isWriting = false;
|
|
87
89
|
enableConsoleOutput;
|
|
88
90
|
constructor(service, minLevel = "debug") {
|
|
89
91
|
this.service = service;
|
|
@@ -115,7 +117,6 @@ export class Logger {
|
|
|
115
117
|
if (!nodeFs || !nodePath)
|
|
116
118
|
return;
|
|
117
119
|
this.logsDir = globalLogsDir;
|
|
118
|
-
this.logFilePath = nodePath.join(this.logsDir, `${this.service}.log`);
|
|
119
120
|
// Create logs directory if it doesn't exist
|
|
120
121
|
if (!nodeFs.existsSync(this.logsDir)) {
|
|
121
122
|
nodeFs.mkdirSync(this.logsDir, { recursive: true });
|
|
@@ -126,26 +127,27 @@ export class Logger {
|
|
|
126
127
|
}
|
|
127
128
|
}
|
|
128
129
|
async writeToFile(content) {
|
|
129
|
-
if (!this.
|
|
130
|
+
if (!this.logsDir || !isNode || !nodePath)
|
|
130
131
|
return;
|
|
131
|
-
|
|
132
|
-
if (
|
|
132
|
+
globalWriteQueue.push(content);
|
|
133
|
+
if (isGlobalWriting) {
|
|
133
134
|
return;
|
|
134
135
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
isGlobalWriting = true;
|
|
137
|
+
const logFilePath = nodePath.join(this.logsDir, LOG_FILE_NAME);
|
|
138
|
+
while (globalWriteQueue.length > 0) {
|
|
139
|
+
const batch = globalWriteQueue.splice(0, globalWriteQueue.length);
|
|
138
140
|
const data = `${batch.join("\n")}\n`;
|
|
139
141
|
try {
|
|
140
142
|
// Dynamic import for Node.js modules
|
|
141
143
|
const fs = require("node:fs");
|
|
142
|
-
await fs.promises.appendFile(
|
|
144
|
+
await fs.promises.appendFile(logFilePath, data, "utf-8");
|
|
143
145
|
}
|
|
144
146
|
catch (_error) {
|
|
145
147
|
// Silently fail
|
|
146
148
|
}
|
|
147
149
|
}
|
|
148
|
-
|
|
150
|
+
isGlobalWriting = false;
|
|
149
151
|
}
|
|
150
152
|
shouldLog(level) {
|
|
151
153
|
return LOG_LEVELS[level] >= LOG_LEVELS[this.minLevel];
|
|
@@ -168,10 +170,10 @@ export class Logger {
|
|
|
168
170
|
notifyLogSubscribers(entry);
|
|
169
171
|
// Write to file in Node.js (for logs tab to read)
|
|
170
172
|
// Lazily set up file logging if globalLogsDir was configured after this logger was created
|
|
171
|
-
if (isNode && !this.
|
|
173
|
+
if (isNode && !this.logsDir && globalLogsDir) {
|
|
172
174
|
this.setupFileLogging();
|
|
173
175
|
}
|
|
174
|
-
if (isNode && this.
|
|
176
|
+
if (isNode && this.logsDir) {
|
|
175
177
|
// Write as JSON without the id field (to match expected format)
|
|
176
178
|
const fileEntry = {
|
|
177
179
|
timestamp: entry.timestamp,
|
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.78",
|
|
5
5
|
"description": "core",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@typescript/native-preview": "^7.0.0-dev.20251207.1",
|
|
33
|
-
"@townco/tsconfig": "0.1.
|
|
33
|
+
"@townco/tsconfig": "0.1.97"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsgo",
|