forked from pwr-Solaar/Solaar
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement logger that internally checks if log level is enabled. Thus, unnecessary log message computation costs are avoid, when logging is disabled and logging code can be cut in half. Related pwr-Solaar#2663
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import logging | ||
|
||
|
||
class CustomLogger(logging.Logger): | ||
"""Logger, that avoids unnecessary string computations. | ||
Does not compute messages for disabled log levels. | ||
""" | ||
|
||
def debug(self, msg, *args, **kwargs): | ||
if self.isEnabledFor(logging.DEBUG): | ||
super().debug(msg, *args, **kwargs) | ||
|
||
def info(self, msg, *args, **kwargs): | ||
if self.isEnabledFor(logging.INFO): | ||
super().info(msg, *args, **kwargs) | ||
|
||
def warning(self, msg, *args, **kwargs): | ||
if self.isEnabledFor(logging.WARNING): | ||
super().warning(msg, *args, **kwargs) | ||
|
||
def error(self, msg, *args, **kwargs): | ||
if self.isEnabledFor(logging.ERROR): | ||
super().error(msg, *args, **kwargs) | ||
|
||
def critical(self, msg, *args, **kwargs): | ||
if self.isEnabledFor(logging.CRITICAL): | ||
super().critical(msg, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters