mirror of
https://git.uzuy-edge.org/Uzuy-Edge/Uzuy
synced 2024-11-23 02:59:44 +00:00
49b663087c
- Introduced a Python-based tool for processing log files. - The tool removes unnecessary `<Info>` lines, focusing on device information, warnings, and errors. - Designed for easy integration into development workflows with drag-and-drop file selection. - Output is formatted for Discord, making it easy to share logs with relevant details.
45 lines
1.7 KiB
Python
45 lines
1.7 KiB
Python
import tkinter as tk
|
|
from tkinter import filedialog
|
|
|
|
def format_log_for_discord(log_data):
|
|
discord_message = "```ini\n" # Start with ini block for device info
|
|
|
|
# Iterate over log data lines and filter for device info, warnings, and errors
|
|
for line in log_data.splitlines():
|
|
# Remove lines with <Info>, and keep errors, warnings, and device info
|
|
if "<Info>" not in line and any(keyword in line for keyword in ["<Error>", "<Critical>", "<Warning>", "Device", "SoC", "Memory"]):
|
|
if "<Error>" in line or "<Critical>" in line:
|
|
discord_message += f"🛑 [ERROR] {line}\n"
|
|
elif "<Warning>" in line:
|
|
discord_message += f"⚠️ [WARNING] {line}\n"
|
|
else:
|
|
discord_message += f"{line}\n" # Keep device info in ini format
|
|
|
|
discord_message += "```\n" # Close ini block
|
|
return discord_message
|
|
|
|
def open_file_and_format():
|
|
# Open file dialog to select the log file
|
|
filepath = filedialog.askopenfilename(title="Select a log file")
|
|
|
|
if filepath:
|
|
with open(filepath, 'r') as file:
|
|
log_data = file.read()
|
|
|
|
formatted_log = format_log_for_discord(log_data)
|
|
|
|
# Show the formatted log in a new window (for copying)
|
|
output_window = tk.Tk()
|
|
output_window.title("Discord Formatted Log")
|
|
text_widget = tk.Text(output_window)
|
|
text_widget.insert(tk.END, formatted_log)
|
|
text_widget.pack(expand=True, fill=tk.BOTH)
|
|
output_window.mainloop()
|
|
|
|
# Set up the main Tkinter window
|
|
root = tk.Tk()
|
|
root.withdraw() # Hide the main window, only show file dialog
|
|
|
|
# Trigger file opening and formatting
|
|
open_file_and_format()
|