cocomon

Filters

Filter records by level, layer, type, feature, or custom boolean combinations.

Filters

Filters run per handler. That means the same record can be accepted by one handler and rejected by another.

Built-in filters

FilterPurpose
LevelLogFilterMinimum severity threshold
LayerLogFilterAllow only selected architectural layers
TypeLogFilterAllow only selected log categories
FeatureLogFilterAllow only selected feature tags
CompositeLogFilterCombine multiple filters with and or or
AllPassLogFilterAccept everything

Minimum level

ConsoleLogHandler(
  filter: const LevelLogFilter(LogLevel.WARNING),
)

This keeps warnings and above while dropping INFO and lower.

Filter by type

ConsoleLogHandler(
  filter: const TypeLogFilter({LogType.network}),
)

Useful when you want one handler dedicated to HTTP or database traffic.

Combine filters

const filter = CompositeLogFilter(
  [
    LevelLogFilter(LogLevel.INFO),
    TypeLogFilter({LogType.network}),
  ],
  mode: CompositeMode.and,
);

This accepts only network records at INFO or above.

Important behavior

  • Filtering happens before handle(record).
  • Rejected records never reach the output sink.
  • Filters with nullable tags usually let missing values pass unless they are explicitly checking for membership.

Practical pattern

Use different filters per sink:

  • console: INFO and above
  • file: FINE and above
  • viewer history: everything you care to inspect live

That is usually better than trying to force one global threshold for every consumer.

On this page