electron-log icon indicating copy to clipboard operation
electron-log copied to clipboard

Allow to reinitialize console transport

Open clemp6r opened this issue 2 years ago • 3 comments

Currently console.js in electron-log makes references to console functions (e.g console.log, etc.) during module initialization (source).

This can lead to problems if the application (or its libraries) then make replacements of these functions.

For instance, the Sentry library replaces (wraps) console functions when it is initialized (call to Sentry.init) (source) so it can intercept all log messages and report them to the Sentry service. As electron-log keep reference to the original/unwrapped functions, all messages created with electron-log are invisible to Sentry.

As a consequence this makes electron-log unusable for projects that uses Sentry or similar libraries.

It would be nice to have a way to tell electron-log to reinitialize its console transport. Or (maybe better) console.js would be partially rewritten so it does not keep references to console functions at module initialization and instead uses the console object again each time its methods need to be called.

Thanks for any feedback

clemp6r avatar Oct 05 '21 15:10 clemp6r

I'll think about it for v5 release.

megahertz avatar Oct 06 '21 04:10 megahertz

We would also like to use it in combination with Sentry... @clemp6r did you find a workaround?

stoefln avatar Dec 07 '21 09:12 stoefln

@stoefln No, we just postponed integration of log files for now.

clemp6r avatar Dec 07 '21 09:12 clemp6r

Any update? Is there a possibility we have a quick workaround until v5 is out?

clemp6r avatar Nov 08 '22 10:11 clemp6r

See my PR that fixes the issue: https://github.com/megahertz/electron-log/pull/330

clemp6r avatar Nov 08 '22 11:11 clemp6r

Thank you @clemp6r . Unfortunately, I can't approve this PR. While it solves an issues with Sentry, it breaks the following case: Object.assign(console, log.functions);. Please let me know if I missed something.

Anyaway, I'm going to publish v5 beta in the next 2-3 weeks

megahertz avatar Nov 08 '22 13:11 megahertz

Ok, no problem, I will close the PR and keep the change for myself.

clemp6r avatar Nov 08 '22 15:11 clemp6r

In v5 console transport has writeFn which allows to override a console call.

megahertz avatar Nov 24 '22 13:11 megahertz