Skip to content

Instantly share code, notes, and snippets.

@brokenthorn
Last active February 11, 2025 19:54
Show Gist options
  • Save brokenthorn/ae534ae08f6956254f443a7960b1a925 to your computer and use it in GitHub Desktop.
Save brokenthorn/ae534ae08f6956254f443a7960b1a925 to your computer and use it in GitHub Desktop.
Effect: Clear all Loggers
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