Skip to main content

Adding Logs

As we've discussed in the Session Reporting section, Embrace will end sessions 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 log method.

let attributes = ["property_a": "value_a", "property_b": "value_b"]
Embrace.client?.log(
"Loading not finished in time.", // message
severity: .warn,
timestamp: Date.now,
attributes: attributes
)

Let's examine the method call from above to understand the arguments involved:

  1. message: The first argument is a string and represents the message itself.
  2. severity: This is the LogSeverity of the event. Typically we use this mechanism for errors and warnings and occasionally for tracing purposes, but that is better left to breadcrumbs.
  3. timestamp: This is the time that this log message should show in the timeline. If the log points to an error or warning happening prior to the current time, the timestamp for the occurrence can be added here.
  4. attributes: 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.
Limits on Log Messages
  • 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 Log Message 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.

info

For more tips on making the most of the Log Message API, checkout the Best Practices.