Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(application): Handle logging setup failure with basic configuration. #42

Merged
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:
li-ruihao marked this conversation as resolved.
Show resolved Hide resolved
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
Loading