|
12 | 12 | class Exception: |
13 | 13 |
|
14 | 14 | new_debug = True |
15 | | - debug = False |
16 | 15 | output = None |
17 | 16 | command = None |
18 | 17 |
|
19 | 18 | @classmethod |
20 | | - def init(cls, debug=False, output=None, command=None): |
| 19 | + def init(cls, output=None, command=None): |
21 | 20 | sys.excepthook = cls.exception_handler # set custom exception handler (uncaught exceptions) |
22 | 21 | cls.output = output |
23 | 22 | cls.command = command |
24 | | - cls.debug = True if debug else False |
25 | 23 |
|
26 | 24 | @classmethod |
27 | 25 | def exception(cls, message: str, e: Exception, tb=None): |
@@ -53,33 +51,32 @@ def exception(cls, message: str, e: Exception, tb=None): |
53 | 51 | "-------------------------" |
54 | 52 | ) |
55 | 53 | print(exception_message) |
56 | | - if cls.debug: |
57 | | - debug_file = os.path.join(cls.output, "waybackup_error.log") |
58 | | - print(f"Exception log: {debug_file}") |
59 | | - print("-------------------------") |
60 | | - print(f"Full traceback:\n{original_tb}") |
61 | | - if cls.new_debug: # new run, overwrite file |
62 | | - cls.new_debug = False |
63 | | - f = open(debug_file, "w") |
64 | | - f.write("-------------------------\n") |
65 | | - f.write(f"Version: {__version__}\n") |
66 | | - f.write("-------------------------\n") |
67 | | - f.write(f"Command: {cls.command}\n") |
68 | | - f.write("-------------------------\n\n") |
69 | | - else: # current run, append to file |
70 | | - f = open(debug_file, "a") |
71 | | - f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n") |
72 | | - f.write(exception_message + "\n") |
73 | | - f.write("!-- Local Variables:\n") |
74 | | - for var_name, value in local_vars.items(): |
75 | | - if var_name in ["status_message", "headers"]: |
76 | | - continue |
77 | | - value = cls.relativate_path(str(value)) |
78 | | - value = value[:666] + " ... " if len(value) > 666 else value |
79 | | - f.write(f" -- {var_name} = {value}\n") |
| 54 | + debug_file = os.path.join(cls.output, "waybackup_error.log") |
| 55 | + print(f"Exception log: {debug_file}") |
| 56 | + # print("-------------------------") |
| 57 | + # print(f"Full traceback:\n{original_tb}") |
| 58 | + if cls.new_debug: # new run, overwrite file |
| 59 | + cls.new_debug = False |
| 60 | + f = open(debug_file, "w") |
80 | 61 | f.write("-------------------------\n") |
81 | | - f.write(original_tb + "\n") |
82 | | - f.close() |
| 62 | + f.write(f"Version: {__version__}\n") |
| 63 | + f.write("-------------------------\n") |
| 64 | + f.write(f"Command: {cls.command}\n") |
| 65 | + f.write("-------------------------\n\n") |
| 66 | + else: # current run, append to file |
| 67 | + f = open(debug_file, "a") |
| 68 | + f.write(datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "\n") |
| 69 | + f.write(exception_message + "\n") |
| 70 | + f.write("!-- Local Variables:\n") |
| 71 | + for var_name, value in local_vars.items(): |
| 72 | + if var_name in ["status_message", "headers"]: |
| 73 | + continue |
| 74 | + value = cls.relativate_path(str(value)) |
| 75 | + value = value[:666] + " ... " if len(value) > 666 else value |
| 76 | + f.write(f" -- {var_name} = {value}\n") |
| 77 | + f.write("-------------------------\n") |
| 78 | + f.write(original_tb + "\n") |
| 79 | + f.close() |
83 | 80 |
|
84 | 81 | @classmethod |
85 | 82 | def relativate_path(cls, input: str) -> str: |
|
0 commit comments