Context.Reference<ReadonlySet<Logger<unknown, any>>>Context reference for the set of loggers currently used by Effect logging operations.
When to use
Use to inspect or provide the complete set of loggers used by Effect logging in the current context.
Details
The default set contains the built-in default logger and tracer logger.
Providing this reference changes which Logger instances receive log entries
in the current context.
export const const CurrentLoggers: Context.Reference<
ReadonlySet<Logger<unknown, any>>
>
const CurrentLoggers: {
key: string;
Service: {
forEach: (callbackfn: (value: Logger<unknown, any>, value2: Logger<unknown, any>, set: ReadonlySet<Logger<unknown, any>>) => void, thisArg?: any) => void;
has: (value: Logger<unknown, any>) => boolean;
size: number;
entries: () => SetIterator<[Logger<unknown, any>, Logger<unknown, any>]>;
keys: () => SetIterator<Logger<unknown, any>>;
values: () => SetIterator<Logger<unknown, any>>;
union: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any> | U>;
intersection: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any> & U>;
difference: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any>>;
symmetricDifference: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any> | U>;
isSubsetOf: (other: ReadonlySetLike<unknown>) => boolean;
isSupersetOf: (other: ReadonlySetLike<unknown>) => boolean;
isDisjointFrom: (other: ReadonlySetLike<unknown>) => boolean;
};
defaultValue: () => Shape;
of: (this: void, self: ReadonlySet<Logger<unknown, any>>) => ReadonlySet<Logger<unknown, any>>;
context: (self: ReadonlySet<Logger<unknown, any>>) => Context.Context<never>;
use: (f: (service: ReadonlySet<Logger<unknown, any>>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: ReadonlySet<Logger<unknown, any>>) => A) => Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
Context reference for the set of loggers currently used by Effect logging
operations.
When to use
Use to inspect or provide the complete set of loggers used by Effect logging
in the current context.
Details
The default set contains the built-in default logger and tracer logger.
Providing this reference changes which Logger instances receive log entries
in the current context.
CurrentLoggers: import ContextContext.interface Reference<in out Shape>Service key with a lazily computed default value.
Details
When a Reference is requested from a Context that does not contain an
override, Context getters that resolve references return the cached default
value instead of failing.
Example (Defining a reference with a default value)
import { Context } from "effect"
// Define a reference with a default value
const LoggerRef: Context.Reference<{ log: (msg: string) => void }> =
Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference can be used without explicit provision
const context = Context.empty()
const logger = Context.get(context, LoggerRef) // Uses default value
Creates a context key with a default value.
When to use
Use when you need to define a context key with a lazily computed default
value.
Details
Context.Reference allows you to create a key that can hold a value. You
can provide a default value for the service, which will automatically be used
when the context is accessed, or override it with a custom implementation
when needed. The default value is computed lazily and cached on the
reference.
Example (Creating references with default values)
import { Context } from "effect"
// Create a reference with a default value
const LoggerRef = Context.Reference("Logger", {
defaultValue: () => ({ log: (msg: string) => console.log(msg) })
})
// The reference provides the default value when accessed from an empty context
const context = Context.empty()
const logger = Context.get(context, LoggerRef)
// You can also override the default value
const customContext = Context.make(LoggerRef, {
log: (msg: string) => `Custom: ${msg}`
})
const customLogger = Context.get(customContext, LoggerRef)
Reference<interface ReadonlySet<T>ReadonlySet<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, any>>> = import internalEffectinternalEffect.const CurrentLoggers: Context.Reference<
ReadonlySet<Logger<unknown, any>>
>
const CurrentLoggers: {
key: string;
Service: {
forEach: (callbackfn: (value: Logger<unknown, any>, value2: Logger<unknown, any>, set: ReadonlySet<Logger<unknown, any>>) => void, thisArg?: any) => void;
has: (value: Logger<unknown, any>) => boolean;
size: number;
entries: () => SetIterator<[Logger<unknown, any>, Logger<unknown, any>]>;
keys: () => SetIterator<Logger<unknown, any>>;
values: () => SetIterator<Logger<unknown, any>>;
union: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any> | U>;
intersection: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any> & U>;
difference: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any>>;
symmetricDifference: (other: ReadonlySetLike<U>) => Set<Logger<unknown, any> | U>;
isSubsetOf: (other: ReadonlySetLike<unknown>) => boolean;
isSupersetOf: (other: ReadonlySetLike<unknown>) => boolean;
isDisjointFrom: (other: ReadonlySetLike<unknown>) => boolean;
};
defaultValue: () => Shape;
of: (this: void, self: ReadonlySet<Logger<unknown, any>>) => ReadonlySet<Logger<unknown, any>>;
context: (self: ReadonlySet<Logger<unknown, any>>) => Context.Context<never>;
use: (f: (service: ReadonlySet<Logger<unknown, any>>) => Effect<A, E, R>) => Effect<A, E, R>;
useSync: (f: (service: ReadonlySet<Logger<unknown, any>>) => A) => Effect<A, never, never>;
Identifier: Identifier;
stack: string | undefined;
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; <…;
toString: () => string;
toJSON: () => unknown;
}
CurrentLoggers