Skip to content

Commit

Permalink
Update to work with most recent SSV node version.
Browse files Browse the repository at this point in the history
  • Loading branch information
JKincorperated committed Jul 1, 2024
1 parent 39dcc80 commit 01ef255
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 23 deletions.
26 changes: 9 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,20 @@ python3 -m pip install ssvlogger

## How to use

### With docker

To tell docker to use journal as its log engine you can append `--log-driver=journald` to the docker run command.

This is an example command you could use
In both cases omit the `-f` to process all available logs, not just follow the current logs.

```bash
docker run --restart unless-stopped --name ssv_node -e \
.... # other flags
--log-driver=journald \ # This is to set up journal as the logging handler for docker
-it "bloxstaking/ssv-node:latest" make BUILD_PATH="/go/bin/ssvnode" start-node
```

After you have configure docker, you can view live logs from the SSV node with this command (assuming you have named the container "ssv_node"):
`journalctl CONTAINER_NAME=ssv_node -f`
### With docker

To use the logger you can pipe the output into the python script using:
`journalctl CONTAINER_NAME=ssv_node -f | ssvlogger`
`docker logs -f ssv_node | ssvlogger`

### Without docker

If you do not use docker it will only work as a service, assuming you have a service called "ssv_node" you should run
`journalctl -u ssv_node -f | ssvlogger`
`journalctl -u ssv_node -f | ssvlogger -j`

Or you could use:

`journalctl -u ssv_node -f --output cat | ssvlogger`

## Additional Flags

Expand All @@ -47,3 +38,4 @@ You can also use different flags to disable or enable certain features in the sc
|-|-|-|
|**-n**|--no-spam|Disables connection and registry event logs
|**-t**|--traceback|Shows tracebacks for errors
|**-j**|--journal|
84 changes: 78 additions & 6 deletions src/ssvlogger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
"""A simple python string to parse SSV node logs and make them legible"""

# pylint: disable=C0103, C0301, W0718, R1702
# pylint: disable=too-many-locals,too-many-branches,too-many-statements


import sys
import json
import colorama

def extract_time_and_stat(log):
def extract_time_and_stat(log, DOCKER_MODE):
"""Extracts time and status from a log"""
time = log[0].split(': ', maxsplit=1)[1]
time = log[0].split(': ', maxsplit=1)[1] if not DOCKER_MODE else log[0]
time = time.replace('T', ' ').split('.', maxsplit=1)[0]
time = colorama.Fore.CYAN + time + colorama.Fore.RESET

Expand All @@ -28,8 +30,6 @@ def extract_time_and_stat(log):

return time, stat

# pylint: disable=too-many-locals,too-many-branches,too-many-statements

def main():
"""Error handling function and soft exit"""

Expand All @@ -48,17 +48,21 @@ def main_function():
colorama.init()
NOSPAM = False
FULLERRORS = False
DOCKER_MODE = False

if "--no-spam" in sys.argv or "-n" in sys.argv:
NOSPAM = True

if "--traceback" in sys.argv or "-t" in sys.argv:
FULLERRORS = True

if "--journal" in sys.argv or "-j" in sys.argv:
DOCKER_MODE = True

additional_logs = []

for line in sys.stdin:
log = line.strip().split(" ")
log = line.strip().replace(" ", "\t").split("\t")

if "systemd[1]" in line: # Ignore systemd messages
continue
Expand All @@ -68,7 +72,7 @@ def main_function():

# Time and information recovery

time, stat = extract_time_and_stat(log)
time, stat = extract_time_and_stat(log, DOCKER_MODE)

try:
# P2P network
Expand Down Expand Up @@ -121,6 +125,16 @@ def main_function():
tolog = f"Connected to execution client at {colorama.Fore.LIGHTMAGENTA_EX}" + \
f"{data['address']}{colorama.Fore.RESET} in {data['took']}"

elif log[2] == "execution_client" and log[3] == "reconnecting":
data = json.loads(log[4])
tolog = f"Reconnecting to execution client at {colorama.Fore.LIGHTMAGENTA_EX}" + \
f"{data['address']}{colorama.Fore.RESET}"

elif log[2] == "execution_client" and log[3] == "could not reconnect, still trying":
data = json.loads(log[4])
tolog = f"Reconnecting to execution client at {colorama.Fore.LIGHTMAGENTA_EX}" + \
f"{data['address']}{colorama.Fore.RESET} ({data['error']})"

# EventSyncer

elif log[2] == "EventSyncer" and log[3] == "subscribing to ongoing registry events":
Expand Down Expand Up @@ -149,6 +163,20 @@ def main_function():
tolog = f"Failed to submit {colorama.Fore.CYAN}{data['handler']}{colorama.Fore.RESET} job.\n"
tolog += "Error: " + data['error'].replace('\\"', '"')

elif log[2] == "DutyScheduler" and log[3] == "could not find validator":
data = json.loads(log[4])
tolog = f"Failed to submit {colorama.Fore.CYAN}{data['handler']}{colorama.Fore.RESET} job " + \
f"for validator {data['pubkey'][:8]} due to non-existant validator."

elif log[2] == "DutyScheduler" and log[3].startswith("malformed event"):
data = json.loads(log[4])
tolog = f"Malformed Event: {log[3].split(":")[1].strip()}. Transaction hash: {data['tx_hash']}"

elif log[2] == "DutyScheduler" and "indices change received" in log[3]:
data = json.loads(log[4])
tolog = f"Received indices change {data['handler']}"


# Controller

elif log[2] == "Controller.Validator" and "starting duty processing" in log[3]:
Expand All @@ -168,6 +196,19 @@ def main_function():
tolog = "Sucessfully submitted attestation at slot " + \
f"{colorama.Fore.LIGHTMAGENTA_EX}{slot}{colorama.Fore.RESET}" + \
f" for validator {colorama.Fore.LIGHTMAGENTA_EX}{validator}{colorama.Fore.RESET}"

elif log[2] == "Controller.Validator" and "got beacon block proposal" in log[3]:
data = json.loads(log[4])
role = data["role"]
slot = data["slot"]
validator = data["pubkey"][:6] + "..."
tolog = f"Processing {colorama.Fore.LIGHTMAGENTA_EX}{role}{colorama.Fore.RESET}" + \
f" duty at slot {colorama.Fore.LIGHTMAGENTA_EX}{slot}{colorama.Fore.RESET}" + \
f" for validator {colorama.Fore.LIGHTMAGENTA_EX}{validator}{colorama.Fore.RESET}"

elif log[2] == "Controller.TaskExecutor" and "removed validator" in log[3]:
data = json.loads(log[4])
tolog = f"Removing validator {colorama.Fore.RED}{data['pubkey'][:8]}{colorama.Fore.RESET}"

elif log[2] == "Controller" and log[3] == "starting validators setup...":
data = json.loads(log[4])
Expand Down Expand Up @@ -203,6 +244,32 @@ def main_function():
additional_logs.append(f"Failed to initialize {colorama.Fore.RED}{data['failures']}" + \
f"{colorama.Fore.RESET} validator{'s' if data['failures'] != 1 else ''}")

elif log[2] == "Controller" and log[3] == "failed to update validators metadata":
data = json.loads(log[4])
tolog = "Failed to update validator metadata"

elif log[2] == "Controller" and "dropping message because the queue is full" in log[3]:
data = json.loads(log[4])
tolog = f"Dropping {data['msg_type']} message because the queue is full."

elif log[2] == "Controller" and "starting new validator" in log[3]:
data = json.loads(log[4])
tolog = f"Starting new validator {colorama.Fore.MAGENTA}{data['pubKey'][:8]}{colorama.Fore.RESET}"

# EventHandler

elif log[2] == "EventHandler" and log[3] == "unknown event name":
data = json.loads(log[4])
tolog = f"Ignoring unknown event {colorama.Fore.RED}{data['name']}{colorama.Fore.RESET}"

elif log[2] == "EventHandler" and "malformed event: " in log[3]:
data = json.loads(log[4])
tolog = f"Malformed Event: {log[3].split(':')[1].strip()}. Transaction hash: {data['tx_hash']}"

elif log[2] == "EventHandler" and "could not parse event" in log[3]:
data = json.loads(log[4])
tolog = f"Failed to parse event {data['event']}"

# Miscellaneous log handling

elif log[2] == "setting ssv network":
Expand All @@ -224,6 +291,11 @@ def main_function():
tolog = f"Set up operator key ({colorama.Fore.MAGENTA}{data['pubkey'][16:]}" + \
f"{colorama.Fore.RESET})"

elif log[2] == "successfully loaded operator keys":
data = json.loads(log[3])
tolog = f"Loaded operator key ({colorama.Fore.MAGENTA}{data['pubkey'][16:]}" + \
f"{colorama.Fore.RESET})"

elif log[2] == "consensus client: connecting":
data = json.loads(log[3])
tolog = f"Connecting to consensus client at {colorama.Fore.MAGENTA}" + \
Expand Down

0 comments on commit 01ef255

Please sign in to comment.