Add logs
Some situations require instant feedback, such as hunting an especially difficult bug, troubleshooting on behalf of high-value users, or monitoring a new version rollout. You can use the log message API for this.
Use the log message API
Log a message immediately by calling any of the log functions, like logError:
import 'package:embrace/embrace.dart';
Embrace.instance.logError(
'Loading not finished on time',
properties: {
'propertyA': 'valueA',
'propertyB': 'valueB',
}
);
Here's a breakdown of the arguments passed to the logError method (the only required argument is the message):
- message: The string message itself. Keep it short yet informative.
- properties: A map of key-value pairs you can use to categorize and filter log messages.
You can adjust the severity of the log by calling the logWarning or logInfo methods:
Embrace.instance.logWarning("User attempted expired credit card", props);
Embrace.instance.logInfo("User has entered checkout flow");
- The maximum length for a log message is 4000 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.
Set up alerts on logs
Once you start using the alerting feature, you can 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 log events. For example, if you have a steady rate of 1% for a given log event, you could set that as a threshold and receive an email if the rate rises beyond that in a sustained way.
Best practices
Logging a message using the Log Message API makes a network request immediately. Sending too many logs can easily impact application performance or battery life.
For more tips on making the most of the Log Message API, check out the Dashboard section on Logs.