Skip to content

Make checkLevel() method on Logger public #21

Description

@adlaws

Currently the checkLevel() method in Logger is a private level method, but it would be useful to expose this method as public.

It can be useful to determine the current log level before making a potentially costly-to-construct log string (which might not even be logged depening on the current log level.

Currently this can be done using the getLevel() method, like so...
// only log if DEBUG level logging or higher is currently enabled
if (this->logger->getLevel() <= Logger::Level::LL_DEBUG)
{
// do the stuff
}

...but if the the checkLevel() method were exposed as a public method it would be a little "cleaner" from a redability point of view, and additionally one does not need to be aware of the internal ordering of the log levels defined in the enum (lowest->highest, or highest->lowest?) in order to do the correct <= or => numeric comparison:
// only log if DEBUG level logging or higher is currently enabled
if ( this->logger->checkLevel(Logger::Level::LL_DEBUG) )
{
// do the stuff
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions