(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 })export const 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>
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 })
consolePretty: (
options: | {
readonly colors?:
| "auto"
| boolean
| undefined
readonly stderr?: boolean | undefined
readonly formatDate?:
| ((date: Date) => string)
| undefined
readonly mode?:
| "browser"
| "tty"
| "auto"
| undefined
}
| undefined
options?: {
readonly colors?: boolean | "auto" | undefinedcolors?: "auto" | boolean | undefined
readonly stderr?: boolean | undefinedstderr?: boolean | undefined
readonly formatDate?: ((date: Date) => string) | undefinedformatDate?: ((date: Datedate: Date) => string) | undefined
readonly mode?: "auto" | "browser" | "tty" | undefinedmode?: "browser" | "tty" | "auto" | undefined
}
) => interface Logger<in Message, out Output>A logger that transforms a runtime log event into an output value.
Details
The runtime calls log with the message, level, cause, fiber, and timestamp
for each log event. Use Logger.layer to install one or more loggers for an
effect.
Example (Creating custom loggers)
import { Effect, Logger } from "effect"
// Create a custom logger that accepts unknown messages and returns void
const stringLogger = Logger.make<unknown, void>((options) => {
console.log(`[${options.logLevel}] ${options.message}`)
})
// Create a logger that accepts any message type and returns a formatted string
const formattedLogger = Logger.make<unknown, string>((options) =>
`${options.date.toISOString()} [${options.logLevel}] ${options.message}`
)
// Use the logger in an Effect program
const program = Effect.log("Hello World").pipe(
Effect.provide(Logger.layer([stringLogger]))
)
Logger<unknown, void> = import effecteffect.const consolePretty: (options?: {
readonly colors?: "auto" | boolean | undefined
readonly formatDate?:
| ((date: Date) => string)
| undefined
readonly mode?:
| "browser"
| "tty"
| "auto"
| undefined
}) => Logger<unknown, void>
consolePretty