MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / init

Method init

src/utils/logger.ts:27–54  ·  view source on GitHub ↗
(minLevel: LogLevel = 'info')

Source from the content-addressed store, hash-verified

25 }
26
27 async init(minLevel: LogLevel = 'info'): Promise<void> {
28 this.minLevel = minLevel;
29 const dir = path.dirname(this.logFile);
30 await fs.mkdir(dir, { recursive: true });
31
32 // Truncate if larger than 10MB
33 try {
34 const stat = await fs.stat(this.logFile);
35 if (stat.size > 10 * 1024 * 1024) {
36 await fs.writeFile(this.logFile, '');
37 }
38 } catch (err) {
39 // The logger can't reliably log about itself; warn once on stderr so an
40 // unbounded log file (rotation truncate failing) doesn't go unnoticed.
41 if (!warnedRotateFailed) {
42 warnedRotateFailed = true;
43 try {
44 process.stderr.write(`qodex: log rotation check failed for ${this.logFile}: ${(err as any)?.message ?? err}\n`);
45 } catch { /* intentional: logger must never throw */ }
46 }
47 }
48
49 this.initialized = true;
50 if (this.buffer.length > 0) {
51 await fs.appendFile(this.logFile, this.buffer.join('\n') + '\n');
52 this.buffer = [];
53 }
54 }
55
56 private async write(level: LogLevel, msg: string, meta?: Record<string, unknown>): Promise<void> {
57 if (LEVEL_PRIORITY[level] < LEVEL_PRIORITY[this.minLevel]) return;

Callers 2

bootstrapFunction · 0.80
initTreeSitterFunction · 0.80

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected