Skip to content

Commit

Permalink
Change logging to match GitHub Actions messages
Browse files Browse the repository at this point in the history
I've changed the logging format to match the format of Github Actions
messages. This means that logging messages, which will only be emitted
sparingly in production, will be added as annotations to the workflow to
make them obvious to the end user.

Note: logging.INFO level messages will get the label "debug", as Github
Actions only has three levels: debug, warning, error.
  • Loading branch information
SebastiaanZ committed Dec 9, 2020
1 parent 00b98cc commit c6e7be4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions github_status_embed/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, *args, masked_values: typing.Sequence[str], **kwargs) -> None
super().__init__(*args, **kwargs)
self._masked_values = masked_values

def format(self, record: logging.LogRecord) -> None:
def format(self, record: logging.LogRecord) -> str:
"""Emit a logging record after masking certain values."""
message = super().format(record)
for masked_value in self._masked_values:
Expand All @@ -24,9 +24,14 @@ def setup_logging(level: int, masked_values: typing.Sequence[str]) -> None:
root = logging.getLogger()
root.setLevel(level)

logging.addLevelName(logging.DEBUG, 'debug')
logging.addLevelName(logging.INFO, 'debug') # GitHub Actions does not have an "info" message
logging.addLevelName(logging.WARNING, 'warning')
logging.addLevelName(logging.ERROR, 'error')

handler = logging.StreamHandler(sys.stdout)
formatter = MaskingFormatter(
'%(asctime)s :: %(name)s :: %(levelname)s :: %(message)s',
'::%(levelname)s::%(message)s',
datefmt="%Y-%m-%d %H:%M:%S",
masked_values=masked_values,
)
Expand Down

0 comments on commit c6e7be4

Please sign in to comment.