Amplify has re-imagined the way frontend developers build fullstack applications. Develop and deploy without the hassle.

Page updated Feb 21, 2024

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.

import Amplify
// Assumes `unsubscribeToken` is declared as an instance variable in your view
unsubscribeToken = Amplify.Hub.listen(to: .logging) { payload in
switch payload.eventName {
case HubPayload.EventName.Logging.writeLogFailure:
print("Error writing to local log")
case HubPayload.EventName.Logging.flushLogFailure:
print("Error sending log events to CloudWatch")
default:
break
}
}
import Amplify
// Assumes `sink` is declared as an instance variable in your code
sink = Amplify.Hub
.publisher(for: .logging)
.sink { payload in
switch payload.eventName {
case HubPayload.EventName.Logging.writeLogFailure:
print("Error writing to local log")
case HubPayload.EventName.Logging.flushLogFailure:
print("Error sending log events to CloudWatch")
default:
break
}
}