<Message, Output>(self: Logger<Message, Output>): Logger<Message, void>Returns a new Logger that writes all output of the specified Logger to
the console.
Details
Will use the appropriate console method (i.e. console.log, console.error,
etc.) based upon the current LogLevel.
Debug uses console.debug, Info uses console.info, Trace uses
console.trace, Warn uses console.warn, Error and Fatal use
console.error, and all other levels use console.log.
Example (Writing logs with level-based console methods)
import { Effect, Logger } from "effect"
const formatter = Logger.make((options) =>
`[${options.logLevel}] ${options.message}`
)
const leveledLogger = Logger.withLeveledConsole(formatter)
const program = Effect.gen(function*() {
yield* Effect.logInfo("Info message") // -> console.info
yield* Effect.logWarning("Warning") // -> console.warn
yield* Effect.logError("Error occurred") // -> console.error
yield* Effect.logDebug("Debug info") // -> console.debug
}).pipe(
Effect.provide(Logger.layer([leveledLogger]))
)export const const withLeveledConsole: <
Message,
Output
>(
self: Logger<Message, Output>
) => Logger<Message, void>
Returns a new Logger that writes all output of the specified Logger to
the console.
Details
Will use the appropriate console method (i.e. console.log, console.error,
etc.) based upon the current LogLevel.
Debug uses console.debug, Info uses console.info, Trace uses
console.trace, Warn uses console.warn, Error and Fatal use
console.error, and all other levels use console.log.
Example (Writing logs with level-based console methods)
import { Effect, Logger } from "effect"
const formatter = Logger.make((options) =>
`[${options.logLevel}] ${options.message}`
)
const leveledLogger = Logger.withLeveledConsole(formatter)
const program = Effect.gen(function*() {
yield* Effect.logInfo("Info message") // -> console.info
yield* Effect.logWarning("Warning") // -> console.warn
yield* Effect.logError("Error occurred") // -> console.error
yield* Effect.logDebug("Debug info") // -> console.debug
}).pipe(
Effect.provide(Logger.layer([leveledLogger]))
)
withLeveledConsole = <function (type parameter) Message in <Message, Output>(self: Logger<Message, Output>): Logger<Message, void>Message, function (type parameter) Output in <Message, Output>(self: Logger<Message, Output>): Logger<Message, void>Output>(
self: Logger<Message, Output>(parameter) self: {
log: (options: Options<Message>) => Output;
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; <…;
}
self: 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<function (type parameter) Message in <Message, Output>(self: Logger<Message, Output>): Logger<Message, void>Message, function (type parameter) Output in <Message, Output>(self: Logger<Message, Output>): Logger<Message, void>Output>
): 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<function (type parameter) Message in <Message, Output>(self: Logger<Message, Output>): Logger<Message, void>Message, void> =>
import effecteffect.const loggerMake: <Message, Output>(
log: (
options: Logger.Options<Message>
) => Output
) => Logger.Logger<Message, Output>
loggerMake((options: Options<Message>(parameter) options: {
message: Message;
logLevel: LogLevel.LogLevel;
cause: Cause.Cause<unknown>;
fiber: Fiber.Fiber<unknown, unknown>;
date: Date;
}
options) => {
const const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console = options: Options<Message>(parameter) options: {
message: Message;
logLevel: LogLevel.LogLevel;
cause: Cause.Cause<unknown>;
fiber: Fiber.Fiber<unknown, unknown>;
date: Date;
}
options.Options<out Message>.fiber: Fiber.Fiber<unknown, unknown>(property) Options<out Message>.fiber: {
id: number;
currentOpCount: number;
getRef: <A>(ref: Context.Reference<A>) => A;
context: Context.Context<never>;
setContext: (context: Context.Context<never>) => void;
currentScheduler: Scheduler;
currentDispatcher: SchedulerDispatcher;
currentSpan: AnySpan | undefined;
currentLogLevel: LogLevel;
minimumLogLevel: LogLevel;
currentStackFrame: StackFrame | undefined;
maxOpsBeforeYield: number;
currentPreventYield: boolean;
addObserver: (cb: (exit: Exit<A, E>) => void) => () => void;
interruptUnsafe: (fiberId?: number | undefined, annotations?: Context.Context<never> | undefined) => void;
pollUnsafe: () => Exit<A, E> | 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; <…;
}
fiber.getRef(import effecteffect.const ConsoleRef: Context.Reference<Console>const ConsoleRef: {
key: string;
Service: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
};
defaultValue: () => Shape;
of: (this: void, self: Console) => Console;
context: (self: Console) => Context.Context<never>;
use: (f: (service: Console) => Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>;
useSync: (f: (service: Console) => A) => Effect.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;
}
ConsoleRef)
const const output: Outputoutput = self: Logger<Message, Output>(parameter) self: {
log: (options: Options<Message>) => Output;
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; <…;
}
self.Logger<Message, Output>.log(options: Options<Message>): Outputlog(options: Options<Message>(parameter) options: {
message: Message;
logLevel: LogLevel.LogLevel;
cause: Cause.Cause<unknown>;
fiber: Fiber.Fiber<unknown, unknown>;
date: Date;
}
options)
switch (options: Options<Message>(parameter) options: {
message: Message;
logLevel: LogLevel.LogLevel;
cause: Cause.Cause<unknown>;
fiber: Fiber.Fiber<unknown, unknown>;
date: Date;
}
options.Options<out Message>.logLevel: LogLevel.LogLevellogLevel) {
case "Debug":
return const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.debug(const output: Outputoutput)
case "Info":
return const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.info(const output: Outputoutput)
case "Trace":
return const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.trace(const output: Outputoutput)
case "Warn":
return const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.warn(const output: Outputoutput)
case "Error":
case "Fatal":
return const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.error(const output: Outputoutput)
default:
return const console: Consoleconst console: {
assert: (condition: boolean, ...args: ReadonlyArray<any>) => void;
clear: () => void;
count: (label?: string) => void;
countReset: (label?: string) => void;
debug: (...args: ReadonlyArray<any>) => void;
dir: (item: any, options?: any) => void;
dirxml: (...args: ReadonlyArray<any>) => void;
error: (...args: ReadonlyArray<any>) => void;
group: (...args: ReadonlyArray<any>) => void;
groupCollapsed: (...args: ReadonlyArray<any>) => void;
groupEnd: () => void;
info: (...args: ReadonlyArray<any>) => void;
log: (...args: ReadonlyArray<any>) => void;
table: (tabularData: any, properties?: ReadonlyArray<string>) => void;
time: (label?: string) => void;
timeEnd: (label?: string) => void;
timeLog: (label?: string, ...args: ReadonlyArray<any>) => void;
trace: (...args: ReadonlyArray<any>) => void;
warn: (...args: ReadonlyArray<any>) => void;
}
console.log(const output: Outputoutput)
}
})