-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add SpiderLoggerAdapter, change Spider.logger to return SpiderL…
…oggerAdapter
- Loading branch information
1 parent
5372c0b
commit bd43233
Showing
2 changed files
with
9 additions
and
18 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
import logging | ||
from typing import Any, Dict, Tuple | ||
from typing import Any, MutableMapping, Tuple | ||
|
||
|
||
class SpiderLoggerAdapter(logging.LoggerAdapter): | ||
def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict[str, Any]]: | ||
def process( | ||
self, msg: str, kwargs: MutableMapping[str, Any] | ||
) -> Tuple[str, MutableMapping[str, Any]]: | ||
"""Method that augments logging with additional 'extra' data""" | ||
extra = kwargs.get("extra") | ||
if not isinstance(extra, dict): | ||
kwargs["extra"] = self.extra | ||
elif isinstance(self.extra, dict): | ||
if isinstance(kwargs.get("extra"), MutableMapping): | ||
kwargs["extra"].update(self.extra) | ||
else: | ||
kwargs["extra"] = self.extra | ||
|
||
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