Skip to content

Commit 8b3935a

Browse files
authored
fix(logging): update how get_logger sets logging level to support int (#26)
* fix(logging): update how get_logger sets logging level to support int based log level env variable. * chore: bump up version for release.
1 parent 11cb2b1 commit 8b3935a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

python/model_hosting_container_standards/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
- FastAPI: from .common.fastapi import EnvVars, ENV_CONFIG
66
"""
77

8-
__version__ = "0.1.8"
8+
__version__ = "0.1.9"

python/model_hosting_container_standards/logging_config.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ def get_logger(name: str = "model_hosting_container_standards") -> logging.Logge
1919
# Only configure if not already configured
2020
if not logger.handlers:
2121
# Get log level from environment, default to ERROR (effectively disabled)
22+
# Convert level to uppercase
2223
level = os.getenv(
2324
"SAGEMAKER_CONTAINER_LOG_LEVEL", os.getenv("LOG_LEVEL", "ERROR")
24-
)
25+
).upper()
2526

2627
# Set up handler with consistent format
2728
handler = logging.StreamHandler(sys.stdout)
@@ -30,7 +31,11 @@ def get_logger(name: str = "model_hosting_container_standards") -> logging.Logge
3031
)
3132
handler.setFormatter(formatter)
3233
logger.addHandler(handler)
33-
logger.setLevel(getattr(logging, level.upper()))
34+
35+
# Convert numeric log level string to int so `setLevel` can recognize it
36+
# Will raise error if the set log level is not registered in
37+
# logging.getLevelNamesMapping()
38+
logger.setLevel(int(level) if level.isdigit() else level.upper())
3439

3540
# Prevent propagation to avoid duplicate logs
3641
logger.propagate = False

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "model-hosting-container-standards"
3-
version = "0.1.8"
3+
version = "0.1.9"
44
description = "Python toolkit for standardized model hosting container implementations with Amazon SageMaker integration"
55
authors = ["Amazon Web Services"]
66
readme = "README.md"

0 commit comments

Comments
 (0)