Files
iNaturalistReactNative/react-native-logs.config.ts
Ryan Stelly fbc7ab07bd support log apis extra property (#3331)
* functional checkpoint for logWithExtra

* remove custom log levels and infer extra arg

* extra function comment & config tidy

* Mov 730 support log extra with wrapper (#3338)

* alternative implementation for log extra w/ log wrapper

* split log enhancer from log transport implementation

* move import out of comment
2026-02-03 15:06:54 -06:00

56 lines
1.5 KiB
TypeScript

import iNatLogstashTransport, { enhanceLoggerWithExtra } from "api/log";
import RNFS from "react-native-fs";
import {
consoleTransport,
fileAsyncTransport,
logger,
} from "react-native-logs";
const fileName = "inaturalist-rn-log.txt";
const logFilePath = `${RNFS.DocumentDirectoryPath}/${fileName}`;
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,
},
};
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.
const log = enhanceLoggerWithExtra( baseLog );
const logWithoutRemote = logger.createLogger( {
...sharedConfig,
transport: [
consoleTransport,
fileAsyncTransport,
],
} );
export {
log,
logFilePath,
logWithoutRemote,
};