All Projects → BeTomorrow → react-native-file-logger

BeTomorrow / react-native-file-logger

Licence: other
A simple file-logger for React Native with configurable rolling policy, based on CocoaLumberjack on iOS and Logback on Android.

Programming Languages

java
68154 projects - #9 most used programming language
objective c
16641 projects - #2 most used programming language
javascript
184084 projects - #8 most used programming language
typescript
32286 projects
ruby
36898 projects - #4 most used programming language
Starlark
911 projects

Projects that are alternatives of or similar to react-native-file-logger

Microservices Sample
Sample project to create an application using microservices architecture
Stars: ✭ 167 (+735%)
Mutual labels:  logback
CocoaLogKit
Log framework based on CocoaLumberjack and ZipArchive
Stars: ✭ 17 (-15%)
Mutual labels:  cocoalumberjack
logunit
A Java library for unit-testing logging.
Stars: ✭ 40 (+100%)
Mutual labels:  logback
Stubbornjava
Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.
Stars: ✭ 184 (+820%)
Mutual labels:  logback
springboot-tutorials
codehome出品SpringBoot2.x基础教程
Stars: ✭ 77 (+285%)
Mutual labels:  logback
owasp-security-logging
OWASP Security Logging library for Java
Stars: ✭ 106 (+430%)
Mutual labels:  logback
Logback Gelf
Logback appender for sending GELF messages with zero additional dependencies.
Stars: ✭ 146 (+630%)
Mutual labels:  logback
echopraxia
Java Logging API with clean and simple structured logging and conditional & contextual features. JSON implementations in Logback and Log4J.
Stars: ✭ 37 (+85%)
Mutual labels:  logback
slack-webhook-appender
Logback appender which posts logs to slack via incoming webhook.
Stars: ✭ 16 (-20%)
Mutual labels:  logback
logback-s3-rolling-policy
Logback RollingPolicy to store logs in S3
Stars: ✭ 26 (+30%)
Mutual labels:  logback
Java Library Examples
💪 example of common used libraries and frameworks, programming required, don't fork man.
Stars: ✭ 204 (+920%)
Mutual labels:  logback
logback-access-spring-boot-starter
Spring Boot Starter for Logback-access.
Stars: ✭ 153 (+665%)
Mutual labels:  logback
liquibase-slf4j
Liquibase SLF4J Logger.
Stars: ✭ 42 (+110%)
Mutual labels:  logback
Tomcat Slf4j Logback
Tomcat, SLF4J and Logback integration Releases
Stars: ✭ 172 (+760%)
Mutual labels:  logback
logback-journal
systemd journal appender for Logback
Stars: ✭ 25 (+25%)
Mutual labels:  logback
Logstash Logback Encoder
Logback JSON encoder and appenders
Stars: ✭ 1,987 (+9835%)
Mutual labels:  logback
herald
Log annotation for logging frameworks
Stars: ✭ 71 (+255%)
Mutual labels:  logback
sample-filebeat-docker-logging
Powerful Logging with Docker, FileBeat and Elasticsearch
Stars: ✭ 23 (+15%)
Mutual labels:  logback
spring-boot-microservice-eureka-zuul-docker-gateway-kubernetes
Spring Boot rest microservices using Kubernetes, ConfigMap, Eureka, Zuul / Spring Boot Gateway, Docker. Monitoring with logstash, logback, elasticsearch, kibana.
Stars: ✭ 86 (+330%)
Mutual labels:  logback
logback-mdc-ttl
logback扩展,集成transmittable-thread-local支持跨线程池的mdc跟踪
Stars: ✭ 107 (+435%)
Mutual labels:  logback

React-native-file-logger

A simple file-logger for React Native with configurable rolling policy, based on CocoaLumberjack on iOS and Logback on Android.

Features

  • 💆‍♂️ Easy to setup: Just call FileLogger.configure() and you're done. All your existing console.log/debug/... calls are automatically logged into a file
  • 🌀 File rolling: Support for time and size-based file rolling. Max number of files and size-limit can be configured. File rolling can also be disabled.
  • 📬 Email support: Logging into a file is useless if users cannot send logs back to developers. With react-native-file-logger, file logs can be sent by email without having to rely on another library
  • 🛠 TypeScript support: Being written entirely in TypeScript, react-native-file-logger has always up-to-date typings

How it works

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

Installation

npm i react-native-file-logger
npx pod-install

Getting started

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.

API

FileLogger.configure(options?): Promise

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

FileLogger.sendLogFilesByEmail(options?): Promise

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

FileLogger.enableConsoleCapture()

Enable appending messages from console calls to the current log file. It is already enabled by default when calling FileLogger.configure().

FileLogger.disableConsoleCapture()

After calling this method, console calls will no longer be written to the current log file.

FileLogger.setLogLevel(logLevel)

Change the minimum log level for file-output. The initial log level can be passed as an option to FileLogger.configure().

FileLogger.getLogLevel(): LogLevel

Return the current log level.

FileLogger.getLogFilePaths(): Promise<string[]>

Returns a promise with the absolute paths to the log files.

FileLogger.deleteLogFiles(): Promise

Remove all log files. Next console calls will be appended to a new empty log file.

Direct access API

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.

FileLogger.debug(msg)

Shortcut for FileLogger.write(LogLevel.Debug, msg).

FileLogger.info(msg)

Shortcut for FileLogger.write(LogLevel.Info, msg).

FileLogger.warn(msg)

Shortcut for FileLogger.write(LogLevel.Warning, msg).

FileLogger.error(msg)

Shortcut for FileLogger.write(LogLevel.Error, msg).

FileLogger.write(level, 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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].