question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Check enable before writing to log

See original GitHub issue

Is there a way to check if a log level is enabled by a logger instance before writing to it?

if (logger.debug_enabled) {
  var msg = ...; // expensive op to compute a verbose message
  logger.debug(msg);
}

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
samngmscommented, Apr 12, 2018

@indexzero I believe you misunderstood the question. logger.debug is defined as long as the level is “defined” not “enabled” One possible way to do is something like the following

if ( logger.levels[logger.level] >= logger.levels['debug'] ) {
    // do some expensive calculation
    logger.debug(...)
}
0reactions
indexzerocommented, Mar 11, 2016

No. You would know implicitly throughout your application what levels are available if you called setLevels once yourself. By default logger.debug exists.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the Enable logging (troubleshooting) option?
Type of log file Subfolder Outlook 2013 Outlook 2010 Outlook 2007 Outlook Autodiscover Temp No Yes Yes Exchange ActiveSync Temp/EASLogFiles Yes No No Availability service Temp/OlkAS...
Read more >
Is there a need to do a if(log.isDebugEnabled()) { ... } check?
The statement: if(log.isDebugEnabled()){. Is used just for performance reasons. It's use is optional since it is called by the log method internally.
Read more >
Tracing and Logging
Select Enable Logging under the Debugging option. Other Options. File Names. plugin <random-number> .trace - Name of the trace file for ...
Read more >
Chrome Browser debug logs - Google Support
You can troubleshoot problems with Chrome Browser, such as hanging tabs and error messages. Use debug logs to help you. These logs aren't...
Read more >
Logging HOWTO — Python 3.11.1 documentation
To log variable data, use a format string for the event description message and append the variable data as arguments. For example: import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found