a8dda20a30
* fix(desktop): rotate electron and backend logs * refactor(desktop): centralize log rotation defaults and debug fs errors * fix(desktop): harden rotation fs ops and buffer backend log writes * refactor(desktop): extract buffered logger and reduce sync stat calls * refactor(desktop): simplify rotation flow and harden logger config * fix(desktop): make app logging async and flush-safe * fix: harden app log path switching and debug-gated rotation errors * fix: cap buffered log chunk size during path switch * fix: avoid redundant plugin reinstall and upgrade electron * fix: stop webchat tasks cleanly and bind packaged backend to localhost * fix: unify platform shutdown and await webchat listener cleanup * fix: improve startup logs for dashboard and onebot listeners * fix: revert extra startup service logs * fix: harden plugin import recovery and webchat listener cleanup * fix: pin dashboard ci node version to 24.13.0 * fix: avoid duplicate webchat listener cleanup on terminate * refactor: clarify platform task lifecycle management * fix: continue platform shutdown when terminate fails
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
const path = require('path');
|
|
const { RotatingLogWriter } = require('./rotating-log-writer');
|
|
const {
|
|
formatLogTimestamp,
|
|
parseLogBackupCount,
|
|
parseLogMaxBytes,
|
|
} = require('./common');
|
|
|
|
function createElectronLogger({ app, getRootDir }) {
|
|
const electronLogMaxBytes = parseLogMaxBytes(
|
|
process.env.ASTRBOT_ELECTRON_LOG_MAX_MB,
|
|
);
|
|
const electronLogBackupCount = parseLogBackupCount(
|
|
process.env.ASTRBOT_ELECTRON_LOG_BACKUP_COUNT,
|
|
);
|
|
const writer = new RotatingLogWriter({
|
|
logPath: null,
|
|
maxBytes: electronLogMaxBytes,
|
|
backupCount: electronLogBackupCount,
|
|
label: 'electron-log',
|
|
});
|
|
|
|
function getElectronLogPath() {
|
|
const rootDir =
|
|
process.env.ASTRBOT_ROOT ||
|
|
(typeof getRootDir === 'function' ? getRootDir() : null) ||
|
|
app.getPath('userData');
|
|
return path.join(rootDir, 'logs', 'electron.log');
|
|
}
|
|
|
|
function logElectron(message) {
|
|
const logPath = getElectronLogPath();
|
|
const line = `[${formatLogTimestamp()}] ${message}\n`;
|
|
void writer.setLogPath(logPath);
|
|
void writer.append(line);
|
|
}
|
|
|
|
async function flushElectron() {
|
|
await writer.flush();
|
|
}
|
|
|
|
return {
|
|
getElectronLogPath,
|
|
logElectron,
|
|
flushElectron,
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
createElectronLogger,
|
|
};
|