Core - v1.0.0
    Preparing search index...

    Class Logger

    Structured, level-classified logging — and nothing else.

    Each line is one JSON object emitted through the matching console.* method, so the runtime's log collector records the native level and keeps the fields searchable. Nothing here aggregates — that is TelemetrySink, a separate capability, because a sink samples at volume and is the wrong place for lines that have to be read back verbatim.

    The threshold comes from the surface registered by configure, and LOG_LEVEL in the environment overrides it per deployment, so staging can run at debug without a code change.

    Retention is the runtime's business, not this class's — it writes lines and stops there. Whether they are kept, and for how long, is a deployment setting wherever the process runs.

    const log = Logger.fromEnv(env, { service: 'ArticleService' })
    log.info('article created', { id })

    Bayu Dwiyan Satria

    1.0.0

    1.0.0

    Index
    context: LogContext

    Fields repeated on every line.

    threshold: number

    Minimum weight a line must carry to be emitted.

    • Emits a debug line.

      Parameters

      • message: string

        What happened.

      • Optionaldata: Record<string, unknown>

        Structured detail.

      Returns void

    • Writes one line through the console method matching its level.

      Parameters

      • level: LogLevel

        Severity of the line.

      • message: string

        What happened.

      • Optionaldata: Record<string, unknown>

        Structured detail.

      Returns void

    • Emits an error line.

      Parameters

      • message: string

        What happened.

      • Optionaldata: Record<string, unknown>

        Structured detail.

      Returns void

    • Builds a logger for the current environment.

      Parameters

      • env: { LOG_LEVEL?: string }

        Anything carrying an optional LOG_LEVEL. Tolerates null.

      • context: LogContext = {}

        Fields to repeat on every line.

      Returns Logger

      A logger honouring the configured (or LOG_LEVEL) threshold.

      The parameter is structural rather than a named environment type. All this needs is a possible LOG_LEVEL, so asking for exactly that keeps the kernel free of any platform's environment shape — a runtime's Env object, a process.env, or a bare object literal all satisfy it.

    • Emits an info line.

      Parameters

      • message: string

        What happened.

      • Optionaldata: Record<string, unknown>

        Structured detail.

      Returns void

    • Parses a level name, ignoring anything unrecognised.

      Parameters

      • Optionalvalue: string

        The candidate level name.

      Returns LogLevel

      The level, or null when the value is not one.

    • Makes a data payload serialisable — Error values in particular, which JSON.stringify would otherwise flatten to {}.

      Parameters

      • data: Record<string, unknown>

        The payload to convert.

      Returns Record<string, unknown>

      The payload with errors expanded to message and stack.

    • Emits a warn line.

      Parameters

      • message: string

        What happened.

      • Optionaldata: Record<string, unknown>

        Structured detail.

      Returns void