Hyperlinkv0.8.0-beta.28

Logger

Logger.consolePrettyconsteffect/Logger.ts:861
(options?: {
  readonly colors?: "auto" | boolean | undefined
  readonly stderr?: boolean | undefined
  readonly formatDate?: ((date: Date) => string) | undefined
  readonly mode?: "browser" | "tty" | "auto" | undefined
}): Logger<unknown, void>

A Logger which outputs logs in a "pretty" format and writes them to the console.

Details

For example, pretty output can render as [09:37:17.579] INFO (#1) label=0ms: hello followed by an annotation line such as key: value.

Example (Logging with pretty console output)

import { Effect, Logger } from "effect"

// Use the pretty console logger with default settings
const basicPretty = Effect.log("Hello Pretty Format").pipe(
  Effect.provide(Logger.layer([Logger.consolePretty()]))
)

// Configure pretty logger options
const customPretty = Logger.consolePretty({
  colors: true,
  stderr: false,
  mode: "tty",
  formatDate: (date) => date.toLocaleTimeString()
})

// Perfect for development environment
const developmentProgram = Effect.gen(function*() {
  yield* Effect.log("Application starting")
  yield* Effect.logInfo("Database connected")
  yield* Effect.logWarning("High memory usage detected")
}).pipe(
  Effect.annotateLogs("environment", "development"),
  Effect.withLogSpan("startup"),
  Effect.provide(Logger.layer([customPretty]))
)

// Disable colors for CI/CD environments
const ciLogger = Logger.consolePretty({ colors: false })
constructors
Source effect/Logger.ts:8618 lines
export const consolePretty: (
  options?: {
    readonly colors?: "auto" | boolean | undefined
    readonly stderr?: boolean | undefined
    readonly formatDate?: ((date: Date) => string) | undefined
    readonly mode?: "browser" | "tty" | "auto" | undefined
  }
) => Logger<unknown, void> = effect.consolePretty