Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom logger #2664

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lib/solaar/custom_logger.py
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)
2 changes: 2 additions & 0 deletions lib/solaar/gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
from solaar import dbus
from solaar import listener
from solaar import ui
from solaar.custom_logger import CustomLogger

logging.setLoggerClass(CustomLogger)
logger = logging.getLogger(__name__)


Expand Down
Loading