-
Notifications
You must be signed in to change notification settings - Fork 4
Added external logging #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nederer
wants to merge
3
commits into
community-of-python:main
Choose a base branch
from
nederer:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 +1,4 @@ | ||
from __future__ import annotations | ||
from future import annotations | ||
import logging | ||
import logging.handlers | ||
import time | ||
|
@@ -71,18 +71,29 @@ def tracer_injection(_: WrappedLogger, __: str, event_dict: EventDict) -> EventD | |
return event_dict | ||
|
||
|
||
DEFAULT_STRUCTLOG_PROCESSORS: typing.Final[list[typing.Any]] = [ | ||
structlog.stdlib.filter_by_level, | ||
structlog.stdlib.add_log_level, | ||
DEFAULT_STRUCTLOG_PRE_CHAIN_PROCESSORS: typing.Final[list[typing.Any]] = [ | ||
structlog.stdlib.add_logger_name, | ||
tracer_injection, | ||
structlog.stdlib.add_log_level, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Трейсинг будет полезен во всех логах |
||
structlog.stdlib.PositionalArgumentsFormatter(), | ||
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S"), | ||
structlog.processors.StackInfoRenderer(), | ||
structlog.processors.format_exc_info, | ||
] | ||
DEFAULT_STRUCTLOG_PROCESSORS: typing.Final[list[typing.Any]] = [ | ||
*DEFAULT_STRUCTLOG_PRE_CHAIN_PROCESSORS, | ||
structlog.stdlib.filter_by_level, | ||
tracer_injection, | ||
structlog.processors.UnicodeDecoder(), | ||
] | ||
DEFAULT_STRUCTLOG_FORMATTER_PROCESSOR: typing.Final = structlog.processors.JSONRenderer(serializer=orjson.dumps) | ||
|
||
|
||
def _serialize_log_with_orjson_to_string(value: typing.Any, **kwargs: typing.Any) -> str: # noqa: ANN401 | ||
return orjson.dumps(value, **kwargs).decode() | ||
|
||
|
||
DEFAULT_STRUCTLOG_FORMATTER_PROCESSOR: typing.Final = structlog.processors.JSONRenderer( | ||
serializer=_serialize_log_with_orjson_to_string | ||
) | ||
|
||
|
||
class MemoryLoggerFactory(structlog.stdlib.LoggerFactory): | ||
|
@@ -150,6 +161,8 @@ def bootstrap(self) -> None: | |
for unset_handlers_logger in self.instrument_config.logging_unset_handlers: | ||
logging.getLogger(unset_handlers_logger).handlers = [] | ||
|
||
stream_handler: typing.Final = logging.StreamHandler() | ||
root_logger: typing.Final = logging.getLogger() | ||
structlog.configure( | ||
Comment on lines
+164
to
+165
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Давай поместим ниже, перед |
||
processors=[ | ||
*DEFAULT_STRUCTLOG_PROCESSORS, | ||
|
@@ -165,6 +178,17 @@ def bootstrap(self) -> None: | |
wrapper_class=structlog.stdlib.BoundLogger, | ||
cache_logger_on_first_use=True, | ||
) | ||
stream_handler.setFormatter( | ||
structlog.stdlib.ProcessorFormatter( | ||
foreign_pre_chain=[ | ||
*DEFAULT_STRUCTLOG_PRE_CHAIN_PROCESSORS, | ||
structlog.stdlib.ProcessorFormatter.remove_processors_meta, | ||
], | ||
processors=[structlog.processors.JSONRenderer()], | ||
logger=root_logger, | ||
) | ||
) | ||
root_logger.addHandler(stream_handler) | ||
|
||
@classmethod | ||
def get_config_type(cls) -> type[LoggingConfig]: | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему?