Access native logs from JS code
npm install react-native-app-logsThe code snippet below will intercept all logs from the main app.
import AppLogs from 'react-native-app-logs';
// ...
AppLogs.configure({ interval: 5 });
AppLogs.registerHandler({
filter: '[AppName]',
handler: ({ filter, logs }) => {
if (logs.length !== 0) {
Alert.alert(filter, logs.join('\n'));
}
},
});On iOS each process has its own logs and they live only within the process (and do not share the logs with other processes).
To intercept logs from NotificationServiceExtension you need to:
- give common app group for both
NotificationServiceExtensionand the main app; - specify
appGroupNameinAppLogs.configuremethod:
import AppLogs from 'react-native-app-logs';
AppLogs.configure({ appGroupName: 'group.applogs.example', interval: 5 });- add new Pod to your
NotificationServiceExtension:
target 'NotificationService' do
pod 'AppLogs', :path => '../../AppLogsPod/'
end- forward logs from
NotificationServiceExtensionto the main app:
import AppLogs
class NotificationService: UNNotificationServiceExtension {
let appLogs: AppLogs = .init()
deinit {
appLogs.forwardLogsTo(appGroup: "group.applogs.example")
}
}See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library