Reputation: 343
I want to write logs to file from RN app. I want to use files for a few reasons:
QA/debugging - I send the app to QA/other developers. In case of an error, I want them to send me the file, so I will understand what is the issue.
On production, I might want to send the log file to the server on specific scenarios (critical bugs).
I don't mind asking for storage permission since I need it anyway (for other features). It's very strange that I didn't find any package for it. I expect to have something like log4j/logback, including rolling file, log levels, etc. Is there any package that can do this?
Upvotes: 2
Views: 8231
Reputation: 9979
react-native-file-log is a good choice. It can log messages to files.
Usage:
import RNReactLogging from 'react-native-file-log';
RNReactLogging.setTag('MyAppName'); // default: RNReactLogging
RNReactLogging.setConsoleLogEnabled(false); // default: true
RNReactLogging.setFileLogEnabled(true); // default: false
RNReactLogging.setMaxFileSize(1024 * 1024); // default: 512 * 1024 ~ 512 kb
RNReactLogging.printLog('test log');
Also check Rollbar which is a realtime crash and error logging solution.
Upvotes: 4