Skip to content

Commit 897867c

Browse files
author
arch
committed
improve logging
1 parent b759d1e commit 897867c

File tree

2 files changed

+41
-7
lines changed

2 files changed

+41
-7
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@
1111
from queue import Queue
1212
from pynput.keyboard import Key, Listener
1313
from dataclasses import dataclass
14-
from funscript_editor.data.funscript import Funscript
15-
from funscript_editor.algorithms.videotracker import StaticVideoTracker
1614
from PyQt5 import QtGui, QtCore, QtWidgets
1715
from matplotlib.figure import Figure
18-
from funscript_editor.utils.config import HYPERPARAMETER, SETTINGS, PROJECTION
1916
from datetime import datetime
20-
from funscript_editor.data.ffmpegstream import FFmpegStream, VideoInfo
21-
from funscript_editor.algorithms.kalmanfilter import KalmanFilter2D
2217
from scipy.interpolate import interp1d
2318

19+
from funscript_editor.algorithms.kalmanfilter import KalmanFilter2D
20+
from funscript_editor.algorithms.videotracker import StaticVideoTracker
21+
from funscript_editor.data.ffmpegstream import FFmpegStream, VideoInfo
22+
from funscript_editor.data.funscript import Funscript
23+
from funscript_editor.utils.config import HYPERPARAMETER, SETTINGS, PROJECTION
24+
from funscript_editor.utils.logging import get_logfiles_paths
25+
from funscript_editor.definitions import SETTINGS_CONFIG_FILE, HYPERPARAMETER_CONFIG_FILE
26+
2427
import funscript_editor.algorithms.signalprocessing as sp
2528
import numpy as np
2629
import matplotlib.pyplot as plt
@@ -997,5 +1000,7 @@ def run(self) -> None:
9971000
self.finished(status, True)
9981001
except Exception as ex:
9991002
self.logger.critical("The program crashed due to a fatal error. " \
1000-
+ "Please open an issue on github with the corresponding log file and application configuration", exc_info=ex)
1003+
+ "Please open an issue on github with the corresponding log file (" \
1004+
+ ','.join(get_logfiles_paths()) + ") and application configuration (" \
1005+
+ SETTINGS_CONFIG_FILE + ", " + HYPERPARAMETER_CONFIG_FILE + ")", exc_info=ex)
10011006
self.finished("The program crashed due to a fatal error", False)

funscript_editor/utils/logging.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,35 @@ def create_log_directories(config: dict) -> None:
2121
if k == 'filename':
2222
os.makedirs(os.path.dirname(os.path.abspath(config[k])), exist_ok=True)
2323

24+
25+
def get_log_config_path() -> str:
26+
""" Get the log config file path for current platfrom
27+
28+
Returns:
29+
str: the log config file path
30+
"""
31+
return WINDOWS_LOG_CONFIG_FILE if platform.system() == 'Windows' else LINUX_LOG_CONFIG_FILE
32+
33+
34+
def get_logfiles_paths() -> list:
35+
""" Get the logfiles paths from log config
36+
37+
Returns:
38+
list: all logiles paths
39+
"""
40+
try:
41+
result = []
42+
config_path = get_log_config_path()
43+
with open(config_path, 'rt') as f:
44+
for line in f.readlines():
45+
if "filename:" in line:
46+
result.append(line.split(':')[1].strip())
47+
48+
return result
49+
except:
50+
return []
51+
52+
2453
def setup_logging(
2554
default_level :int = logging.INFO,
2655
env_key :str = 'LOG_CFG') -> None:
@@ -30,7 +59,7 @@ def setup_logging(
3059
default_level (int): logging level e.g. `logging.INFO` (default is `logging.DEBUG`).
3160
env_key (str, optional): env variable name to load a configuration file via environment variable (default is `LOG_CFG`).
3261
"""
33-
config_path = WINDOWS_LOG_CONFIG_FILE if platform.system() == 'Windows' else LINUX_LOG_CONFIG_FILE
62+
config_path = get_log_config_path()
3463
value = os.getenv(env_key, None)
3564
if value: config_path = value
3665
if os.path.exists(config_path):

0 commit comments

Comments
 (0)