Skip to content

Commit

Permalink
feat($Loguru): set default log level as "INFO"
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Nov 13, 2021
1 parent e66050e commit 1b71e45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion home_guardian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
configure as thread_pool_configure,
)

application_configure()
loguru_configure()
thread_pool_configure()
application_configure()
10 changes: 7 additions & 3 deletions home_guardian/configuration/loguru_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from loguru import logger

from home_guardian.configuration.application_configuration import application_conf
from home_guardian.function_collection import get_data_dir

_message_format = (
Expand All @@ -16,9 +17,10 @@
logger.remove(handler_id=None)
# Set up logging
_log_file = get_data_dir() + "/logs/home_guardian.{time}.log"
log_level = application_conf.get_string("log_level")
logger.add(
_log_file,
level="DEBUG",
level=log_level,
format=_message_format,
enqueue=True,
# turn to false if in production to prevent data leaking
Expand All @@ -29,10 +31,12 @@
serialize=False,
)
# Override the default stderr
logger.add(sys.stderr, format=_message_format)
logger.add(sys.stderr, level=log_level, format=_message_format)


# Intercept standard logging https://gist.github.com/devsetgo/28c2edaca2d09e267dec46bb2e54b9e2


class InterceptHandler(logging.Handler):
def emit(self, record):
# Get corresponding Loguru level if it exists
Expand All @@ -59,4 +63,4 @@ def configure() -> None:
"""
Configure logging.
"""
logger.warning("Loguru logging configured")
logger.warning(f"Loguru logging configured, log_level: {log_level}")
2 changes: 2 additions & 0 deletions home_guardian/resources/application.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
log_level = "INFO"
log_level = ${?LOG_LEVEL}
email {
mail_host = "smtp.tom.com"
mail_port = 25
Expand Down

0 comments on commit 1b71e45

Please sign in to comment.