Hyperlinkv0.8.0-beta.28

LogLevel

LogLevel.isLessThanOrEqualToconsteffect/LogLevel.ts:373
(that: LogLevel): (self: LogLevel) => boolean
(self: LogLevel, that: LogLevel): boolean

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.

Example (Filtering by maximum log level)

import { Logger, LogLevel } from "effect"

// Check if level is at or below threshold
console.log(LogLevel.isLessThanOrEqualTo("Info", "Info")) // true
console.log(LogLevel.isLessThanOrEqualTo("Debug", "Info")) // true
console.log(LogLevel.isLessThanOrEqualTo("Error", "Info")) // false

// Create a logger that suppresses verbose logs
const quietLogger = Logger.make((options) => {
  if (LogLevel.isLessThanOrEqualTo(options.logLevel, "Info")) {
    console.log(`[${options.logLevel}] ${options.message}`)
  }
})

// Development logger - suppress trace logs
const devLogger = Logger.make((options) => {
  if (LogLevel.isLessThanOrEqualTo(options.logLevel, "Debug")) {
    console.log(`[${options.logLevel}] ${options.message}`)
  }
})

// Curried usage for filtering
const isInfoOrBelow = LogLevel.isLessThanOrEqualTo("Info")
const shouldLog = isInfoOrBelow("Debug") // true
ordering
export const isLessThanOrEqualTo: {
  (that: LogLevel): (self: LogLevel) => boolean
  (self: LogLevel, that: LogLevel): boolean
} = Ord.isLessThanOrEqualTo(Order)