Files
iNaturalistReactNative/react-native-logs.config.ts
Ryan Stelly 793c6bb215 MOB-992 start using rolling daily logs instead of a single append-only (#3433)
* extract non-react log helpers out of custom hook

* git mv useLogs to more appropriate name / location

* update logmgmt imports, clean up getLogs

* git mv Log.js Log.tsx

* remove sharing functionality from log preview screen

* reorganize debug screen w/ headers

* refactor all Debug sections for consistency

* add rolling log config, switch existing logmgmt to 'legacy' var

* factor path out of share/email for legacy wrappers

* add 'legacy' log category in prep for showing new logs

* add legacy flag to log preview screen params

* add useLogPreview for Log screen supporting legacy and aggregated recent rolling logs

* actually support sharing the new logs w/ a tmp file of concatenated recent logs

* delete low value developer screen test

* fix double reverse and handle bad filename
2026-03-17 16:19:18 -05:00

64 lines
2.1 KiB
TypeScript

import iNatLogstashTransport, { enhanceLoggerWithExtra } from "api/log";
import RNFS from "react-native-fs";
import {
consoleTransport,
fileAsyncTransport,
logger,
} from "react-native-logs";
// before introducing {date-today} rolling logs, we had a single logfile
// we still want to allow users to retreive this logfile but heads up, they may be _big_ like 100MB
const legacyLogfileName = "inaturalist-rn-log.txt";
export const legacyLogfilePath = `${RNFS.DocumentDirectoryPath}/${legacyLogfileName}`;
export const logFileNamePrefix = "inaturalist-rn-log";
const logFileName = `${logFileNamePrefix}.{date-today}.txt`;
export const logFileDirectory = `${RNFS.DocumentDirectoryPath}/logs`;
RNFS.exists( logFileDirectory ).then( exists => ( exists
? Promise.resolve()
: RNFS.mkdir( logFileDirectory ) ) );
const sharedConfig = {
dateFormat: "iso",
// eslint-disable-next-line no-undef
severity: __DEV__
? "debug"
: "info",
transportOptions: {
// TS TODO: this type is "fixed" in next minor version bump of rn-logs
// https://github.com/mowispace/react-native-logs/commit/df7444279525b7fa88c1509655d8fb6e7582b9cb#diff-c7efff41b2f47cae54e9c83fbe3156db0f1ef1bf405e0750c94d6a10bb74e5a0L110
// eslint-disable-next-line @typescript-eslint/no-explicit-any
FS: RNFS as any,
fileName: logFileName,
filePath: logFileDirectory,
// logname.{date-today}.txt => logname.2026-3-11.txt (note, no padded 0)
fileNameDateType: "iso" as const,
},
};
const baseLog = logger.createLogger( {
...sharedConfig,
transport: [
consoleTransport,
fileAsyncTransport,
iNatLogstashTransport,
],
} );
// given the general react-native-logs logger with debug(), warn(), etx,
// add wrappers for debugWithExtra(), etc which provides more intentional
// log interfaces for the iNatLogstash API `extra` proprty. `iNatLogstashTransport`
// handles this extra data specially while other transports treat it as any other normal
// log param.
export const log = enhanceLoggerWithExtra( baseLog );
export const logWithoutRemote = logger.createLogger( {
...sharedConfig,
transport: [
consoleTransport,
fileAsyncTransport,
],
} );