Skip to content

Commit

Permalink
Don't emit timestamps on log-format=plain
Browse files Browse the repository at this point in the history
This reverts to <= 0.12.0 behavior. The intent is to let the service
manager (e.g. systemd) handle logging, and thus it's desirable to avoid
timestamps being duplicated on e.g. the journald.
  • Loading branch information
paravoid committed Oct 3, 2024
1 parent b807e05 commit e0be5fa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions ircstream/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ def parse_args(argv: Sequence[str] | None) -> argparse.Namespace:
def configure_logging(log_format: str) -> None:
"""Configure logging parameters."""
renderer: structlog.typing.Processor
if log_format == "plain" or log_format == "console":
if log_format == "plain":
timestamper = None
renderer = structlog.dev.ConsoleRenderer(colors=False)
elif log_format == "console":
timestamper = structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=False)
enable_colors = log_format == "console"
renderer = structlog.dev.ConsoleRenderer(colors=enable_colors)
renderer = structlog.dev.ConsoleRenderer(colors=True)
elif log_format == "json":
timestamper = structlog.processors.TimeStamper(fmt="iso")
renderer = structlog.processors.JSONRenderer(sort_keys=True)
Expand All @@ -72,9 +74,11 @@ def configure_logging(log_format: str) -> None:
structlog.stdlib.add_logger_name,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
timestamper,
]

if timestamper:
processors.append(timestamper)

structlog.configure(
processors=[
*processors,
Expand Down

0 comments on commit e0be5fa

Please sign in to comment.