forked from NWACus/avy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.ts
48 lines (40 loc) · 1.37 KB
/
logger.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {StreamOptions, createLogger, stdSerializers} from 'browser-bunyan';
import Constants from 'expo-constants';
import * as FileSystem from 'expo-file-system';
import * as Updates from 'expo-updates';
import {ConsoleFormattedStream} from 'logging/consoleFormattedStream';
import {FileStream} from 'logging/fileStream';
import {LogBox} from 'react-native';
// react-native-logs always logs to FS.documentDirectory
const LOG_PATH = 'log.json';
export const logFilePath = String(FileSystem.documentDirectory) + LOG_PATH;
// Always delete the log file on startup
if (process.env.NODE_ENV !== 'test') {
void (async () => {
await FileSystem.deleteAsync(logFilePath, {idempotent: true});
})();
}
if (process.env.EXPO_PUBLIC_DISABLE_LOGBOX) {
LogBox.ignoreAllLogs(true);
}
const defaultLogLevel = process.env.NODE_ENV === 'test' ? 'WARN' : 'INFO';
const streams: StreamOptions[] = [];
// In development mode, log to the console
if (Updates.channel === 'development') {
streams.push({
level: (Constants.expoConfig?.extra?.log_level as string) ?? defaultLogLevel,
stream: new ConsoleFormattedStream(),
});
}
// Always log to file, except for when we're in test
if (process.env.NODE_ENV === 'test') {
streams.push({
level: 'INFO',
stream: new FileStream(logFilePath),
});
}
export const logger = createLogger({
name: 'avy',
serializers: stdSerializers,
streams,
});