Page updated Nov 11, 2023

Listen to log events

The Amplify Logger sends errors that occur when using it through Amplify Hub. To ensure that errors do not occur when logging, log messages should be validated and follow the best security practices. Additionally, you should ensure that log messages do not exceed the Amazon CloudWatch log event size of 256 KB.

You can get logging error events by listening/subscribing to the logging events from the Amplify Hub.

Amplify.Hub.subscribe(HubChannel.LOGGING, hubEvent -> { if (hubEvent.getName().equals(LoggingEventName.WRITE_LOG_FAILURE.toString())) { Log.i("LOGGING", "Failed to write logs"); } else if (hubEvent.getName().equals(LoggingEventName.FLUSH_LOG_FAILURE.toString())){ Log.i("LOGGING", "Failed to flush logs"); } } );
2 hubEvent -> {
3 if (hubEvent.getName().equals(LoggingEventName.WRITE_LOG_FAILURE.toString())) {
4 Log.i("LOGGING", "Failed to write logs");
5 } else if (hubEvent.getName().equals(LoggingEventName.FLUSH_LOG_FAILURE.toString())){
6 Log.i("LOGGING", "Failed to flush logs");
7 }
8 }
9 );