-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
log messages now identify the task instance doing the logging (#107)
* logging now identifies the task doing the logging
- Loading branch information
Phil Varner
authored
Apr 19, 2024
1 parent
e91a947
commit 5939ff3
Showing
3 changed files
with
24 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Any, Optional | ||
|
||
|
||
class TaskLoggerAdapter(logging.LoggerAdapter): # type: ignore | ||
def __init__(self, logger: logging.Logger, prefix: Optional[str]) -> None: | ||
super().__init__(logger, {}) | ||
self.prefix = prefix | ||
|
||
def process(self, msg: str, kwargs: Any) -> tuple[str, Any]: | ||
if self.prefix is not None: | ||
return f"[{self.prefix}] {msg}", kwargs | ||
else: | ||
return msg, kwargs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters