Adding Logs
As we've discussed in the Session Reporting section, Embrace will end and attempt to upload the current session when the app is sent to the background.
However, some situations might require immediate feedback, such as hunting an especially difficult bug, troubleshooting on behalf of high-value users, or monitoring a new version rollout.
You can leverage the log message API for this.
Using the Log Message API
You can log a message immediately by calling the logMessage
method.
- Swift
- Objective-C
let properties = ["property_a": "value_a", "property_b": "value_b"]
Embrace.sharedInstance().logMessage("Loading not finished in time.", with: .error, properties: properties)
NSDictionary *properties = @{@"property_a": @"value_a", @"property_b": @"value_b"};
[[Embrace sharedInstance] logMessage:@"Loading not finished in time." withSeverity:EMBSeverityError properties:properties];
Let's examine the method call from above to understand the arguments involved:
- logMessage: The first argument is a string and represents the message itself.
- with: This is the severity of the event. Typically we use this mechanism for errors and warnings and occasionally for tracing purposes, but that is better left to breadcrumbs.
- properties: This is a dictionary of key-value pairs. When logging an event, break out any details into this dictionary and you will be able to categorize and filter on those values.
- The maximum length for a log message is 128 characters. Messages are truncated if they exceed the limit.
- Properties are limited to 10 per log
- Property keys have a limit of 128 characters.
- Property values have a limit of 256 characters.
Being Alerted on Logs
Once you start using our alerting feature you can also configure how these are handled on the backend. Using the Embrace Dashboard, you can configure email alerts to be sent to your team when certain thresholds are met with logEvents. For example, if you have a steady rate of 1% for a given logEvent, then you can set a threshold so that if it rises in a sustained way you get an email sent directly to you.
Best Practices
Embrace's logMessage API is immediate mode. A call to this API results in a networking call between your app and Embrace's servers immediately. This can have a negative effect on your application's performance or battery life when over-used. It can also be an invaluable tool for getting information about your application quickly.
For more tips on making the most of the Log Message API, checkout the Best Practices.
Congratulations! By this point, you should have a solid integration. Continue to the Next Steps page to wrap up your integration.