Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
Co-authored-by: Filippo Luca Ferretti <102977828+flferretti@users.noreply.github.com>
  • Loading branch information
diegoferigo and flferretti committed May 17, 2024
1 parent 42a3430 commit 44068bc
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions src/rod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,21 @@ def get_default_logging_level(env_var: str) -> logging.LoggingLevel:

import os

# Define the default logging level depending on the installation mode.
default_logging_level = (
logging.LoggingLevel.DEBUG
if installation_is_editable()
else logging.LoggingLevel.WARNING
)

# Allow to override the default logging level with an environment variable.
try:
return logging.LoggingLevel[os.environ[env_var].upper()]

# Raise if the environment variable is set but the logging level is invalid.
except AttributeError:
msg = f"Invalid logging level defined in {env_var}: '{os.environ[env_var]}'"
raise ValueError(msg)

# If the environment variable is not set, return the logging level depending
# on the installation mode.
except KeyError:
return (
logging.LoggingLevel.DEBUG
if installation_is_editable()
else logging.LoggingLevel.WARNING
)
return logging.LoggingLevel[
os.environ.get(env_var, default_logging_level.name).upper()
]
except KeyError as exc:
msg = f"Invalid logging level defined in {env_var}='{os.environ[env_var]}'"
raise RuntimeError(msg) from exc


# Configure the logger with the default logging level.
Expand Down

0 comments on commit 44068bc

Please sign in to comment.