Documentation
    Preparing search index...

    Public API for the Logs browser SDK.

    See Browser Log Collection for further information.

    interface LogsGlobal {
        clearAccount: () => void;
        clearGlobalContext: () => void;
        clearUser: () => void;
        createLogger: (name: string, conf?: LoggerConfiguration) => Logger;
        getAccount: () => Context;
        getGlobalContext: () => Context;
        getInitConfiguration: () => undefined | LogsInitConfiguration;
        getLogger: (name: string) => undefined | Logger;
        getUser: () => Context;
        init: (initConfiguration: LogsInitConfiguration) => void;
        logger: Logger;
        onReady: (callback: () => void) => void;
        removeAccountProperty: (key: string) => void;
        removeGlobalContextProperty: (key: any) => void;
        removeUserProperty: (key: any) => void;
        setAccount: (newAccount: Account) => void;
        setAccountProperty: (key: string, property: any) => void;
        setGlobalContext: (context: any) => void;
        setGlobalContextProperty: (key: any, value: any) => void;
        setTrackingConsent: (trackingConsent: TrackingConsent) => void;
        setUserProperty: (key: any, property: any) => void;
        version: string;
        setUser(newUser: User & { id: string }): void;
        setUser(newUser: User): void;
    }

    Hierarchy (View Summary)

    Index

    Account

    clearAccount: () => void

    Clear all account information

    Type declaration

      • (): void
      • Returns void

        Clear all account information

    getAccount: () => Context

    Get account information

    Type declaration

    removeAccountProperty: (key: string) => void

    Remove an account property

    Type declaration

      • (key: string): void
      • Parameters

        • key: string

          Key of the property to remove

        Returns void

    setAccount: (newAccount: Account) => void

    Set account information to all events, stored in @account

    Type declaration

      • (newAccount: Account): void
      • Parameters

        • newAccount: Account

          Account information

        Returns void

    setAccountProperty: (key: string, property: any) => void

    Set or update the account property, stored in @account.<key>

    Type declaration

      • (key: string, property: any): void
      • Parameters

        • key: string

          Key of the property

        • property: any

          Value of the property

        Returns void

    Global Context

    clearGlobalContext: () => void

    Clear the global context

    See Global context for further information.

    getGlobalContext: () => Context

    Get the global Context

    See Global context for further information.

    removeGlobalContextProperty: (key: any) => void

    Remove a global context property

    See Global context for further information.

    setGlobalContext: (context: any) => void

    Set the global context information to all events, stored in @context See Global context for further information.

    Type declaration

      • (context: any): void
      • Parameters

        • context: any

          Global context

        Returns void

    setGlobalContextProperty: (key: any, value: any) => void

    Set or update a global context property, stored in @context.<key>

    See Global context for further information.

    Type declaration

      • (key: any, value: any): void
      • Parameters

        • key: any

          Key of the property

        • value: any

          Value of the property

        Returns void

    Init

    getInitConfiguration: () => undefined | LogsInitConfiguration

    Get the init configuration

    Type declaration

    init: (initConfiguration: LogsInitConfiguration) => void

    Init the Logs browser SDK.

    See Browser Log Collection for further information.

    Type declaration

    Logger

    createLogger: (name: string, conf?: LoggerConfiguration) => Logger

    The Datadog browser logs SDK contains a default logger DD_LOGS.logger, but this API allows to create different ones.

    See Define multiple loggers for further information.

    Type declaration

    getLogger: (name: string) => undefined | Logger

    Get a logger

    See Define multiple loggers for further information.

    Type declaration

      • (name: string): undefined | Logger
      • Parameters

        • name: string

          Name of the logger

        Returns undefined | Logger

    logger: Logger

    The default logger

    Other

    onReady: (callback: () => void) => void

    For CDN async setup: Early RUM API calls must be wrapped in the window.DD_RUM.onReady() callback. This ensures the code only gets executed once the SDK is properly loaded.

    See CDN async setup for further information.

    version: string

    Version of the Logs browser SDK

    Tracking Consent

    setTrackingConsent: (trackingConsent: TrackingConsent) => void

    Set the tracking consent of the current user.

    Logs will be sent only if it is set to "granted". This value won't be stored by the library across page loads: you will need to call this method or set the appropriate trackingConsent field in the init() method at each page load.

    If this method is called before the init() method, the provided value will take precedence over the one provided as initialization parameter.

    See User tracking consent for further information.

    Type declaration

    User

    clearUser: () => void

    Clear all user information

    See User session for further information.

    getUser: () => Context

    Get user information

    See User session for further information.

    Type declaration

    removeUserProperty: (key: any) => void

    Remove a user property

    Type declaration

      • (key: any): void
      • Parameters

        • key: any

          Key of the property to remove

        Returns void

    User session for further information.

    setUserProperty: (key: any, property: any) => void

    Set or update the user property, stored in @usr.<key>

    See User session for further information.

    Type declaration

      • (key: any, property: any): void
      • Parameters

        • key: any

          Key of the property

        • property: any

          Value of the property

        Returns void