Logging to a log level with undefined transport causes app to crash
kalyncoose opened this issue · 2 comments
Bug Description
After reading this section of the READ_ME
, Logs Only In Development Mode, I was lead to believe that I could trick the __DEV__
false/else clause to use undefined
for transport
so that a Release variant of the app would not utilize logging at all. Unfortunately it causes the app to completely crash (go to home screen on the device) so it appears react-native-logs
does not have any exception handling when it comes to attempting to log to a level where there is no transport
setup.
Bug Reproduction
Here is the general pattern of what causes the app to crash:
- Logger Config has:
transport: __DEV__ ? consoleTransport : undefined,
severity: __DEV__ ? 'info' : 'warn'
- App starts up fine in Release variant, but when encounters a
log.warn()
it crashes to device's home screen
Proposed Solution
Add exception handling to react-native-logs
internal library code so it does its own warning to console if this scenario occurs - rather than completely crashing the app.
Note: I am mostly just submitting this issue for others to read as a possibility for what happens when you use the logger config this way.
Thanks, i've added an error handling for this. 5c0fea3
I'm just now getting around to testing this fix, and it appears if you continue to use undefined
log transport config it will still cause an app crash (because your fix now does throw Error
which I guess RN does not like since it is not caught anywhere). To workaround this issue, I tried instead defining transport in release mode as an empty function like so:
transport: __DEV__ ? consoleTransport : () => {},
This appears to prevent the app from crashing as the transport logic is happy and does not throw a JS/TS error. Let me know if you think this may have any adverse side effects that I should consider.
Thanks!