Skip to content

margelo/react-native-app-logs

Repository files navigation

react-native-app-logs

Access native logs from JS code

Installation

npm install react-native-app-logs

Usage

Basic usage

The code snippet below will intercept all logs from the main app.

import AppLogs from 'react-native-app-logs';

// ...

AppLogs.registerHandler({
  filter: '[AppName]',
  handler: ({ filter, logs }) => {
    if (logs.length !== 0) {
      Alert.alert(filter, logs.join('\n'));
    }
  },
});

Intercept logs from NotificationServiceExtension

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 NotificationServiceExtension and the main app;
  • specify appGroupName in AppLogs.configureAppGroupName method:
import AppLogs from 'react-native-app-logs';

AppLogs.configureAppGroupName('group.applogs.example');
  • add new Pod to your NotificationServiceExtension:
target 'NotificationService' do
  pod 'AppLogs', :path => '../../AppLogsPod/'
end
  • forward logs from NotificationServiceExtension to the main app:
import AppLogs

class NotificationService: UNNotificationServiceExtension {
    let appLogs: AppLogs = .init()

    deinit {
        appLogs.forwardLogsTo(appGroup: "group.applogs.example")
    }
}

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library