Skip to content

Commit

Permalink
Define order on log messages and use in web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ties committed Dec 11, 2023
1 parent cbe9c86 commit 048d851
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2023-12-11

* Add a stable sort for event log items and use it in the web
index page.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
exclude MANIFEST.in
exclude poetry.lock
exclude CHANGELOG.md
exclude .pre-commit-config.yaml
exclude .flake8
exclude .dockerignore
Expand Down
5 changes: 1 addition & 4 deletions sagemcom_f3896_client/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import asyncio
import logging
import operator
import time
from contextlib import asynccontextmanager
from contextvars import ContextVar
Expand Down Expand Up @@ -173,9 +172,7 @@ async def modem_event_log(self) -> List[EventLogItem]:
async with self.__request("GET", "/rest/v1/cablemodem/eventlog") as resp:
res = await resp.json()
return sorted(
[EventLogItem.build(e) for e in res["eventlog"]],
key=operator.attrgetter("time"),
reverse=True,
(EventLogItem.build(e) for e in res["eventlog"]), reverse=True
)

async def modem_service_flows(self) -> List[ModemServiceFlowResult]:
Expand Down
8 changes: 7 additions & 1 deletion sagemcom_f3896_client/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ def build(body: Dict[str, str]) -> "UserTokenResult":
)


@dataclass
@dataclass(order=True, frozen=True)
class EventLogItem:
"""Event log elements.
Sorted by time, priority, message (field order).
Is hashable because it's frozen.
"""

time: datetime.datetime
priority: Literal["error", "notice", "critical", "warning"]
message: str
Expand Down

0 comments on commit 048d851

Please sign in to comment.