Hyperlinkv0.8.0-beta.28

Logger

Logger.formatLogFmtconsteffect/Logger.ts:583
Logger<unknown, string>

A Logger which outputs logs using the logfmt style.

Details

For example, a logfmt entry is rendered as timestamp=2025-01-03T14:22:47.570Z level=INFO fiber=#1 message=hello.

Example (Formatting logs as logfmt)

import { Effect, Logger } from "effect"

// Use the logfmt format logger
const logfmtLoggerProgram = Effect.log("Hello LogFmt Format").pipe(
  Effect.provide(Logger.layer([Logger.formatLogFmt]))
)

// Perfect for structured logging systems
const structuredProgram = Effect.gen(function*() {
  yield* Effect.log("User login", { userId: 123, method: "OAuth" })
  yield* Effect.logInfo("Request processed", {
    duration: 45,
    status: "success"
  })
}).pipe(
  Effect.provide(Logger.layer([Logger.withConsoleLog(Logger.formatLogFmt)]))
)

// Good for log aggregation systems like Splunk, ELK
const productionLogger = Logger.formatLogFmt
constructors
Source effect/Logger.ts:5831 lines
export const formatLogFmt = effect.loggerMake(format(JSON.stringify, 0))
Referenced by 1 symbols