Skip to content

Commit

Permalink
refactor(cluster): fix log display (#210)
Browse files Browse the repository at this point in the history
* fix(cluster): display logs properly by prepending offset (not after)

* refactor(cluster): move logging offset to class var

* refactor(cluster): there is not CRITICAL log type
  • Loading branch information
fubuloubu authored Feb 15, 2025
1 parent 5fac1e3 commit fe617af
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions silverback/cluster/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,13 @@ class BotLogEntry(BaseModel):
r"""^
(?P<timestamp>\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z?)\s
(?:
(?P<level>DEBUG:\s\s\s|INFO:\s\s\s\s|SUCCESS:\s|WARNING:\s|ERROR:\s\s\s|CRITICAL:)\s
(?P<level>DEBUG:\s\s\s|INFO:\s\s\s\s|SUCCESS:\s|WARNING:\s|ERROR:\s\s\s)\s
)?
(?P<message>.*)$""",
re.VERBOSE,
)
# NOTE: Add offset (18+8+2=28) to all newlines in message after the first
LOGLINE_OFFSET: ClassVar[str] = "\n" + " " * 27 + "| "

level: LogLevel | None = None
timestamp: datetime | None = None
Expand Down Expand Up @@ -369,9 +371,8 @@ def __str__(self) -> str:
else:
timestamp_str = ""

# NOTE: Add offset (18+8+2=28) to all newlines in message after the first
if "\n" in (message := self.message):
message = (" " * 28 + "\n").join(message.split("\n"))
message = self.LOGLINE_OFFSET.join(message.split("\n"))

# NOTE: Max size of `LogLevel` is 8 chars
# NOTE: Max size of normalized timestamp is 18 chars
Expand Down

0 comments on commit fe617af

Please sign in to comment.