Last active
February 11, 2025 19:54
-
-
Save brokenthorn/ae534ae08f6956254f443a7960b1a925 to your computer and use it in GitHub Desktop.
Effect: Clear all Loggers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Effect, FiberRef, HashSet, Layer } from "effect"; | |
/** | |
* A Layer that clears all existing `Logger`s. | |
* | |
* @example | |
* import { NodeRuntime } from "@effect/platform-node" | |
* import { Effect, FiberRef, HashSet, Layer, Logger } from "effect" | |
* | |
* const MainLayer = Logger.json.pipe(Layer.provide(ClearAllLoggersLayer)) | |
* // const MainLayer = Layer.provide(ClearAllLoggersLayer)(Logger.json) | |
* | |
* const program = Effect.gen(function*() { | |
* yield* Effect.log("OK") | |
* }) | |
* | |
* NodeRuntime.runMain( | |
* program.pipe(Effect.provide(MainLayer)) | |
* ) | |
*/ | |
export const ClearAllLoggersLayer = Layer.scopedDiscard( | |
Effect.locallyScoped(FiberRef.currentLoggers, HashSet.empty()), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment