mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-04-18 05:49:24 -04:00
* Update package.json * Update package-lock.json * Update Podfile.lock * Update PrivacyInfo.xcprivacy * Update react-native-logs.config.ts * Update paths.ts * Update savePhotoToDocumentsDirectory.ts * Update useAppSize.ts * Update installData.ts * Update mlModel.ts * Update storageMetrics.ts * Update removeAllFilesFromDirectory.ts * Update util.ts * Update removeSyncedFilesFromDirectory.ts * Update contexts.ts * Update index.ts * Update Photo.ts * Update Sound.js * Update logManagementHelpers.ts * Update PhotoLibrary.tsx * Update flattenUploadParams.ts * Update shouldFetchObservationLocation.ts * Update Developer.tsx * Update vision-camera.js * Update sentinelFiles.ts * Move mock * Switch to unlink util
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import * as RNFS from "@dr.pogodin/react-native-fs";
|
|
import iNatLogstashTransport, { enhanceLoggerWithExtra } from "api/log";
|
|
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,
|
|
],
|
|
} );
|