Skip to content

Commit

Permalink
fixed logger style varies for same identity
Browse files Browse the repository at this point in the history
  • Loading branch information
visualDust committed Nov 24, 2023
1 parent b8f9014 commit 7bcc1bd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
5 changes: 2 additions & 3 deletions neetbox/daemon/client/_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ def _init_ws():
# ws server url
ClientConn.ws_server_addr = f"ws://{cfg['host']}:{cfg['port'] + 1}{CLIENT_API_ROOT}"

# todo wait for server online
# create websocket app
logger.log(f"creating websocket connection to {ClientConn.ws_server_addr}")
# todo does run_forever reconnect after close?

ws = websocket.WebSocketApp(
ClientConn.ws_server_addr,
on_open=ClientConn.__on_ws_open,
Expand Down Expand Up @@ -148,7 +147,7 @@ def ws_send(event_type: str, payload):
NAME_NAME_KEY: ClientConn._display_name,
EVENT_TYPE_NAME_KEY: event_type,
PAYLOAD_NAME_KEY: payload,
EVENT_ID_NAME_KEY: -1, # todo
EVENT_ID_NAME_KEY: -1, # todo how does ack work
}
)
)
Expand Down
7 changes: 7 additions & 0 deletions neetbox/daemon/readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# DAEMON readme

## How to run server only

at neetbox project root:
```bash
python neetbox/daemon/server/_server.py
```

## WS message standard

websocke messages are described in json. There is a dataclass representing websocket message:
Expand Down
3 changes: 2 additions & 1 deletion neetbox/integrations/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import importlib
from enum import Enum
from functools import lru_cache
from typing import List, Optional

from neetbox.logging import logger
Expand All @@ -22,7 +23,7 @@ def __str__(self) -> str:
installed_engines: Optional[List] = None


# todo migrate to python 3.9 after frameworks are supporting it
@lru_cache
def get_supported_engines():
global supported_engines
if not supported_engines:
Expand Down
7 changes: 4 additions & 3 deletions neetbox/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ def log(

_style = self.style
if not _style: # if style not set
if _caller_identity in Logger.__WHOM_2_STYLE: # check for previous style
_style = Logger.__WHOM_2_STYLE[_caller_identity]
_style_index = str(_caller_identity)
if _style_index in Logger.__WHOM_2_STYLE: # check for previous style
_style = Logger.__WHOM_2_STYLE[_style_index]
else:
_style = LogStyle().randcolor()
Logger.__WHOM_2_STYLE[_caller_identity] = _style
Logger.__WHOM_2_STYLE[_style_index] = _style

raw_log = RawLog(
rich_msg=_pure_str_message,
Expand Down

0 comments on commit 7bcc1bd

Please sign in to comment.