Skip to content

Commit

Permalink
add better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
seiyria committed Oct 1, 2024
1 parent 4a2cd4e commit acf15fd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions app/helpers/modtest.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import * as childProcess from 'child_process';
import { app } from 'electron';
import log from 'electron-log';
import * as fs from 'fs-extra';
import * as path from 'path';

import { SendToUI } from '../types';
import { baseUrl } from './constants';

let mongoProcess: any = null;
let lotrProcess: any = null;

const testLogger = log.create({ logId: 'modtest' });

testLogger.transports.file.level = 'info';

testLogger.transports.file.resolvePathFn = () =>
path.join(app.getAppPath(), 'logs/modtest.log');

process.on('exit', () => {
console.log('Attempting to clean up stray processes...');
testLogger.log('Attempting to clean up stray processes...');
killMod();
});

Expand Down Expand Up @@ -83,7 +93,15 @@ MODS_TO_LOAD=mod
mongoProcess = childProcess.exec(
`${baseUrl}/resources/mongodb/bin/mongod.exe --port 35353 --dbpath ${baseUrl}/resources/mongodb/data/db`,
{},
() => {}
(error, stdout, stderr) => {
if (error) {
testLogger.error(`mongo error: ${error}`);
return;
}

testLogger.log(`mongo stdout: ${stdout}`);
testLogger.error(`mongo stderr: ${stderr}`);
}
);
}

Expand All @@ -93,7 +111,7 @@ MODS_TO_LOAD=mod
sendToUI('notify', { type: 'info', text: 'Stopping old Rair Server...' });
childProcess.exec('taskkill /F /IM lotr-server.exe');
} catch (e) {
console.error(e);
testLogger.error(e);
}
}

Expand All @@ -104,11 +122,12 @@ MODS_TO_LOAD=mod
{ cwd: `${baseUrl}/resources/rair` },
(error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
testLogger.error(`rair error: ${error}`);
return;
}
console.log(`stdout: ${stdout}`);
console.error(`stderr: ${stderr}`);

testLogger.log(`rair stdout: ${stdout}`);
testLogger.error(`rair stderr: ${stderr}`);
}
);

Expand Down
2 changes: 1 addition & 1 deletion app/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const isDevelopment = !app.isPackaged;

log.transports.file.level = 'info';

log.transports.file.resolvePath = () =>
log.transports.file.resolvePathFn = () =>
path.join(app.getAppPath(), 'logs/main.log');

process.on('uncaughtException', (err) => {
Expand Down

0 comments on commit acf15fd

Please sign in to comment.