Skip to content

Commit

Permalink
Customising showwarning means actually doing, not formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyandrewmeyer committed Dec 18, 2024
1 parent a589f26 commit 3bd3f98
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ops/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ def setup_root_logging(
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(JujuLogHandler(model_backend))
logging.captureWarnings(True)

def custom_showwarning(
message: typing.Union[str, Warning],
category: typing.Type[Warning],
filename: str,
lineno: int,
*_: typing.Any,
) -> str:
"""Like the default showwarning, but don't include the code."""
return f'{filename}:{lineno}: {category.__name__}: {message}'
**__: typing.Any,
):
"""Direct the warning to Juju's debug-log, and don't include the code."""
logger.warning('%s:%s: %s: %s', filename, lineno, category.__name__, message)

warnings.showwarning = custom_showwarning

Expand Down

0 comments on commit 3bd3f98

Please sign in to comment.