Giter VIP home page Giter VIP logo

Comments (2)

charlesmchen-replit avatar charlesmchen-replit commented on July 17, 2024

It might be nice to add a means to flush logs to disk.

from react-native-logs.

alessandro-bottamedi avatar alessandro-bottamedi commented on July 17, 2024

I believe that it's better to perform all these tasks before the initialization of react-native-logs, also for performance reasons. It's better to avoid putting them in the fileAsyncTransport, which is executed every time an attempt is made to write a log. For example, we could compress the last log file upon opening the app:

import { zip } from 'react-native-zip-archive'
import RNFS from 'react-native-fs'
import { logger, fileAsyncTransport } from "react-native-logs"

let date = new Date();
date.setDate(date.getDate() - 1);

let d = date.getDate();
let m = date.getMonth() + 1;
let y = date.getFullYear();

const targetPath = `${DocumentDirectoryPath}/logs_${d}-${m}-${y}.zip`
const sourcePath = `${DocumentDirectoryPath}/logs_${d}-${m}-${y}`

RNFS.exists(sourcePath)
  .then((exists) => {
    if (exists) {
      zip(sourcePath, targetPath)
      .then((path) => {
        RNFS.unlink(filePath)
      })
      .catch((error) => {
        console.error(error)
      })
  })
  .catch((error) => {
    console.error(error);
  });


const config = {
  severity: "debug",
  transport: fileAsyncTransport,
  transportOptions: {
    FS: RNFS,
    fileName: `logs_{date-today}`, // Create a new file every day
  },
};

I haven't tested this code; there might be errors...

from react-native-logs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.