Skip to content

Commit

Permalink
feat: format logger
Browse files Browse the repository at this point in the history
  • Loading branch information
pmareke committed Sep 26, 2024
1 parent 8f0f104 commit c20b05e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@asynccontextmanager
async def lifespan(_app: FastAPI) -> AsyncGenerator:
setup_logging()
logger = logging.getLogger(__name__)
logger = logging.getLogger("server")
logger.info("Starting FastAPI server...")

yield
Expand Down
9 changes: 8 additions & 1 deletion src/common/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@


def setup_logging() -> None:
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger("server")
logger.setLevel(logging.INFO)
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)
format = "%(levelname)s: %(asctime)s - %(message)s"
formatter = logging.Formatter(format)
ch.setFormatter(formatter)
logger.addHandler(ch)
2 changes: 1 addition & 1 deletion src/use_cases/health_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def message(self) -> bool:


class HealthCommandHandler(CommandHandler):
def __init__(self, logger: Logger = logging.getLogger(__name__)) -> None:
def __init__(self, logger: Logger = logging.getLogger("server")) -> None:
self._logger = logger

def execute(self, command: HealthCommand) -> HealthCommandResponse:
Expand Down
2 changes: 1 addition & 1 deletion src/use_cases/say_hello_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class SayHelloCommandHandler(CommandHandler):
def __init__(
self,
hello_client: HelloClient,
logger: Logger = logging.getLogger(__name__),
logger: Logger = logging.getLogger("server"),
) -> None:
self._hello_client = hello_client
self._logger = logger
Expand Down

0 comments on commit c20b05e

Please sign in to comment.