forked from deshaw/pyflyby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |