2020-10-13 16:05:41 +00:00
|
|
|
import log from 'electron-log';
|
|
|
|
import { isDevelopment } from './constants';
|
2020-10-20 11:01:47 +00:00
|
|
|
import { dirname } from 'path';
|
2020-10-13 16:05:41 +00:00
|
|
|
|
|
|
|
export const initializeLogging = () => {
|
|
|
|
if (isDevelopment()) {
|
|
|
|
// Disable file logging during development
|
|
|
|
log.transports.file.level = false;
|
|
|
|
} else {
|
|
|
|
const fileTransport = log.transports.file;
|
|
|
|
const logFile = fileTransport.getFile();
|
|
|
|
// Set the max log file size to 10mb
|
|
|
|
// When the log file exceeds this limit, it will be rotated to {file name}.old.log file.
|
|
|
|
fileTransport.maxSize = 1024 * 1024 * 10;
|
|
|
|
// Rotate the log file every time we start the app
|
2021-05-12 06:35:00 +00:00
|
|
|
// @ts-expect-error -- TSCONVERSION seems like something is wrong here but I don't want to convert to string until I can take a closer look
|
2020-10-13 16:05:41 +00:00
|
|
|
fileTransport.archiveLog(logFile);
|
|
|
|
logFile.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite the console.log/warn/etc methods
|
|
|
|
Object.assign(console, log.functions);
|
|
|
|
};
|
|
|
|
|
2021-05-12 06:35:00 +00:00
|
|
|
export function getLogDirectory() {
|
2020-10-20 11:01:47 +00:00
|
|
|
const logPath = log.transports.file.getFile().path;
|
|
|
|
return dirname(logPath);
|
|
|
|
}
|
|
|
|
|
2020-10-13 16:05:41 +00:00
|
|
|
export default log;
|