Skip to content

@repo/datadata/logger

The logger interface datadata reports through, and a console logger for the browser.

Functions

createBrowserConsoleLogger

export declare function createBrowserConsoleLogger(options?: BrowserConsoleLoggerOptions): Logger;

A Logger that writes to the console (info to console.log, the others to the method of the same name). An entry's object, when given, is passed to the console as a second argument rather than serialized. Child loggers inherit the prefix and level and add their bindings to the parent's.

Interfaces

BrowserConsoleLoggerOptions

export interface BrowserConsoleLoggerOptions

Options for createBrowserConsoleLogger.

bindings?: object;

Fields written after the prefix on every line, as key=value pairs. Default: none.

logLevel?: LogLevel;

The lowest level written; entries below it are dropped. Default: "debug".

prefix?: string;

Text written at the start of every line, e.g. "[datadata]". Default: none.

Logger

export interface Logger

The structured logger datadata writes to, in the pino calling convention: each method takes either a message string, or an object of fields followed by an optional message. A pino logger satisfies it as is; see createBrowserConsoleLogger for a console-backed one.

child: (bindings: object) => Logger;

Return a logger that adds bindings to every entry it writes.

debug: (obj: object | string, msg?: string) => void;

Log at debug level.

error: (obj: object | string, msg?: string) => void;

Log at error level.

info: (obj: object | string, msg?: string) => void;

Log at info level.

warn: (obj: object | string, msg?: string) => void;

Log at warn level.

LoggerContext

export interface LoggerContext

A context that carries the logger for the call it belongs to.

logger: Logger;

The logger for this call.

Types

LogLevel

export type LogLevel = "debug" | "info" | "warn" | "error";

A log severity, lowest first: debug, info, warn, error.