Ditto JS SDK v5.0.0
    Preparing search index...

    Class Logger

    Class with static methods to customize the logging behavior from Ditto and log messages with the Ditto logging infrastructure.

    Currently, Ditto uses the persistence directory of the Ditto instance that was most recently created to store a limited amount of logs. Ditto may continue writing logs to a persistence directory even after the associated Ditto instance is closed. If this is a concern, consider either disabling logging by setting Logger.enabled to false, or instantiating a new Ditto instance. After either of these actions, it is safe to remove the persistence directory. Please refer to exportToFile() for further details on locally collected logs.

    Index

    Accessors

    • get enabled(): boolean

      Whether the logger is currently enabled.

      Logs exported through exportToFile() are not affected by this setting and will also include logs emitted while enabled is false.

      Returns boolean

    • set enabled(enabled: boolean): void

      Enables or disables logging.

      Parameters

      • enabled: boolean

      Returns void

    • get logFile(): string

      Registers a file path where logs will be written to, whenever Ditto wants to issue a log (on top of emitting the log to the console).

      Returns string

    • get minimumLogLevel(): LogLevel

      The minimum log level at which logs will be logged.

      For example if this is set to Warning, then only logs that are logged with the Warning or Error log levels will be shown.

      Logs exported through exportToFile() are not affected by this setting and include all logs at Debug level and above.

      Returns LogLevel

    • set minimumLogLevel(minimumLogLevel: LogLevel): void

      The minimum log level at which logs will be logged.

      For example if this is set to Warning, then only logs that are logged with the Warning or Error log levels will be shown.

      Parameters

      Returns void

    Methods

    • Convenience method, same as calling log() with LogLevel Debug.

      Parameters

      • message: string

      Returns void

    • Convenience method, same as calling log() with LogLevel Error.

      Parameters

      • message: string

      Returns void

    • Exports collected logs to a compressed and JSON-encoded file on the local file system.

      Ditto's logger locally collects a limited amount of logs at Debug level and above, periodically discarding older logs. This internal logger is always enabled and works independently of the Logger.enabled setting and the configured Logger.minimumLogLevel. Its logs can be requested and downloaded from any peer that is active in a Ditto app using the portal's device dashboard. This method provides an alternative way of accessing those logs by exporting them to the local file system.

      The logs will be written as a gzip compressed file at the path specified by the path parameter. When uncompressed, the file contains one JSON value per line with the oldest entry on the first line (JSON lines format).

      By default, Ditto limits the amount of logs it retains on disk to 15 MB and a maximum age of 15 days. Older logs are periodically discarded once one of these limits is reached.

      This method currently only exports logs from the most recently created Ditto instance, even when multiple instances are running in the same process.

      Not supported in browser environments.

      Parameters

      • path: string

        The path of the file to write the logs to. The file must not already exist, and the containing directory must exist. It is recommended for the path to have the .jsonl.gz file extension but Ditto won't enforce it, nor correct it.

      Returns Promise<number>

      The number of bytes written to the file.

      TypeError if path is not a string.

      DittoError io/* when the file cannot be written to disk. Prevent this by ensuring that no file exists at the provided path, all parent directories exists, sufficient permissions are granted, and that the disk is not full.

      DittoError unsupported when called in a browser environment.

    • Convenience method, same as calling log() with LogLevel Info.

      Parameters

      • message: string

      Returns void

    • Registers a custom callback that will be called to report each log entry.

      Parameters

      • Optionalcallback: CustomLogCallback

        function called for each log entry. undefined will unregister any previous callback and stop reporting log entries through callbacks.

      Returns Promise<void>

      if callback is not a function or undefined.

      when called in a React Native environment.

    • Convenience method, same as calling log() with LogLevel Verbose.

      Parameters

      • message: string

      Returns void

    • Convenience method, same as calling log() with LogLevel Warning.

      Parameters

      • message: string

      Returns void