Logger - DataDog/dd-sdk-android GitHub Wiki

class Logger

A class enabling Datadog logging features.

It allows you to create a specific context (automatic information, custom attributes, tags) that will be embedded in all logs sent through this logger.

You can have multiple loggers configured in your application, each with their own settings.

Types

Logger.Builder

Functions

addAttribute

fun addAttribute(key: String, value: Any?)

Add a custom attribute to all future logs sent by this logger.

Values can be nested up to 10 levels deep. Keys using more than 10 levels will be sanitized by SDK.

Parameters
key the key for this attribute
value the attribute value

addTag

fun addTag(key: String, value: String)

Add a tag to all future logs sent by this logger. The tag will take the form "key:value".

Tags must start with a letter and after that may contain the following characters: Alphanumerics, Underscores, Minuses, Colons, Periods, Slashes. Other special characters are converted to underscores. Tags must be lowercase, and can be at most 200 characters. If the tag you provide is longer, only the first 200 characters will be used.

Parameters
key the key for this tag
value the (non null) value of this tag
See also
documentation (https://docs.datadoghq.com/tagging/#defining-tags)

fun addTag(tag: String)

Add a tag to all future logs sent by this logger.

Tags must start with a letter and after that may contain the following characters: Alphanumerics, Underscores, Minuses, Colons, Periods, Slashes. Other special characters are converted to underscores. Tags must be lowercase, and can be at most 200 characters. If the tag you provide is longer, only the first 200 characters will be used.

Parameters
tag the (non null) tag
See also
documentation (https://docs.datadoghq.com/tagging/#defining-tags)

d

@JvmOverloads

fun d(message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends a Debug log message.

Parameters
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

e

@JvmOverloads

fun e(message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends an Error log message.

Parameters
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

i

@JvmOverloads

fun i(message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends an Info log message.

Parameters
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

log

@JvmOverloads

fun log(priority: Int, message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends a log message.

Parameters
priority the priority level (must be one of the Android Log.* constants)
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

@JvmOverloads

fun log(priority: Int, message: String, errorKind: String?, errorMessage: String?, errorStacktrace: String?, attributes: Map<String, Any?> = emptyMap())

Sends a log message with strings for error information.

This method is meant for non-native or cross platform frameworks (such as React Native or Flutter) to send error information to Datadog. Although it can be used directly, it is recommended to use other methods declared on Logger.

Parameters
priority the priority level (must be one of the Android Log.* constants)
message the message to be logged
errorKind the kind of error to be logged with the message
errorMessage the message from the error to be logged with this message
errorStacktrace the stack trace from the error to be logged with this message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

removeAttribute

fun removeAttribute(key: String)

Remove a custom attribute from all future logs sent by this logger. Previous logs won't lose the attribute value associated with this key if they were created prior to this call.

Parameters
key the key of the attribute to remove

removeTag

fun removeTag(tag: String)

Remove a tag from all future logs sent by this logger. Previous logs won't lose the this tag if they were created prior to this call.

Parameters
tag the tag to remove

removeTagsWithKey

fun removeTagsWithKey(key: String)

Remove all tags with the given key from all future logs sent by this logger. Previous logs won't lose the this tag if they were created prior to this call.

Parameters
key the key of the tags to remove

v

@JvmOverloads

fun v(message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends a VERBOSE log message.

Parameters
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

w

@JvmOverloads

fun w(message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends a Warning log message.

Parameters
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)

wtf

@JvmOverloads

fun wtf(message: String, throwable: Throwable? = null, attributes: Map<String, Any?> = emptyMap())

Sends an Assert log message.

Parameters
message the message to be logged
throwable a (nullable) throwable to be logged with the message
attributes a map of attributes to include only for this message. If an attribute with the same key already exist in this logger, it will be overridden (just for this message)