mowispace/react-native-logs

limit file size

Closed this issue · 3 comments

if file exceeds 1mb make a new file dump new logs there and make that file name as latest if no of files exceed more than 5 delete oldest file is this possible with this library?

For now the fileTransport does not allow it, I mark it as a new feature to be added in the near future

Hadwz commented

I also face the same problem. Finally, I added a new FileAsyncTransport and used react-native-file-logger to solve this problem

import { FileLogger, LogLevel } from "react-native-file-logger";
import RNFS from 'react-native-fs';

import { transportFunctionType } from '../types';

FileLogger.configure({
	logLevel: LogLevel.Info,
	captureConsole: false,
	dailyRolling: true,
	maximumFileSize: 1024 * 1024, //1M
	maximumNumberOfFiles: 5,
	logsDirectory: RNFS.ExternalDirectoryPath
});

const fileAsyncTransport: transportFunctionType = props => {
	const level = props.level.severity;
	const output = `${props?.msg}\n`;

	FileLogger.write(level, output);
};

export { fileAsyncTransport };

Hope this can help you @Shirsendu-Sarkar

The library(react-native-file-logger) could be used as a reference for the new feature ? @alessandro-bottamedi

To avoid overcomplicating the fileTransport for now I have included the possibility in v 5.0.0 to have a new file every day automatically, we will evaluate in the future whether we need to add a size limit as well.