codex-lens 0.1.0 → 0.1.1
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/build.js +1 -0
- package/dist/lib/logger.js +77 -0
- package/package.json +1 -1
package/build.js
CHANGED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync } from "fs";
|
|
3
|
+
import { dirname, join, resolve } from "path";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
const LOG_DIR = resolve(__dirname, "../../logs");
|
|
8
|
+
const LEVELS = {
|
|
9
|
+
DEBUG: 0,
|
|
10
|
+
INFO: 1,
|
|
11
|
+
WARN: 2,
|
|
12
|
+
ERROR: 3
|
|
13
|
+
};
|
|
14
|
+
let sharedLogFile = null;
|
|
15
|
+
let sharedInitDone = false;
|
|
16
|
+
class Logger {
|
|
17
|
+
constructor(moduleName, level = "INFO") {
|
|
18
|
+
this.moduleName = moduleName;
|
|
19
|
+
this.level = LEVELS[level] ?? LEVELS.INFO;
|
|
20
|
+
}
|
|
21
|
+
init() {
|
|
22
|
+
if (!sharedInitDone) {
|
|
23
|
+
if (!existsSync(LOG_DIR)) {
|
|
24
|
+
mkdirSync(LOG_DIR, { recursive: true });
|
|
25
|
+
}
|
|
26
|
+
const now = /* @__PURE__ */ new Date();
|
|
27
|
+
const timestamp = now.toISOString().replace(/[:.]/g, "-").slice(0, 19);
|
|
28
|
+
sharedLogFile = join(LOG_DIR, `${timestamp}.txt`);
|
|
29
|
+
appendFileSync(sharedLogFile, `
|
|
30
|
+
========== Session Started: ${now.toISOString()} ==========
|
|
31
|
+
`);
|
|
32
|
+
sharedInitDone = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
_format(level, message) {
|
|
36
|
+
const now = /* @__PURE__ */ new Date();
|
|
37
|
+
const timestamp = now.toISOString();
|
|
38
|
+
return `[${timestamp}] [${level}] [${this.moduleName}] ${message}`;
|
|
39
|
+
}
|
|
40
|
+
_write(level, message) {
|
|
41
|
+
if (LEVELS[level] < this.level) return;
|
|
42
|
+
const formatted = this._format(level, message);
|
|
43
|
+
console.log(formatted);
|
|
44
|
+
if (sharedLogFile) {
|
|
45
|
+
try {
|
|
46
|
+
appendFileSync(sharedLogFile, formatted + "\n");
|
|
47
|
+
} catch (e) {
|
|
48
|
+
console.error("Failed to write to log file:", e);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
debug(message) {
|
|
53
|
+
this._write("DEBUG", message);
|
|
54
|
+
}
|
|
55
|
+
info(message) {
|
|
56
|
+
this._write("INFO", message);
|
|
57
|
+
}
|
|
58
|
+
warn(message) {
|
|
59
|
+
this._write("WARN", message);
|
|
60
|
+
}
|
|
61
|
+
error(message) {
|
|
62
|
+
this._write("ERROR", message);
|
|
63
|
+
}
|
|
64
|
+
errorWithStack(message, error) {
|
|
65
|
+
const stack = error?.stack || error?.message || error || "";
|
|
66
|
+
this._write("ERROR", `${message}
|
|
67
|
+
${stack}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function createLogger(moduleName, level = "INFO") {
|
|
71
|
+
const logger = new Logger(moduleName, level);
|
|
72
|
+
logger.init();
|
|
73
|
+
return logger;
|
|
74
|
+
}
|
|
75
|
+
export {
|
|
76
|
+
createLogger
|
|
77
|
+
};
|
package/package.json
CHANGED