PlatformLogger overview
Added in v1.0.0
Table of contents
utils
toFile
Create a Logger from another string Logger that writes to the specified file.
Signature
export declare const toFile: {
(
path: string,
options?: (OpenFileOptions & { readonly batchWindow?: DurationInput | undefined }) | undefined
): <Message>(
self: Logger.Logger<Message, string>
) => Effect<Logger.Logger<Message, void>, PlatformError, Scope | FileSystem>
<Message>(
self: Logger.Logger<Message, string>,
path: string,
options?: (OpenFileOptions & { readonly batchWindow?: DurationInput | undefined }) | undefined
): Effect<Logger.Logger<Message, void>, PlatformError, Scope | FileSystem>
}
Example
import { PlatformLogger } from "@effect/platform"
import { NodeFileSystem, NodeRuntime } from "@effect/platform-node"
import { Effect, Layer, Logger } from "effect"
const fileLogger = Logger.logfmtLogger.pipe(PlatformLogger.toFile("/tmp/log.txt"))
const LoggerLive = Logger.replaceScoped(Logger.defaultLogger, fileLogger).pipe(Layer.provide(NodeFileSystem.layer))
Effect.log("a").pipe(
Effect.zipRight(Effect.log("b")),
Effect.zipRight(Effect.log("c")),
Effect.provide(LoggerLive),
NodeRuntime.runMain
)
Added in v1.0.0