Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
react-native-file-logger
Advanced tools
A simple file-logger for React Native with configurable rolling policy, based on CocoaLumberjack on iOS and Logback on Android.
FileLogger.configure()
and you're done. All your existing console.log/debug/...
calls are automatically logged into a fileReact-native-file-logger uses the undocumented global.__inspectorLog
from React Native. It allows to intercept any calls to console
and to retrieve the already-formatted log message. React-native-file-logger uses file-loggers from CocoaLumberjack on iOS and Logback Android on Android to append messages into log files with an optional rolling policy.
npm i react-native-file-logger
npx pod-install
import { FileLogger } from "react-native-file-logger";
FileLogger.configure();
This is all you need to add file-logging to your app. All your existing console
calls will be appended to a log file. FileLogger.configure()
also takes options to customize the rolling policy, log directory path or log-level. If you don't want to use console
calls for logging, you can also use the direct access API.
Initialize the file-logger with the specified options. As soon as the returned promise is resolved, all console
calls are appended to a log file. To ensure that no logs are missing, it is good practice to await
this call at the launch of your app.
Option | Description | Default |
---|---|---|
logLevel | Minimum log level for file output (it won't affect console output) | LogLevel.Debug |
formatter | A function that takes the log level and message and returns the formatted string to write to the log file. | Default format: ${now} [${level}] ${msg} |
captureConsole | If true , all console calls are automatically captured and written to a log file. It can also be changed by calling the enableConsoleCapture() and disableConsoleCapture() methods | true |
dailyRolling | If true , a new log file is created every day | true |
maximumFileSize | A new log file is created when current log file exceeds the given size in bytes. 0 to disable | 1024 * 1024 (1MB) |
maximumNumberOfFiles | Maximum number of log files to keep. When a new log file is created, if the total number of files exceeds this limit, the oldest file is deleted. 0 to disable | 5 |
logsDirectory | Absolute path of directory where log files are stored. If not defined, log files are stored in the cache directory of the app | undefined |
Send all log files by email. On iOS, it uses MFMailComposeViewController
to ensure that the user won't leave the app when sending log files.
Option | Description |
---|---|
to | Email address of the recipient |
subject | Email subject |
body | Plain text body message of the email |
Enable appending messages from console
calls to the current log file. It is already enabled by default when calling FileLogger.configure()
.
After calling this method, console
calls will no longer be written to the current log file.
Change the minimum log level for file-output. The initial log level can be passed as an option to FileLogger.configure()
.
Return the current log level.
Returns a promise with the absolute paths to the log files.
Remove all log files. Next console
calls will be appended to a new empty log file.
If you don't want to use console
calls for file-logging, you can directly use the following methods to directly write messages to the log file. It is encouraged to wrap these calls with your own logger API.
Shortcut for FileLogger.write(LogLevel.Debug, msg)
.
Shortcut for FileLogger.write(LogLevel.Info, msg)
.
Shortcut for FileLogger.write(LogLevel.Warning, msg)
.
Shortcut for FileLogger.write(LogLevel.Error, msg)
.
Append the given message to the log file with the specified log level. The message will be formatted with the formatter
function specified during the FileLogger.configure()
call.
FAQs
A simple file-logger for React Native
The npm package react-native-file-logger receives a total of 5,335 weekly downloads. As such, react-native-file-logger popularity was classified as popular.
We found that react-native-file-logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.