Skip to content

Commit

Permalink
fix(cluster): fix how to render bot log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Feb 8, 2025
1 parent 7cffbf2 commit 12c1d96
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion silverback/cluster/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,21 @@ class BotInfo(BaseModel):


class BotLogEntry(BaseModel):
# TODO: Fix logs w/ Cluster, remove defaults here
level: LogLevel = LogLevel.INFO
timestamp: datetime | None = None
message: str

def __str__(self) -> str:
return f"{self.timestamp} [{self.level}]: {self.message}"
# TODO: Once defaults are removed, put timestamp directly in
if self.timestamp:
timestamp_str = f"{self.timestamp:%x %X} "
else:
timestamp_str = ""

# NOTE: Add offset (20+8+2=30) to all lines in message after the first
message = self.message.replace("\n", " " * 30 + "\n")

# NOTE: Max size of `LogLevel` is 8 chars
# NOTE: Max size of timestamp is 19 chars (plus 1 extra space)
return f"{timestamp_str:<20}{self.level.name:>8}: {message}"

0 comments on commit 12c1d96

Please sign in to comment.