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.

1Amplify.Hub.subscribe(HubChannel.LOGGING,
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 );
1Amplify.Hub.subscribe(
2 HubChannel.LOGGING
3) { hubEvent: HubEvent<*> ->
4 if (hubEvent.name == LoggingEventName.WRITE_LOG_FAILURE.toString()) {
5 Log.i("LOGGING", "Failed to write logs")
6 } else if (hubEvent.name == LoggingEventName.FLUSH_LOG_FAILURE.toString()) {
7 Log.i("LOGGING", "Failed to flush logs")
8 }
9}
1RxAmplify.Hub.on(HubChannel.LOGGING)
2.map(HubEvent::getName)
3.subscribe(name -> {
4 if (name.equals(LoggingEventName.WRITE_LOG_FAILURE.toString())) {
5 Log.i("LOGGING", "Failed to write logs");
6 return;
7 } else if (name.equals(LoggingEventName.FLUSH_LOG_FAILURE.toString())) {
8 Log.i("LOGGING", "Failed to flush logs");
9 return;
10 }
11});