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.formatLogFmtconstructors
Source effect/Logger.ts:5831 lines
export const const formatLogFmt: Logger<
unknown,
string
>
const formatLogFmt: {
log: (options: Options<unknown>) => string;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
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
formatLogFmt = import effecteffect.const loggerMake: <Message, Output>(
log: (
options: Logger.Options<Message>
) => Output
) => Logger.Logger<Message, Output>
loggerMake(const format: (
quoteValue: (s: string) => string,
space?: number | string | undefined
) => ({
cause,
date,
fiber,
logLevel,
message,
}: Options<unknown>) => string
Used by both
formatSimple
and
formatLogFmt
to render a log
message.
format(var JSON: JSONAn intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.JSON.stringify(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string (+1 overload)Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
stringify, 0))Referenced by 1 symbols