rn-redux-file-logger
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

REACT NATIVE REDUX FILE LOGGER

Introduction

This project exports a middleware that creates a csv log file in the android/ios file system. It has the following functionalities:

  1. Gives the developer control over what actions need to be logged inside the csv file.

  2. Can be plugged into any project with minimal setup.

  3. Provides the name of the CSV file back to the project so that the user can use it to either send to the server or email or do anything with it.

  4. Fault tolerant if any of the write calls to the file system fails.

Requirements

This project has a peer dependency of react-native-fs. This project requires the project that uses it to have this module installed for file manipulation.

Usage

This project exports these functions.

  • setupLoggingMiddleware(actionsToIgnore: string[], fileName: string) //Function to create the logging middleware.

This function as the name suggests creates a loggingMiddleware that can be plugged inside any application. It takes two arguments:

  1. actionsToIgnore: Array of actions that need to be ignored by the middleware.

  2. actionsToSkipPayload: Array of actions whose payload need to be ignored to by the middleware.

  3. fileName: Name of the file where the logs are stored. Give the file with an extension. By default name is logs.csv.

  • getFileName() //Function to get the file name and file path.

This function helps in getting the file name and the file path.

  • deleteFile() //Function to delete the logs file.

This function deletes the log file from the file system.

  • getFileContent(encoding: ('ascii' | 'base64' | 'utf8')) // Function to get the file content.

This function return a promise which has the file content in it. Encoding can be passed as an argument. utf8 by default.

  • purgeFileContent(noOfDays: number) //Function to purge the file content.

This function will purge the contents of the file based on the noOfDays that are passed. All rows that have a timepstamp less than noOfDays ago will be purged.

Contribution

If you see any bug or any feature addition, do create something in the issues section of the repository and we can take a look. Star the project if you like it :D

Package Sidebar

Install

npm i rn-redux-file-logger

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

46.2 kB

Total Files

31

Last publish

Collaborators

  • awesome31