Skip to content

Commit

Permalink
standardise logging
Browse files Browse the repository at this point in the history
  • Loading branch information
samj committed Jul 20, 2024
1 parent 59ceff7 commit 2a1dc26
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
7 changes: 3 additions & 4 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@
logger = get_logger(__name__)

def handle_keyboard_interrupt(signum, frame):
print("Cleaning up...")
cleanup()
asyncio.get_event_loop().stop()

def cleanup():
# Perform any necessary cleanup here
logger.info("Performing cleanup tasks...")
logger.info("Performing cleanup tasks.")

if __name__ == "__main__":
# Set up signal handlers
#signal.signal(signal.SIGINT, handle_keyboard_interrupt)
#signal.signal(signal.SIGTERM, handle_keyboard_interrupt)

# Create the app
logger.info("Creating the app...")
logger.info("Creating the app.")
from app import create_app
app = create_app()

# Run the app
import uvicorn

logger.info("Running the app...")
logger.info("Running the app with uvicorn.")
try:
uvicorn.run("app:create_app", host="localhost", port=3080, factory=True, workers=1, reload=True, reload_dirs=[backend_dir], reload_excludes=[venv_dir], log_config=logging_config)
except KeyboardInterrupt:
Expand Down
2 changes: 1 addition & 1 deletion backend/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# use alembic to create the database or migrate to the latest schema
def init_db():
logger.info("Initializing database...")
logger.info("Initializing database.")
alembic_cfg = AlembicConfig()
os.makedirs(db_path.parent, exist_ok=True)
alembic_cfg.set_main_option("script_location", str(base_dir / "migrations"))
Expand Down
16 changes: 13 additions & 3 deletions common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"disable_existing_loggers": False,
"formatters": {
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
},
"uvicorn_default": {
"()": "uvicorn.logging.DefaultFormatter",
Expand All @@ -22,13 +22,22 @@

},
"handlers": {
# TODO: standardise formatting; for now use uvicorn_default
"default": {
#"formatter": "standard",
"formatter": "uvicorn_default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
"standard": {
"formatter": "standard",
#"formatter": "standard",
"formatter": "uvicorn_default",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
"uvicorn_default": {
"formatter": "uvicorn_default",
#"formatter": "standard",
"class": "logging.StreamHandler",
"stream": "ext://sys.stderr",
},
Expand All @@ -50,10 +59,11 @@
},
},
"loggers": {
"": {"handlers": ["standard"], "level": "INFO"}, # root logger
"": {"handlers": ["default"], "level": "INFO"}, # root logger
"connexion": {"handlers": ["connexion"], "level": "DEBUG", "propagate": False},
"uvicorn": {"handlers": ["uvicorn_default"], "level": "INFO", "propagate": False},
"uvicorn.error": {"level": "INFO"},
"uvicorn.access": {"handlers": ["access"], "level": "INFO", "propagate": False},
"watchfiles.main": {"level": "ERROR"}, # filter watchfiles noise
},
}

0 comments on commit 2a1dc26

Please sign in to comment.