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

Renderer logs not written to file after updating to v5.2.0 #441

Open
tomdixon opened this issue Oct 31, 2024 · 6 comments
Open

Renderer logs not written to file after updating to v5.2.0 #441

tomdixon opened this issue Oct 31, 2024 · 6 comments

Comments

@tomdixon
Copy link

Hi,

After updating to v5.2.0 from v4.2.2 I'm no longer seeing renderer process logs written to the renderer.log file as before. I've set up the main/remote logging as per the README, and I am getting console logs which indicates that the logs are being sent to the main process via IPC ok. Any ideas what I might be doing wrong?

My setup is as follows:

Main process

import log from 'electron-log/main';

log.initialize();
log.transports.file.level = IS_DEV ? 'debug' : 'info';
log.transports.console.level = IS_DEV ? 'debug' : false;

Renderer process

import log from 'electron-log/renderer';

log.info('Hello world')
@megahertz
Copy link
Owner

megahertz commented Oct 31, 2024

Your code looks fine. Can you try to call logging with a delay in a renderer process? E.g. setTimeout(() => log.info('Hello world'), 1000)

@tomdixon
Copy link
Author

Thanks for the quick reply. Unfortunately that still doesn't lead to the log file being written. I'm just trying it now in a vanilla Electron project. If that also doesn't work I'll link to the code here.

@tomdixon
Copy link
Author

OK I figured it out. Two things happening at once!

  1. All logs are now being written to main.log. Is this intentional? Is there anyway to configure the file logger to use a different file path for renderer logs?
  2. I tracked down a codepath from my main process that was using a shared util which imported from 'electron-log/renderer'. It seems that if this import exists in the main process at all (even if the log function is never called) then renderer logs stop logging to file. Is there a recommended setup here, as I can imagine this being an easy trap to fall into especially if you use shared utilities between main and renderer code?

@megahertz
Copy link
Owner

  1. You can configure a custom log path through the resolvePath callback. The second argument is a message object containing information about the process where the log was generated.
  2. I didn't think about such a case. You're right, it would be nice to warn about it.

@TuKun33
Copy link

TuKun33 commented Nov 8, 2024

Your code looks fine. Can you try to call logging with a delay in a renderer process? E.g. setTimeout(() => log.info('Hello world'), 1000)

Hello, I encountered a similar problem. The logs printed in the main process are not printed in the console of the renderer process. Is it because I am not using bundler, I cannot import "electron-log/renderer" in HTML, or is it another configuration problem?

@megahertz
Copy link
Owner

@TuKun33 When contextIsolation/sandboxing is enabled (by default), and no bundling is used, it's only possible to use a limited set of logger features in a renderer process.

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

3 participants