Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Send logs to Datadog from your Flutter applications with Datadog’s flutter plugin and leverage the following features:

  • Log to Datadog in JSON format natively.
  • Use default and add custom attributes to each log sent.
  • Record real client IP addresses and User-Agents.
  • Leverage optimized network usage with automatic bulk posts.

Setup

To initialize the Datadog Flutter SDK for Logs, see Setup.

Once you have initialized the Datadog Flutter SDK with a LoggingConfiguration parameter, use the default instance of logs to send logs to Datadog.

DatadogSdk.instance.logs?.debug("A debug message.");
DatadogSdk.instance.logs?.info("Some relevant information?");
DatadogSdk.instance.logs?.warn("An important warning…");
DatadogSdk.instance.logs?.error("An error was met!");

You can create additional loggers using the createLogger method:

final myLogger = DatadogSdk.instance.createLogger(
  LoggingConfiguration({
    loggerName: 'Additional logger'
  })
);

myLogger.info('Info from my additional logger.');

For more information about available logging options, see the LoggingConfiguration class documentation.

Manage tags

Tags set on loggers are local to each logger.

Add tags

Use the DdLogs.addTag method to add tags to all logs sent by a specific logger:

// This adds a "build_configuration:debug" tag
logger.addTag("build_configuration", "debug")

Remove tags

Use the DdLogs.removeTag method to remove tags from all logs sent by a specific logger:

// This removes any tag that starts with "build_configuration"
logger.removeTag("build_configuration")

For more information, see Getting Started with Tags.

Manage attributes

Attributes set on loggers are local to each logger.

Default attributes

By default, the following attributes are added to all logs sent by a logger:

  • http.useragent and its extracted device and OS properties
  • network.client.ip and its extracted geographical properties (country, city)
  • logger.version, Datadog SDK version
  • logger.thread_name, (main, background)
  • version, client’s app version extracted from either the Info.plist or application.manifest
  • environment, the environment name used to initialize the SDK

Add attributes

Use the DdLogs.addAttribute method to add a custom attribute to all logs sent by a specific logger:

logger.addAttribute("user-status", "unregistered")

The value can be most types supported by the StandardMessageCodec class.

Remove attributes

Use the DdLogs.removeAttribute method to remove a custom attribute from all logs sent by a specific logger:

// This removes the attribute "user-status" from all logs sent moving forward.
logger.removeAttribute("user-status")

Further reading

Documentation, liens et articles supplémentaires utiles: