MCPcopy Create free account
hub / github.com/anus-dev/ANUS / initialize

Method initialize

packages/core/src/core/logger.ts:129–161  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127 }
128
129 async initialize(): Promise<void> {
130 if (this.initialized) {
131 return;
132 }
133
134 this.anusDir = getProjectTempDir(process.cwd());
135 this.logFilePath = path.join(this.anusDir, LOG_FILE_NAME);
136
137 try {
138 await fs.mkdir(this.anusDir, { recursive: true });
139 let fileExisted = true;
140 try {
141 await fs.access(this.logFilePath);
142 } catch (_e) {
143 fileExisted = false;
144 }
145 this.logs = await this._readLogFile();
146 if (!fileExisted && this.logs.length === 0) {
147 await fs.writeFile(this.logFilePath, '[]', 'utf-8');
148 }
149 const sessionLogs = this.logs.filter(
150 (entry) => entry.sessionId === this.sessionId,
151 );
152 this.messageId =
153 sessionLogs.length > 0
154 ? Math.max(...sessionLogs.map((entry) => entry.messageId)) + 1
155 : 0;
156 this.initialized = true;
157 } catch (err) {
158 console.error('Failed to initialize logger:', err);
159 this.initialized = false;
160 }
161 }
162
163 private async _updateLogFile(
164 entryToAppend: LogEntry,

Callers 1

useLoggerFunction · 0.95

Calls 3

_readLogFileMethod · 0.95
getProjectTempDirFunction · 0.85
mkdirMethod · 0.80

Tested by

no test coverage detected