mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-09-30 19:33:45 +08:00
Error logs
This commit is contained in:
+19
-1
@@ -2,6 +2,7 @@
|
||||
import os
|
||||
import sentry_sdk
|
||||
import traceback
|
||||
from datetime import datetime
|
||||
from enum import Enum
|
||||
from sentry_sdk.integrations.threading import ThreadingIntegration
|
||||
|
||||
@@ -11,6 +12,8 @@ from openpilot.system.hardware import HARDWARE, PC
|
||||
from openpilot.common.swaglog import cloudlog
|
||||
from openpilot.system.version import get_build_metadata, get_version
|
||||
|
||||
from openpilot.frogpilot.common.frogpilot_variables import ERROR_LOGS_PATH
|
||||
|
||||
|
||||
class SentryProject(Enum):
|
||||
# python project
|
||||
@@ -35,7 +38,7 @@ def capture_block() -> None:
|
||||
sentry_sdk.flush()
|
||||
|
||||
|
||||
def capture_exception(*args, **kwargs) -> None:
|
||||
def capture_exception(*args, crash_log=True, **kwargs) -> None:
|
||||
exc_text = traceback.format_exc()
|
||||
|
||||
errors_to_ignore = [
|
||||
@@ -44,6 +47,7 @@ def capture_exception(*args, **kwargs) -> None:
|
||||
if any(error in exc_text for error in errors_to_ignore):
|
||||
return
|
||||
|
||||
save_exception(exc_text, crash_log)
|
||||
cloudlog.error("crash", exc_info=kwargs.get('exc_info', 1))
|
||||
|
||||
try:
|
||||
@@ -57,6 +61,20 @@ def set_tag(key: str, value: str) -> None:
|
||||
sentry_sdk.set_tag(key, value)
|
||||
|
||||
|
||||
def save_exception(exc_text: str, crash_log) -> None:
|
||||
files = [
|
||||
ERROR_LOGS_PATH / datetime.now().astimezone().strftime("%Y-%m-%d--%H-%M-%S.log"),
|
||||
ERROR_LOGS_PATH / "error.txt"
|
||||
]
|
||||
|
||||
for file_path in files:
|
||||
if file_path.name == "error.txt" and crash_log:
|
||||
lines = exc_text.splitlines()[-10:]
|
||||
file_path.write_text("\n".join(lines))
|
||||
else:
|
||||
file_path.write_text(exc_text)
|
||||
|
||||
|
||||
def init(project: SentryProject) -> bool:
|
||||
build_metadata = get_build_metadata()
|
||||
# forks like to mess with this, so double check
|
||||
|
||||
Reference in New Issue
Block a user