Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to prevent the creation of default main.log file #230

Closed
amarshetty6 opened this issue Dec 22, 2020 · 6 comments
Closed

Is there a way to prevent the creation of default main.log file #230

amarshetty6 opened this issue Dec 22, 2020 · 6 comments

Comments

@amarshetty6
Copy link

amarshetty6 commented Dec 22, 2020

I have configured to write the log files in my custom app path which works fine. But i still see the initial log file created in ~/Library/Logs/ + appName + / + main.log on macOS. Is there a way i can prevent this or at least change the appName in the default path without affecting my custom path ?

@megahertz
Copy link
Owner

Are you sure a new path is configured right after electron-log is requires for the first time? If so, could you provide code which can reproducing the issue?

@amarshetty6
Copy link
Author

Hi this is the part in main.js where i am setting up the logger
app.on('ready', function () {
appWindow.createWindow();
errorLogger.setupLogger();
})

function setupLogger() {
var __dirname;
var _file = 'appname.log';
if (process.platform === 'darwin') {
__dirname = '/Library/Application\ Support/appname//Logs/';
}else if (process.platform === 'win32') {
__dirname = 'C:/ProgramData/appname/logs/';
}
logger.transports.file.level = 'info';
logger.transports.file.maxSize = 5 * 1024 * 1024;
logger.transports.file.resolvePath = () => path.join(__dirname, _file);
}
Am i missing something?
Please let me know if you need anything else i cant share the complete code but will try as much as possible to reproduce the issue.

@megahertz
Copy link
Owner

First of all, try to call setupLogger() on entry point. app ready event may be fired too late.

@amarshetty6
Copy link
Author

amarshetty6 commented Dec 23, 2020

Tried calling setupLogger() after requires in main.js but still seeing the issue.
Anything else i can try?

@megahertz
Copy link
Owner

If main.log is not empty, it does mean that logging is called before initialization. There are many ways how to find what happens. In such a situation, I usually prefer to patch a library for debugging (in node_modules). For example, you can patch log function in electron-log/src/log.js by adding console.log(new Error().stack); to find a place where the first call occurs. After that, node_modules should be reset.

@amarshetty6
Copy link
Author

I was able to find the entry point where the first log was being written using your suggested method and moved my function accordingly. Now it is working fine. Thanks a lot for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants