Skip to content

Commit

Permalink
fix(application): Handle logging setup failure with basic configurati…
Browse files Browse the repository at this point in the history
…on. (junhaoliao#42)
  • Loading branch information
li-ruihao authored Jan 9, 2025
1 parent 9b06e91 commit 313066c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions application/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
from werkzeug.exceptions import HTTPException
from werkzeug.serving import WSGIRequestHandler

logger = logging.getLogger(__name__)

try:
with open('log_config.yaml', 'r') as config_file:
with open('log_config.yaml') as config_file:
config = yaml.safe_load(config_file.read())
logging.config.dictConfig(config)
except Exception as ex:
print("Logging setup failed with exception = ", ex)

logger = logging.getLogger(__name__)
logger.warning(f"Logging is set up with config={config}")
except Exception:
# Fallback to a basic configuration
logging.basicConfig(format='%(asctime)s %(levelname)s [%(name)s:%(lineno)d] %(message)s', level=logging.INFO, force=True)
logger.exception("Logging setup failed")
else:
logger.warning("Logging setup is completed with config=%s", config)

from .Profile.Profile import Profile

Expand Down

0 comments on commit 313066c

Please sign in to comment.