2

I want to write logs to file from RN app. I want to use files for a few reasons:

  1. 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.

  2. 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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks ! react-native-file-log has only 2 stars on github - why ? I wonder why file logging is not common on RN apps.
Ya. There is only a few stars for that repo. And only 22 weekly downloads. But the scenario is rare. Logging is mainly used only at development phase.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.