Skip to content

Commit

Permalink
Merge pull request #348 from Clinical-Genomics/colored_logs_again
Browse files Browse the repository at this point in the history
Fixed colors in logging
  • Loading branch information
northwestwitch authored Sep 20, 2024
2 parents 75ca2a6 + b01741d commit c97555f
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Fixed
- Updated dependencies including `certifi` to address dependabot alert
- Update pytest to v.7.4.4 to address a `ReDoS` vulnerability
- Colored logs

## [1.9]
### Added
Expand Down
47 changes: 46 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ python-multipart = "^0.0.9"
schug = "1.6.0"
certifi = "^2024.7.4"
pytest = "7.4.4"
coloredlogs = "^15.0.1"

[tool.poetry.extras]
m1 = ["pyd4"]
Expand Down
17 changes: 6 additions & 11 deletions src/chanjo2/logger.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import logging

import uvicorn
import coloredlogs
from fastapi.applications import FastAPI

LOG = logging.getLogger(__name__)


def configure_log():
def configure_log(log: logging.Logger, app: FastAPI):
"""Configure logging."""
console_formatter = uvicorn.logging.ColourizedFormatter(
"{levelprefix} {asctime} : {message}", style="{", use_colors=True
)
if LOG.handlers:
LOG.handlers[0].setFormatter(console_formatter)
else:
logging.basicConfig()

current_log_level = log.getEffectiveLevel()
coloredlogs.install(level="DEBUG" if app.debug else current_log_level)
2 changes: 1 addition & 1 deletion src/chanjo2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def create_db_and_tables():

@asynccontextmanager
async def lifespan(app_: FastAPI):
configure_log()
configure_log(app=app, log=LOG)
LOG.info("Starting up...")
await startup_db()
yield
Expand Down

0 comments on commit c97555f

Please sign in to comment.