Skip to content

Modern Log Enabled

Paul Squires edited this page Oct 19, 2026 · 6 revisions

Home › Logging › Logging › Enabled

Enabled

Returns true if a record at a level would be emitted, to skip building costly messages.

Syntax

Enabled( byval lv as LogLevel ) as boolean

Notes

  • The guard for a message that is expensive to build: formatting, joining or serialising something that will then be thrown away.
  • It compares against MinLevel, so it answers the same question the level methods ask internally -- this just lets a caller ask first.
  • Cheap: a comparison, no allocation.

Examples

#import "std/logs"
using logs

dim con as ConsoleSink
dim lg as Logger
lg.AddSink( @con )

lg.MinLevel = LOG_INFO

print lg.Enabled( LOG_INFO )     '' true
print lg.Enabled( LOG_DEBUG )    '' false -- below MinLevel

'' The point of it: skip work that would be discarded
if lg.Enabled( LOG_DEBUG ) then
    lg.Debug( ).AddText( "dump", "something expensive to build" ).Msg( "state" )
end if

Library: Logging
Category: Logging
Documented under: Members

Clone this wiki locally