This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Reload the pyo3-log config when the Python logging config changes. #14976
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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 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 @@ | ||
Fix a bug introduced in Synapse 1.68.0 where logging from the Rust module was not properly logged. |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
def sum_as_string(a: int, b: int) -> str: ... | ||
def get_rust_file_digest() -> str: ... | ||
def reset_logging_config() -> None: ... |
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 |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
|
||
from synapse.logging.context import LoggingContextFilter | ||
from synapse.logging.filter import MetadataFilter | ||
from synapse.synapse_rust import reset_logging_config | ||
from synapse.types import JsonDict | ||
|
||
from ..util import SYNAPSE_VERSION | ||
|
@@ -200,24 +201,6 @@ def _setup_stdlib_logging( | |
""" | ||
Set up Python standard library logging. | ||
""" | ||
if log_config_path is None: | ||
log_format = ( | ||
"%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s" | ||
" - %(message)s" | ||
) | ||
|
||
logger = logging.getLogger("") | ||
logger.setLevel(logging.INFO) | ||
logging.getLogger("synapse.storage.SQL").setLevel(logging.INFO) | ||
|
||
formatter = logging.Formatter(log_format) | ||
|
||
handler = logging.StreamHandler() | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
else: | ||
# Load the logging configuration. | ||
_load_logging_config(log_config_path) | ||
|
||
# We add a log record factory that runs all messages through the | ||
# LoggingContextFilter so that we get the context *at the time we log* | ||
|
@@ -237,6 +220,26 @@ def factory(*args: Any, **kwargs: Any) -> logging.LogRecord: | |
|
||
logging.setLogRecordFactory(factory) | ||
|
||
# Configure the logger with the initial configuration. | ||
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. I don't think this has to be moved, but since our logging generally assumes that a |
||
if log_config_path is None: | ||
log_format = ( | ||
"%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s" | ||
" - %(message)s" | ||
) | ||
|
||
logger = logging.getLogger("") | ||
logger.setLevel(logging.INFO) | ||
logging.getLogger("synapse.storage.SQL").setLevel(logging.INFO) | ||
|
||
formatter = logging.Formatter(log_format) | ||
|
||
handler = logging.StreamHandler() | ||
handler.setFormatter(formatter) | ||
logger.addHandler(handler) | ||
else: | ||
# Load the logging configuration. | ||
_load_logging_config(log_config_path) | ||
|
||
# Route Twisted's native logging through to the standard library logging | ||
# system. | ||
observer = STDLibLogObserver() | ||
|
@@ -294,6 +297,9 @@ def _load_logging_config(log_config_path: str) -> None: | |
|
||
logging.config.dictConfig(log_config) | ||
|
||
# Blow away the pyo3-log cache so that it reloads the configuration. | ||
reset_logging_config() | ||
|
||
|
||
def _reload_logging_config(log_config_path: Optional[str]) -> None: | ||
""" | ||
|
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
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.
I have no idea if this is safe / smart to do.
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.
I think this is fine! The Rust module is loaded after Python is started up, so can't see that being a problem.
And unless you write
unsafe
, I generally trust the Rust compiler to know what it's talking about with thread safety — it looks likereset
takes(&self)
and you're not mutating this afterwards, plus the Python GIL means it's all going to be single-threaded anyway ... I can't see why this should be concerning.