Skip to content

Commit

Permalink
add log.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Oct 29, 2024
1 parent cc1198f commit 777eb6e
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import sys
import json

from dataclasses import dataclass
from pathlib import Path

from typing import Optional, Any

from rich.console import Console

console = Console()


@dataclass
class Entry:
taskName: Any
stack_info: Any
filename: str
funcName: str
levelname: str
module: str
name: str
pathname: str
process: int
lineno: int
thread: int
processName: str
threadName: str
message: str
time: str
msg: str

@property
def relpath(self):
cwd = Path(".").expanduser().absolute()
return "./" + str(Path(self.pathname).relative_to(Path(cwd)))

@property
def fm(self):
pass


ignore = """
_importdb.py:563
_importdb.py:345
_autoimp.py:513
"""

ign = ignore.strip().splitlines()

igns = []
nig = []

for line in open("logpipe", "r"):
from time import sleep

line = line.strip() # Remove any leading/trailing whitespace

if not line:
sleep(0.01)
continue
try:
# Attempt to parse the line as JSON
parsed_json = json.loads(line)

e = Entry(**parsed_json)
tag = f"{e.filename}:{e.lineno}"
if tag in ign:
igns.append(tag)
continue

nig.append(tag)

fmess = f"{e.relpath:>34}:{e.lineno:>4} {e.funcName:>25}: {e.message}"
try:
console.print(fmess)

except:
print(fmess)
except json.JSONDecodeError:
# If parsing fails, print the line as-is
pass
print(line)

from collections import Counter

for k, v in Counter(igns).items():
print(k, v)
print("Not ignored")
for k, v in Counter(nig).most_common(10):
print(k, v)

0 comments on commit 777eb6e

Please sign in to comment.