@gvray/logger / conditionalMiddleware
Function: conditionalMiddleware()
conditionalMiddleware(
condition,middleware):LogMiddleware
Defined in: middleware/conditional.ts:23
Middleware that applies another middleware only when a condition holds.
When condition(ctx) returns true, the wrapped middleware runs; the log is always forwarded (via next()) regardless of the condition.
Parameters
condition
(ctx) => boolean
Predicate evaluated against each log context.
middleware
Middleware to apply when the condition is true.
Returns
A LogMiddleware instance.
Example
ts
logger.use(
conditionalMiddleware(
(ctx) => ctx.level >= LogLevel.ERROR,
prefixMiddleware('🚨 ALERT'),
),
);