(options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<Record<string, unknown>>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}): LogEntryBuild a LogEntry from runtime logger options and fiber log context.
export const const logEntryFromLoggerOptions: (options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}) => LogEntry
Build a
LogEntry
from runtime logger options and fiber log context.
logEntryFromLoggerOptions = (options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options: {
readonly message: unknownmessage: unknown;
readonly logLevel: LogLevellogLevel: type LogLevel = "All" | "Fatal" | "Error" | "Warn" | "Info" | "Debug" | "Trace" | "None"Represents every level used by Effect logging, including concrete message
severities and the All and None sentinel levels.
When to use
Use to type values that may be either concrete log message severities or
logging configuration sentinels.
Details
The levels are ordered from most severe to least severe:
All - Special level that allows all messages
Fatal - System is unusable, immediate attention required
Error - Error conditions that should be investigated
Warn - Warning conditions that may indicate problems
Info - Informational messages about normal operation
Debug - Debug information useful during development
Trace - Very detailed trace information
None - Special level that suppresses all messages
Example (Using log levels)
import { Effect } from "effect"
// Using log levels with Effect logging
const program = Effect.gen(function*() {
yield* Effect.logFatal("System failure")
yield* Effect.logError("Database error")
yield* Effect.logWarning("High memory usage")
yield* Effect.logInfo("User logged in")
yield* Effect.logDebug("Processing request")
yield* Effect.logTrace("Variable state")
})
// Type-safe log level variables
const errorLevel = "Error" // LogLevel
const debugLevel = "Debug" // LogLevel
LogLevel;
readonly cause: Cause.Cause<unknown>(property) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause: import CauseCause.interface Cause<out E>A structured representation of how an Effect failed.
When to use
Use to preserve the full structured failure information for an effect instead
of collapsing it to a single error value.
Details
Access the individual failure entries through the reasons array, then
narrow each entry with
isFailReason
,
isDieReason
, or
isInterruptReason
.
- Use
hasFails
/
hasDies
/
hasInterrupts
to test
for the presence of specific reason kinds without iterating.
- Use
findError
/
findDefect
to extract the first value
of a given kind.
- Use
combine
to merge two causes.
Cause implements Equal — two causes with the same reasons (by value)
compare as equal.
Example (Creating and inspecting a cause)
import { Cause } from "effect"
const cause = Cause.fail("Something went wrong")
console.log(cause.reasons.length) // 1
console.log(Cause.isFailReason(cause.reasons[0])) // true
Companion namespace for the Cause interface.
Cause<unknown>;
readonly date: Datedate: Date;
readonly annotations: Readonly<Record<string, unknown>>annotations: type Readonly<T> = {
readonly [P in keyof T]: T[P]
}
Make all properties in T readonly
Readonly<type Record<K extends keyof any, T> = {
[P in K]: T
}
Construct a type with a set of properties K of type T
Record<string, unknown>>;
readonly spans: readonly (readonly [
label: string,
startTime: number
])[]
spans: interface ReadonlyArray<T>ReadonlyArray<readonly [stringlabel: string, numberstartTime: number]>;
}): LogEntry => ({
LogEntry.date: stringdate: options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.date: Datedate.Date.toISOString(): stringReturns a date as a string value in ISO format.
toISOString(),
LogEntry.level: LogLevellevel: options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.logLevel: LogLevellogLevel,
LogEntry.message: stringmessage: const encodeMessage: (
message: unknown
) => string
encodeMessage(options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.message: unknownmessage),
...(options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.cause: Cause.Cause<unknown>(property) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause.Cause<unknown>.reasons: readonly Cause.Reason<unknown>[]reasons.ReadonlyArray<Reason<unknown>>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === 0
? {}
: { LogEntry.cause?: string | undefinedcause: import CauseCause.const pretty: <unknown>(
cause: Cause.Cause<unknown>
) => string
Formats a Cause as a human-readable string for logging or debugging.
When to use
Use to render a whole cause as one human-readable string for logs or
diagnostics.
Details
Delegates to
prettyErrors
to convert each reason to an Error,
then joins their stack traces with newlines. Nested Error.cause chains
are rendered inline with indentation:
ErrorName: message
at ...
at ... {
[cause]: NestedError: message
at ...
}
Span annotations are appended to the relevant stack frames when available.
Gotchas
Rendering an empty cause produces an empty string because there are no
errors to render.
Example (Rendering a cause)
import { Cause } from "effect"
const rendered = Cause.pretty(Cause.fail("something went wrong"))
console.log(rendered.includes("something went wrong")) // true
pretty(options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.cause: Cause.Cause<unknown>(property) cause: {
reasons: ReadonlyArray<Reason<E>>;
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;
}
cause) }),
LogEntry.annotations: Readonly<Record<string, string>>annotations: var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.fromEntries<string>(entries: Iterable<readonly [PropertyKey, string]>): {
[k: string]: string;
} (+1 overload)
Returns an object created by key-value entries for properties and methods
fromEntries(
var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.entries<unknown>(o: {
[s: string]: unknown;
} | ArrayLike<unknown>): [string, unknown][] (+1 overload)
Returns an array of key/values of the enumerable own properties of an object
entries(options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.annotations: Readonly<Record<string, unknown>>annotations).Array<[string, unknown]>.map<[string, string]>(callbackfn: (value: [string, unknown], index: number, array: [string, unknown][]) => [string, string], thisArg?: any): [string, string][]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(([key: stringkey, value: unknownvalue]) => [
key: stringkey,
const encodeAnnotationValue: (
value: unknown
) => string
encodeAnnotationValue(value: unknownvalue),
]),
),
LogEntry.spans: readonly string[]spans: options: {
readonly message: unknown
readonly logLevel: LogLevel
readonly cause: Cause.Cause<unknown>
readonly date: Date
readonly annotations: Readonly<
Record<string, unknown>
>
readonly spans: ReadonlyArray<
readonly [label: string, startTime: number]
>
}
options.spans: readonly (readonly [
label: string,
startTime: number
])[]
spans.ReadonlyArray<readonly [label: string, startTime: number]>.map<string>(callbackfn: (value: readonly [label: string, startTime: number], index: number, array: readonly (readonly [label: string, startTime: number])[]) => string, thisArg?: any): string[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(([label: stringlabel]) => label: stringlabel),
});