1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-08 10:47:45 +03:00

fix(server): create errors.log if it does not exist before parsing logs

This commit is contained in:
louistiti 2023-04-18 09:21:05 +08:00
parent e5fdeba50b
commit b16475766a
No known key found for this signature in database
GPG Key ID: 92CD6A2E497E1669

View File

@ -89,23 +89,23 @@ export class LogHelper {
* @example parseErrorLogs() // 'Failed to connect to the TCP server: Error: read ECONNRESET'
*/
public static async parseErrorLogs(): Promise<string[]> {
if (fs.existsSync(LogHelper.ERRORS_FILE_PATH)) {
const errorFileContent = await fs.promises.readFile(
LogHelper.ERRORS_FILE_PATH,
'utf8'
)
const errorLogs = errorFileContent
.trim()
.split(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2} - /)
// Remove the first empty string if there's one
if (errorLogs[0] === '') {
errorLogs.shift()
}
return errorLogs
if (!fs.existsSync(LogHelper.ERRORS_FILE_PATH)) {
await fs.promises.open(LogHelper.ERRORS_FILE_PATH, 'w')
}
return ['']
const errorFileContent = await fs.promises.readFile(
LogHelper.ERRORS_FILE_PATH,
'utf8'
)
const errorLogs = errorFileContent
.trim()
.split(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2} - /)
// Remove the first empty string if there's one
if (errorLogs[0] === '') {
errorLogs.shift()
}
return errorLogs
}
}