| 155 | } |
| 156 | |
| 157 | #openLogFile () { |
| 158 | // Count in filename will be 0 indexed |
| 159 | const count = this.#files.length |
| 160 | |
| 161 | try { |
| 162 | // Pad with zeros so that our log files are always sorted properly |
| 163 | // We never want to write files ending in `-9.log` and `-10.log` because log file cleaning is done by deleting the oldest. |
| 164 | // So in this example `-10.log` would be deleted next. |
| 165 | const f = this.#getLogFilePath(padZero(count, this.#MAX_FILES_PER_PROCESS)) |
| 166 | // Some effort was made to make the async, but we need to write logs during process.on('exit') which has to be synchronous. |
| 167 | // So in order to never drop log messages, it is easiest to make it sync all the time and this was measured to be about 1.5% slower for 40k lines of output |
| 168 | const logStream = new fsMiniPass.WriteStreamSync(f, { flags: 'a' }) |
| 169 | if (count > 0) { |
| 170 | // Reset file log count if we are opening after our first file |
| 171 | this.#fileLogCount = 0 |
| 172 | } |
| 173 | this.#files.push(logStream.path) |
| 174 | return logStream |
| 175 | } catch (e) { |
| 176 | // If the user has a readonly logdir then we don't want to warn this on every command so it should be verbose |
| 177 | log.verbose('logfile', `could not be created: ${e}`) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | async #cleanLogs () { |
| 182 | // module to clean out the old log files this is a best-effort attempt. |