Thanks to visit codestin.com
Credit goes to effect-ts.github.io

Skip to main content Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

Logger.ts overview

Since v2.0.0


Exports Grouped by Category


console

withConsoleError

Signature

declare const withConsoleError: <M, O>(self: Logger<M, O>) => Logger<M, void>

Source

Since v2.0.0

withConsoleLog

Signature

declare const withConsoleLog: <M, O>(self: Logger<M, O>) => Logger<M, void>

Source

Since v2.0.0

withLeveledConsole

Takes a Logger<M, O> and returns a logger that calls the respective Console method based on the log level.

Example

import { Logger, Effect } from "effect"

const loggerLayer = Logger.replace(Logger.defaultLogger, Logger.withLeveledConsole(Logger.stringLogger))

Effect.gen(function* () {
  yield* Effect.logError("an error")
  yield* Effect.logInfo("an info")
}).pipe(Effect.provide(loggerLayer))

Signature

declare const withLeveledConsole: <M, O>(self: Logger<M, O>) => Logger<M, void>

Source

Since v3.8.0

constructors

defaultLogger

Signature

declare const defaultLogger: Logger<unknown, void>

Source

Since v2.0.0

json

The json logger formats log entries as JSON objects, making them easy to integrate with logging systems that consume JSON data.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.json)))
// {"message":["message1","message2"],"logLevel":"INFO","timestamp":"...","annotations":{"key2":"value2","key1":"value1"},"spans":{"myspan":0},"fiberId":"#0"}

Signature

declare const json: Layer.Layer<never, never, never>

Source

Since v2.0.0

jsonLogger

The jsonLogger logger formats log entries as JSON objects, making them easy to integrate with logging systems that consume JSON data.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.json)))
// {"message":["message1","message2"],"logLevel":"INFO","timestamp":"...","annotations":{"key2":"value2","key1":"value1"},"spans":{"myspan":0},"fiberId":"#0"}

Signature

declare const jsonLogger: Logger<unknown, string>

Source

Since v2.0.0

logFmt

This logger outputs logs in a human-readable format that is easy to read during development or in a production console.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.logFmt)))
// timestamp=... level=INFO fiber=#0 message=message1 message=message2 myspan=0ms key2=value2 key1=value1

Signature

declare const logFmt: Layer.Layer<never, never, never>

Source

Since v2.0.0

logfmtLogger

This logger outputs logs in a human-readable format that is easy to read during development or in a production console.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.logFmt)))
// timestamp=... level=INFO fiber=#0 message=message1 message=message2 myspan=0ms key2=value2 key1=value1

Signature

declare const logfmtLogger: Logger<unknown, string>

Source

Since v2.0.0

make

Creates a custom logger that formats log messages according to the provided function.

Example

import { Effect, Logger, LogLevel } from "effect"

const logger = Logger.make(({ logLevel, message }) => {
  globalThis.console.log(`[${logLevel.label}] ${message}`)
})

const task1 = Effect.logDebug("task1 done")
const task2 = Effect.logDebug("task2 done")

const program = Effect.gen(function* () {
  yield* Effect.log("start")
  yield* task1
  yield* task2
  yield* Effect.log("done")
}).pipe(Logger.withMinimumLogLevel(LogLevel.Debug), Effect.provide(Logger.replace(Logger.defaultLogger, logger)))

Effect.runFork(program)
// [INFO] start
// [DEBUG] task1 done
// [DEBUG] task2 done
// [INFO] done

Signature

declare const make: <Message, Output>(log: (options: Logger.Options<Message>) => Output) => Logger<Message, Output>

Source

Since v2.0.0

none

A logger that does nothing in response to logging events.

Signature

declare const none: Logger<unknown, void>

Source

Since v2.0.0

pretty

The pretty logger utilizes the capabilities of the console API to generate visually engaging and color-enhanced log outputs. This feature is particularly useful for improving the readability of log messages during development and debugging processes.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.pretty)))
//         green --v                      v-- bold and cyan
// [07:51:54.434] INFO (#0) myspan=1ms: message1
//   message2
//    v-- bold
//   key2: value2
//   key1: value1

Signature

declare const pretty: Layer.Layer<never, never, never>

Source

Since v3.5.0

prettyLogger

The pretty logger utilizes the capabilities of the console API to generate visually engaging and color-enhanced log outputs. This feature is particularly useful for improving the readability of log messages during development and debugging processes.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.pretty)))
//         green --v                      v-- bold and cyan
// [07:51:54.434] INFO (#0) myspan=1ms: message1
//   message2
//    v-- bold
//   key2: value2
//   key1: value1

Signature

declare const prettyLogger: (options?: {
  readonly colors?: "auto" | boolean | undefined
  readonly stderr?: boolean | undefined
  readonly formatDate?: ((date: Date) => string) | undefined
  readonly mode?: "browser" | "tty" | "auto" | undefined
}) => Logger<unknown, void>

Source

Since v3.5.0

prettyLoggerDefault

A default version of the pretty logger.

Signature

declare const prettyLoggerDefault: Logger<unknown, void>

Source

Since v3.8.0

simple

Signature

declare const simple: <A, B>(log: (a: A) => B) => Logger<A, B>

Source

Since v2.0.0

stringLogger

Signature

declare const stringLogger: Logger<unknown, string>

Source

Since v2.0.0

structured

The structured logger provides detailed log outputs, structured in a way that retains comprehensive traceability of the events, suitable for deeper analysis and troubleshooting.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.structured)))
// {
//   message: [ 'message1', 'message2' ],
//   logLevel: 'INFO',
//   timestamp: '2024-07-09T14:05:41.623Z',
//   cause: undefined,
//   annotations: { key2: 'value2', key1: 'value1' },
//   spans: { myspan: 0 },
//   fiberId: '#0'
// }

Signature

declare const structured: Layer.Layer<never, never, never>

Source

Since v2.0.0

structuredLogger

The structured logger provides detailed log outputs, structured in a way that retains comprehensive traceability of the events, suitable for deeper analysis and troubleshooting.

Example

import { Effect, Logger } from "effect"

const program = Effect.log("message1", "message2").pipe(
  Effect.annotateLogs({ key1: "value1", key2: "value2" }),
  Effect.withLogSpan("myspan")
)

Effect.runFork(program.pipe(Effect.provide(Logger.structured)))
// {
//   message: [ 'message1', 'message2' ],
//   logLevel: 'INFO',
//   timestamp: '2024-07-09T14:05:41.623Z',
//   cause: undefined,
//   annotations: { key2: 'value2', key1: 'value1' },
//   spans: { myspan: 0 },
//   fiberId: '#0'
// }

Signature

declare const structuredLogger: Logger<
  unknown,
  {
    readonly logLevel: string
    readonly fiberId: string
    readonly timestamp: string
    readonly message: unknown
    readonly cause: string | undefined
    readonly annotations: Record<string, unknown>
    readonly spans: Record<string, number>
  }
>

Source

Since v2.0.0

succeed

Signature

declare const succeed: <A>(value: A) => Logger<unknown, A>

Source

Since v2.0.0

sync

Signature

declare const sync: <A>(evaluate: LazyArg<A>) => Logger<unknown, A>

Source

Since v2.0.0

test

Signature

declare const test: {
  <Message>(input: Message): <Output>(self: Logger<Message, Output>) => Output
  <Message, Output>(self: Logger<Message, Output>, input: Message): Output
}

Source

Since v2.0.0

tracerLogger

Signature

declare const tracerLogger: Logger<unknown, void>

Source

Since v2.0.0

context

add

Signature

declare const add: <B>(logger: Logger<unknown, B>) => Layer.Layer<never>

Source

Since v2.0.0

addEffect

Signature

declare const addEffect: <A, E, R>(effect: Effect<Logger<unknown, A>, E, R>) => Layer.Layer<never, E, R>

Source

Since v2.0.0

addScoped

Signature

declare const addScoped: <A, E, R>(effect: Effect<Logger<unknown, A>, E, R>) => Layer.Layer<never, E, Exclude<R, Scope>>

Source

Since v2.0.0

minimumLogLevel

Sets the minimum log level for logging operations, allowing control over which log messages are displayed based on their severity.

Example

import { Effect, Logger, LogLevel } from "effect"

const program = Effect.gen(function* () {
  yield* Effect.log("Executing task...")
  yield* Effect.sleep("100 millis")
  console.log("task done")
})

// Logging disabled using a layer
Effect.runFork(program.pipe(Effect.provide(Logger.minimumLogLevel(LogLevel.None))))
// task done

Signature

declare const minimumLogLevel: (level: LogLevel.LogLevel) => Layer.Layer<never>

Source

Since v2.0.0

remove

Signature

declare const remove: <A>(logger: Logger<unknown, A>) => Layer.Layer<never>

Source

Since v2.0.0

replace

Signature

declare const replace: {
  <B>(that: Logger<unknown, B>): <A>(self: Logger<unknown, A>) => Layer.Layer<never>
  <A, B>(self: Logger<unknown, A>, that: Logger<unknown, B>): Layer.Layer<never>
}

Source

Since v2.0.0

replaceEffect

Signature

declare const replaceEffect: {
  <B, E, R>(that: Effect<Logger<unknown, B>, E, R>): <A>(self: Logger<unknown, A>) => Layer.Layer<never, E, R>
  <A, B, E, R>(self: Logger<unknown, A>, that: Effect<Logger<unknown, B>, E, R>): Layer.Layer<never, E, R>
}

Source

Since v2.0.0

replaceScoped

Signature

declare const replaceScoped: {
  <B, E, R>(
    that: Effect<Logger<unknown, B>, E, R>
  ): <A>(self: Logger<unknown, A>) => Layer.Layer<never, E, Exclude<R, Scope>>
  <A, B, E, R>(
    self: Logger<unknown, A>,
    that: Effect<Logger<unknown, B>, E, R>
  ): Layer.Layer<never, E, Exclude<R, Scope>>
}

Source

Since v2.0.0

withMinimumLogLevel

Sets the minimum log level for subsequent logging operations, allowing control over which log messages are displayed based on their severity.

Example

import { Effect, Logger, LogLevel } from "effect"

const program = Effect.logDebug("message1").pipe(Logger.withMinimumLogLevel(LogLevel.Debug))

Effect.runFork(program)
// timestamp=... level=DEBUG fiber=#0 message=message1

Signature

declare const withMinimumLogLevel: {
  (level: LogLevel.LogLevel): <A, E, R>(self: Effect<A, E, R>) => Effect<A, E, R>
  <A, E, R>(self: Effect<A, E, R>, level: LogLevel.LogLevel): Effect<A, E, R>
}

Source

Since v2.0.0

filtering

filterLogLevel

Returns a version of this logger that only logs messages when the log level satisfies the specified predicate.

Signature

declare const filterLogLevel: {
  (
    f: (logLevel: LogLevel.LogLevel) => boolean
  ): <Message, Output>(self: Logger<Message, Output>) => Logger<Message, Option.Option<Output>>
  <Message, Output>(
    self: Logger<Message, Output>,
    f: (logLevel: LogLevel.LogLevel) => boolean
  ): Logger<Message, Option.Option<Output>>
}

Source

Since v2.0.0

guards

isLogger

Returns true if the specified value is a Logger, otherwise returns false.

Signature

declare const isLogger: (u: unknown) => u is Logger<unknown, unknown>

Source

Since v1.0.0

mapping

batched

Creates a batched logger that groups log messages together and processes them in intervals.

Example

import { Console, Effect, Logger } from "effect"

const LoggerLive = Logger.replaceScoped(
  Logger.defaultLogger,
  Logger.logfmtLogger.pipe(
    Logger.batched("500 millis", (messages) => Console.log("BATCH", `[\n${messages.join("\n")}\n]`))
  )
)

const program = Effect.gen(function* () {
  yield* Effect.log("one")
  yield* Effect.log("two")
  yield* Effect.log("three")
}).pipe(Effect.provide(LoggerLive))

Effect.runFork(program)
// BATCH [
// timestamp=... level=INFO fiber=#0 message=one
// timestamp=... level=INFO fiber=#0 message=two
// timestamp=... level=INFO fiber=#0 message=three
// ]

Signature

declare const batched: {
  <Output, R>(
    window: DurationInput,
    f: (messages: Array<Types.NoInfer<Output>>) => Effect<void, never, R>
  ): <Message>(self: Logger<Message, Output>) => Effect<Logger<Message, void>, never, R | Scope>
  <Message, Output, R>(
    self: Logger<Message, Output>,
    window: DurationInput,
    f: (messages: Array<Types.NoInfer<Output>>) => Effect<void, never, R>
  ): Effect<Logger<Message, void>, never, Scope | R>
}

Source

Since v2.0.0

map

Signature

declare const map: {
  <Output, Output2>(
    f: (output: Output) => Output2
  ): <Message>(self: Logger<Message, Output>) => Logger<Message, Output2>
  <Message, Output, Output2>(self: Logger<Message, Output>, f: (output: Output) => Output2): Logger<Message, Output2>
}

Source

Since v2.0.0

mapInput

Signature

declare const mapInput: {
  <Message, Message2>(
    f: (message: Message2) => Message
  ): <Output>(self: Logger<Message, Output>) => Logger<Message2, Output>
  <Output, Message, Message2>(
    self: Logger<Message, Output>,
    f: (message: Message2) => Message
  ): Logger<Message2, Output>
}

Source

Since v2.0.0

mapInputOptions

Signature

declare const mapInputOptions: {
  <Message, Message2>(
    f: (options: Logger.Options<Message2>) => Logger.Options<Message>
  ): <Output>(self: Logger<Message, Output>) => Logger<Message2, Output>
  <Output, Message, Message2>(
    self: Logger<Message, Output>,
    f: (options: Logger.Options<Message2>) => Logger.Options<Message>
  ): Logger<Message2, Output>
}

Source

Since v2.0.0

models

Logger (interface)

Signature

export interface Logger<in Message, out Output> extends Logger.Variance<Message, Output>, Pipeable {
  log(options: Logger.Options<Message>): Output
}

Source

Since v2.0.0

symbols

LoggerTypeId

Signature

declare const LoggerTypeId: unique symbol

Source

Since v2.0.0

LoggerTypeId (type alias)

Signature

type LoggerTypeId = typeof LoggerTypeId

Source

Since v2.0.0

tracing

withSpanAnnotations

Signature

declare const withSpanAnnotations: <Message, Output>(self: Logger<Message, Output>) => Logger<Message, Output>

Source

Since v2.0.0

utils

Logger (namespace)

Source

Since v2.0.0

Variance (interface)

Signature

export interface Variance<in Message, out Output> {
  readonly [LoggerTypeId]: {
    readonly _Message: Types.Contravariant<Message>
    readonly _Output: Types.Covariant<Output>
  }
}

Source

Since v2.0.0

Options (interface)

Signature

export interface Options<out Message> {
  readonly fiberId: FiberId.FiberId
  readonly logLevel: LogLevel.LogLevel
  readonly message: Message
  readonly cause: Cause.Cause<unknown>
  readonly context: FiberRefs.FiberRefs
  readonly spans: List.List<LogSpan.LogSpan>
  readonly annotations: HashMap.HashMap<string, unknown>
  readonly date: Date
}

Source

Since v2.0.0

zipping

zip

Combines this logger with the specified logger to produce a new logger that logs to both this logger and that logger.

Signature

declare const zip: {
  <Message2, Output2>(
    that: Logger<Message2, Output2>
  ): <Message, Output>(self: Logger<Message, Output>) => Logger<Message & Message2, [Output, Output2]>
  <Message, Output, Message2, Output2>(
    self: Logger<Message, Output>,
    that: Logger<Message2, Output2>
  ): Logger<Message & Message2, [Output, Output2]>
}

Source

Since v2.0.0

zipLeft

Signature

declare const zipLeft: {
  <Message2, Output2>(
    that: Logger<Message2, Output2>
  ): <Message, Output>(self: Logger<Message, Output>) => Logger<Message & Message2, Output>
  <Message, Output, Message2, Output2>(
    self: Logger<Message, Output>,
    that: Logger<Message2, Output2>
  ): Logger<Message & Message2, Output>
}

Source

Since v2.0.0

zipRight

Signature

declare const zipRight: {
  <Message2, Output2>(
    that: Logger<Message2, Output2>
  ): <Message, Output>(self: Logger<Message, Output>) => Logger<Message & Message2, Output2>
  <Message, Output, Message2, Output2>(
    self: Logger<Message, Output>,
    that: Logger<Message2, Output2>
  ): Logger<Message & Message2, Output2>
}

Source

Since v2.0.0