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.

Accessors

  • get emojiLogLevelHeadingsEnabled(): boolean
  • Represents whether or not emojis should be used as the log level indicator in the logs.

    Returns boolean

  • set emojiLogLevelHeadingsEnabled(emojiLogLevelHeadingsEnabled): void
  • Represents whether or not emojis should be used as the log level indicator in the logs.

    Parameters

    • emojiLogLevelHeadingsEnabled: boolean

    Returns void

  • 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): 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): 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).

    Ditto limits the amount of logs it retains on disk to 15 MB and a maximum age of three 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.

    Throws

    TypeError if path is not a string.

    Throws

    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.

    Throws

    DittoError sdk/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

    • Optional callback: CustomLogCallback

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

    Returns Promise<void>

    Throws

    if callback is not a function or undefined.

    Throws

    if called in a React Native environment.

  • On Node, 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). In the browser, this method has no effect.

    Parameters

    • path: string

      can be null, in which case the current logging file, if any, is unregistered, otherwise, the file path must be within an already existing directory.

    Returns void

  • Convenience method, takes the path part of the URL and calls setLogFile() with it.

    Parameters

    • url: URL

    Returns void

  • 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