megahertz / electron-log

Simple logging module Electron/Node.js/NW.js application. No dependencies. No complicated configuration.
MIT License
1.3k stars 127 forks source link

Error Handling #341

Closed monica-muthukumaran closed 1 year ago

monica-muthukumaran commented 1 year ago

Hey! I was trying to handle errors in electron-log. Scenario: If a user tries to log in an un-authorized location exception to be caught and handled accordingly.

logger.transports.file.resolvePath = () => 'C:/Users/Administrator/Logs' +\main_${Date.now()}.log logger.transports.file.resolvePath(); logger.catchErrors();

the below error is not handled by try catch aswell image

megahertz commented 1 year ago

Log functions shouldn't throw errors, otherwise it may break the whole app since such a call is widely used across the whole app in most cases. A custom log path should be used carefully.

monica-muthukumaran commented 1 year ago

Is there any alternative way atleast a one-time catch, later we could play around with flags.?

megahertz commented 1 year ago

The only way is checking whether a file is writable before logger initialization.