Skip to content

Commit

Permalink
Use the logging module directly instead of home-grown code.
Browse files Browse the repository at this point in the history
This has the advantage of overall less custom code; as well as support
for per-module configuration. This would enable a potential solution for
ultrabug#1479, since in the future
it can allow per-module configuration of log levels.

I expect this to mainly help module creators, allowing them to enable
logging for only their module, while disabling all other messages. It
also is easier to use, since the `logging` module's interface is
generally simpler than `self.py3`.

Here, I've made the decision to keep the message format as close as
possible to the existing log messages.
  • Loading branch information
rlerm authored and lasers committed Jan 21, 2024
1 parent 636f56e commit 35f16c4
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions py3status/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
"info": logging.INFO,
}

LOGGING_LEVELS = {
"error": logging.ERROR,
"warning": logging.WARNING,
"info": logging.INFO,
}

DBUS_LEVELS = {"error": "critical", "warning": "normal", "info": "low"}

CONFIG_SPECIAL_SECTIONS = [
Expand Down Expand Up @@ -531,27 +537,6 @@ def load_modules(self, modules_list, user_modules):

def _setup_logging(self):
"""Set up the global logger."""
log_config = self.config.get("log_config")
if log_config:
if self.config.get("debug"):
self.report_exception("--debug is invalid when --log-config is passed")
if self.config.get("log_file"):
self.report_exception(
"--log-file is invalid when --log-config is passed"
)

with log_config.open() as f:
import logging.config

try:
config_dict = load(f, strict=False)
logging.config.dictConfig(config_dict)
except JSONDecodeError as e:
self.report_exception(str(e))
# Nothing else to do. All logging config is provided by the config
# dictionary.
return

root = logging.getLogger(name=None)
if self.config.get("debug"):
root.setLevel(logging.DEBUG)
Expand Down

0 comments on commit 35f16c4

Please sign in to comment.