mowispace/react-native-logs

In transportOptions I'm Not able generate logs.txt file

Closed this issue · 7 comments

Hi, I'm not able to see the newly generated logs.txt file it's not generated but In the console log Logs are visible I have tried both FS RNFS and FileSystem.

`import { logger, fileAsyncTransport } from 'react-native-logs';
import RNFS from 'react-native-fs';
import FileSystem from 'react-native-fs';

const config = {
transport: fileAsyncTransport,
transportOptions: {
FS: FileSystem,
fileName: logs.txt,
},
};
var log = logger.createLogger(config);
export const LoggerUI = () => {
log.debug('Debug message');
return <Text style={{ fontSize: 50 }}> Test logs;
};
`

I'm experiencing the same issue using the configuration from the docs.

nvm, I just lack understanding of android in general.
The file does get created, just not in a place when the user can access it from the gui.
@codemap01 in case of RNFS the default path is /data/user/0/com.yourapp/files. You can access it via android studio > View > Tool Windows > Device File Explorer

@Rankarusu Thanks, I'm able to see the logs.txt file in Android studio Device File Explorer but In my real (physical )device I'm not able to see this logs.txt file so how can able to see this file in my device?

@codemap01 search in Android folder of File Manager or try changing the path.

@shahanshah87 I have searched all hidden files in the Android folder of File Manager but it's not visible to me so how can I change my path? can you share with code example.

console.log(RNFS.CachesDirectoryPath);
console.log(RNFS.ExternalCachesDirectoryPath);
console.log(RNFS.DownloadDirectoryPath);
console.log(RNFS.DocumentDirectoryPath);
console.log(RNFS.ExternalDirectoryPath);
console.log(RNFS.ExternalStorageDirectoryPath);
console.log(RNFS.TemporaryDirectoryPath);

Output:

 LOG  /data/user/0/com.seedao.app/cache
 LOG  /storage/emulated/0/Android/data/com.seedao.app/cache
 LOG  /storage/emulated/0/Download
 LOG  /data/user/0/com.seedao.app/files
 LOG  /storage/emulated/0/Android/data/com.seedao.app/files
 LOG  /storage/emulated/0
 LOG  /data/user/0/com.seedao.app/cache

So RNFS.ExternalCachesDirectoryPath is the best choose!

Following is my code:

import {logger, consoleTransport, fileAsyncTransport} from 'react-native-logs';
import RNFS from 'react-native-fs';

const config = {
  transport: __DEV__ ? consoleTransport : fileAsyncTransport,
  severity: __DEV__ ? 'debug' : 'error',
  transportOptions: {
    colors: {
      info: 'blueBright',
      warn: 'yellowBright',
      error: 'redBright',
    },
    FS: RNFS,
    filePath: RNFS.ExternalCachesDirectoryPath,
    fileName: 'logs_{date-today}.log',
  },
};

const log = logger.createLogger(config);

export {log};

so I can find the log files in my FileManger easily.

I added a demo file (demo/ComponentReadLogsRN.tsx) for implementing a simple component to display log files in a React Native app, it might be helpful for you.