LogLevel
Log-level types and helpers used by Effect logging. The module defines all accepted log levels, the concrete emitted severities, the ordered level list, equality and ordering instances, threshold comparison helpers, and an effect for checking whether a level is enabled by the current logging settings.
Constants
Returns all LogLevel values in order from All through the concrete severities to
None.
When to use
Use to enumerate or validate all accepted LogLevel string values, including
the All and None sentinel levels.
Details
The array order matches the module severity order: All, concrete
severities from Fatal to Trace, then None.
Gotchas
This list includes All and None, so it is not limited to concrete emitted
severities.
See
Signature
declare const values: ReadonlyArray<LogLevel>Instances
Equivalence
Equivalence instance for log levels using strict equality (===).
When to use
Use to compare two LogLevel values when only the exact same level should
match.
Details
Each log level string, including All and None, only matches itself.
See
- Order for severity ordering rather than exact level equality
- isGreaterThanOrEqualTo for minimum-threshold checks
Signature
declare const Equivalence: Equ.Equivalence<LogLevel>Example
(Comparing log levels)
import { LogLevel } from "effect"
LogLevel.Equivalence("Error", "Error") // => trueLogLevel.Equivalence("Error", "Info") // => falseModels
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 messagesFatal- System is unusable, immediate attention requiredError- Error conditions that should be investigatedWarn- Warning conditions that may indicate problemsInfo- Informational messages about normal operationDebug- Debug information useful during developmentTrace- Very detailed trace informationNone- Special level that suppresses all messages
Signature
type LogLevel = "All" | "Fatal" | "Error" | "Warn" | "Info" | "Debug" | "Trace" | "None"Example
(Using log levels)
import { Effect, References } from "effect"
// Using log levels with Effect loggingconst 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 variablesconst errorLevel = "Error" // LogLevelconst debugLevel = "Debug" // LogLevel
await Effect.runPromise( Effect.provideService(program, References.MinimumLogLevel, "None"))
const levels = [errorLevel, debugLevel]levels // => ["Error", "Debug"]Log levels that represent actual message severities, excluding the All and
None sentinel levels.
When to use
Use when typing emitted log message severities, such as explicit log calls,
current log level references, or error-report severity annotations, where
All and None are not valid values.
See
Signature
type Severity = "Fatal" | "Error" | "Warn" | "Info" | "Debug" | "Trace"Ordering
getOrdinal
Returns the ordinal value of the log level.
When to use
Use to project a LogLevel into the numeric sort key used by
LogLevel.Order when custom ordering code or an integration needs a number
instead of an Order comparison.
Details
The mapping is All to Number.MIN_SAFE_INTEGER, Trace to 0, Debug to
10000, Info to 20000, Warn to 30000, Error to 40000, Fatal to
50000, and None to Number.MAX_SAFE_INTEGER.
Gotchas
These ordinals are internal sort keys; do not treat them as external severity numbers.
See
- Order for comparing log levels without exposing numeric keys
- isGreaterThanOrEqualTo for minimum-threshold filtering
Signature
declare function getOrdinal(self: LogLevel): numberisGreaterThan
Determines if the first log level is more severe than the second.
When to use
Use to check whether one log level is strictly more severe than another.
Details
Returns true if self represents a more severe level than that.
Signature
declare const isGreaterThan: { (that: LogLevel): (self: LogLevel) => boolean; (self: LogLevel, that: LogLevel): boolean;}Example
(Checking higher severity)
import { LogLevel } from "effect"
LogLevel.isGreaterThan("Error", "Info") // => trueLogLevel.isGreaterThan("Debug", "Error") // => false
// Use with filteringconst isFatal = LogLevel.isGreaterThan("Fatal", "Warn")const isError = LogLevel.isGreaterThan("Error", "Warn")const isDebug = LogLevel.isGreaterThan("Debug", "Warn")isFatal // => trueisError // => trueisDebug // => false
// Curried usageconst isMoreSevereThanInfo = LogLevel.isGreaterThan("Info")isMoreSevereThanInfo("Error") // => trueisMoreSevereThanInfo("Debug") // => falseisGreaterThanOrEqualTo
Determines if the first log level is more severe than or equal to the second.
When to use
Use to implement minimum log-level filtering by checking whether a message level meets a threshold.
Details
Returns true if self represents a level that is more severe than or equal to that.
Signature
declare const isGreaterThanOrEqualTo: { (that: LogLevel): (self: LogLevel) => boolean; (self: LogLevel, that: LogLevel): boolean;}Example
(Filtering by minimum log level)
import { LogLevel } from "effect"
LogLevel.isGreaterThanOrEqualTo("Error", "Error") // => trueLogLevel.isGreaterThanOrEqualTo("Error", "Info") // => trueLogLevel.isGreaterThanOrEqualTo("Debug", "Info") // => false
const isInfoOrAbove = LogLevel.isGreaterThanOrEqualTo("Info")isInfoOrAbove("Error") // => trueisLessThan
Determines if the first log level is less severe than the second.
When to use
Use to check whether one log level is strictly less severe than another.
Details
Returns true if self represents a less severe level than that.
Signature
declare const isLessThan: { (that: LogLevel): (self: LogLevel) => boolean; (self: LogLevel, that: LogLevel): boolean;}Example
(Checking lower severity)
import { LogLevel } from "effect"
LogLevel.isLessThan("Debug", "Info") // => trueLogLevel.isLessThan("Error", "Info") // => false
// Filter out verbose logsconst isFatalVerbose = LogLevel.isLessThan("Fatal", "Info")const isErrorVerbose = LogLevel.isLessThan("Error", "Info")const isTraceVerbose = LogLevel.isLessThan("Trace", "Info")isFatalVerbose // => falseisErrorVerbose // => falseisTraceVerbose // => true
// Curried usageconst isLessSevereThanError = LogLevel.isLessThan("Error")isLessSevereThanError("Info") // => trueisLessSevereThanError("Fatal") // => falseisLessThanOrEqualTo
Determines if the first log level is less severe than or equal to the second.
When to use
Use to implement maximum log-level filtering by checking whether a level is at or below a threshold.
Details
Returns true if self represents a level that is less severe than or equal to that.
Signature
declare const isLessThanOrEqualTo: { (that: LogLevel): (self: LogLevel) => boolean; (self: LogLevel, that: LogLevel): boolean;}Example
(Filtering by maximum log level)
import { LogLevel } from "effect"
LogLevel.isLessThanOrEqualTo("Info", "Info") // => trueLogLevel.isLessThanOrEqualTo("Debug", "Info") // => trueLogLevel.isLessThanOrEqualTo("Error", "Info") // => false
const isInfoOrBelow = LogLevel.isLessThanOrEqualTo("Info")isInfoOrBelow("Debug") // => trueOrder instance for LogLevel that defines the severity ordering.
When to use
Use to sort or compare log levels according to Effect's severity order.
Details
This order treats "All" as the least restrictive level and "None" as the most restrictive, with Fatal being the most severe actual log level.
Signature
declare const Order: Ord.Order<LogLevel>Example
(Ordering log levels)
import { LogLevel } from "effect"
LogLevel.Order("Error", "Info") // => 1LogLevel.Order("Debug", "Error") // => -1LogLevel.Order("Info", "Info") // => 0Predicates
Checks whether a given log level is enabled for the current fiber.
When to use
Use to check whether a log level would be emitted under the current fiber's minimum log level.
Details
A log level is enabled when it is greater than or equal to
References.MinimumLogLevel.
Signature
declare function isEnabled(self: LogLevel): Effect<boolean>Example
(Checking current fiber log level)
import { Effect, LogLevel, References } from "effect"
const program = Effect.gen(function*() { const debugEnabled = yield* LogLevel.isEnabled("Debug") const errorEnabled = yield* LogLevel.isEnabled("Error")
return { debugEnabled, errorEnabled }})
const warnOnly = program.pipe( Effect.provideService(References.MinimumLogLevel, "Warn"))
await Effect.runPromise(warnOnly) // => { debugEnabled: false, errorEnabled: true }