Skip to content

Commit

Permalink
Simplify logging configuration (#167)
Browse files Browse the repository at this point in the history
Also, by default, skips printing tracebacks on frequent tracing
connection issues.
  • Loading branch information
hluk committed Feb 19, 2024
1 parent b429663 commit 676f89f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
8 changes: 5 additions & 3 deletions waiverdb/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: GPL-2.0+

import logging.config as logging_config
import os

try:
Expand All @@ -15,7 +16,6 @@
import requests

from waiverdb.events import publish_new_waiver
from waiverdb.logger import init_logging
from waiverdb.tracing import init_tracing
from waiverdb.api_v1 import api_v1, oidc
from waiverdb.models import db
Expand Down Expand Up @@ -95,6 +95,9 @@ def create_app(config_obj=None):
if app.config['PRODUCTION'] and app.secret_key == 'replace-me-with-something-random': # nosec
raise Warning("You need to change the app.secret_key value for production")

log_config = app.config["LOGGING"]
logging_config.dictConfig(log_config)

# register error handlers
for code in default_exceptions.keys():
app.register_error_handler(code, json_error)
Expand All @@ -105,8 +108,7 @@ def create_app(config_obj=None):
if 'OIDC' in auth_methods(app):
oidc.init_app(app)
app.oidc = oidc
# initialize logging
init_logging(app)

# initialize db
db.init_app(app)
# initialize tracing
Expand Down
34 changes: 32 additions & 2 deletions waiverdb/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Config(object):
"""
DEBUG = True
DATABASE_URI = 'postgresql+psycopg2:///waiverdb'
# We configure logging explicitly, turn off the Flask-supplied log handler.
LOGGER_HANDLER_POLICY = 'never'
HOST = '127.0.0.1'
PORT = 5004
PRODUCTION = False
Expand Down Expand Up @@ -44,6 +42,38 @@ class Config(object):
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_SAMESITE = "Lax"

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'loggers': {
'waiverdb': {
'level': 'INFO',
},
# Skip printing tracebacks on frequent tracing connection issues
'opentelemetry.sdk.trace.export': {
'level': 'CRITICAL',
},
},
'handlers': {
'console': {
'formatter': 'bare',
'class': 'logging.StreamHandler',
'stream': 'ext://sys.stdout',
'level': 'DEBUG',
},
},
'formatters': {
'bare': {
# Drop timestamp and process ID, already included in Apache logs
'format': '[%(levelname)s] %(name)s: %(message)s',
}
},
'root': {
'level': 'INFO',
'handlers': ['console'],
},
}


class ProductionConfig(Config):
DEBUG = False
Expand Down
32 changes: 0 additions & 32 deletions waiverdb/logger.py

This file was deleted.

0 comments on commit 676f89f

Please sign in to comment.