Skip to content

Logit API Reference

API At a Glance

SymbolPurposeExecution modeCommon gotcha
createLogger()Create scoped logger instancesSyncSet logLevel explicitly in production environments
Logit.scope()Create namespaced logger childrenSyncNamespace too broad makes filtering noisy
logger.time()Measure async/sync execution timeAsyncWrap awaited operations to keep timing accurate

Package Entry Point

ImportPurpose
@vielzeug/logitMain API (createLogger, Logit) and exported logger types

createLogger(initial?)

Creates an isolated logger instance.

Signature: createLogger(initial?: LogitOptions | string): Logger

  • string shorthand sets namespace (createLogger('api')).
  • Instances do not share mutable config.

Logit Object

Logit is the pre-created default logger instance (createLogger() called once).

Core members:

  • Logging: debug, trace, info, success, warn, error
  • Utilities: assert, table, time, group
  • Composition: scope(name), child(overrides?)
  • Configuration: setConfig(opts), config, enabled(level)

Behavior notes:

  • setConfig() applies partial updates and returns the same logger.
  • config returns a snapshot copy (remote is also copied).
  • enabled() checks against current level threshold.
  • time() and group() always call timeEnd/groupEnd even on throw/reject.

Types

LogType

'debug' | 'trace' | 'info' | 'success' | 'warn' | 'error'

LogLevel

LogType | 'off'

Variant

'text' | 'symbol' | 'icon'

RemoteLogData

FieldTypeDescription
argsunknown[]Original user log args
env'production' | 'development'Runtime env marker
namespacestring?Effective namespace
timestampstring?ISO timestamp when enabled

RemoteHandler

(type: LogType, data: RemoteLogData) => void

RemoteOptions

FieldTypeDescription
handlerRemoteHandler?Async-safe remote sink callback
logLevelLogLevel?Remote forwarding threshold

LogitOptions

FieldTypeDescription
logLevelLogLevel?Console threshold
variantVariant?Badge style
timestampboolean?Include timestamp
environmentboolean?Include env badge
namespacestring?Namespace prefix
remoteRemoteOptions?Remote forwarding config

LogitConfig

Resolved config shape exposed via logger.config:

Omit<Required<LogitOptions>, 'remote'> & { remote: { handler?: RemoteHandler; logLevel: LogLevel } }

Logger

Logger methods:

  • debug(...args), trace(...args), info(...args), success(...args), warn(...args), error(...args)
  • assert(condition, ...args)
  • table(data, properties?)
  • time(label, fn)
  • group(label, fn, collapsed?)
  • scope(name)
  • child(overrides?)
  • setConfig(opts)
  • enabled(level)
  • config (readonly snapshot)