Skip to content

Commit 93be736

Browse files
committed
feat(debug): log debug contents into a file
1 parent 8fb8a38 commit 93be736

3 files changed

Lines changed: 28 additions & 2 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ del_*.ps1
144144
# VSCode stuff.
145145
.vscode
146146

147+
# Custom debug log
148+
ocsi_dbg_log*
149+
147150
# MacOS bundling tests
148151
*.dmg
149152
*.app

src/info.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
the UI functions.
55
"""
66
import json
7-
import platform
87
import os
8+
import platform
9+
import re
910
import sys
10-
import requests
1111

1212
dir_delim = "\\" if platform.system().lower() == "windows" else "/"
1313

@@ -72,13 +72,22 @@ def color_text(text, color):
7272
def format_text(text, formatting):
7373
formatting_list = formatting.split("+")
7474
final_string = text
75+
7576
for format in formatting_list:
7677
format_var = globals().get(format) if globals().get(format) else None
78+
7779
if format_var:
7880
final_string = f"{format_var}{final_string}"
81+
7982
final_string += end_formatting
83+
8084
return final_string
8185

86+
def clear_ansi(text):
87+
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
88+
89+
return ansi_escape.sub('', text)
90+
8291
surprise = f"""{cyan}
8392
__ __ ______ _ _____ _
8493
\ \ / / | ____| | | |_ _| |

src/util/debugger.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1+
import os
2+
3+
from src.info import AppInfo, clear_ansi
4+
5+
16
class DebuggerInst():
27
def __init__(self):
38
self.debug = None
9+
self.file = os.path.join(
10+
AppInfo.root_dir,
11+
'ocsi_dbg_log.txt'
12+
)
413

514
def log_dbg(self, contents = "\n"):
615
if not self.debug:
716
return
17+
18+
if self.file:
19+
with open(self.file, 'a') as file:
20+
file.write(clear_ansi(contents) + "\n")
21+
file.close()
822

923
print(contents)
1024

0 commit comments

Comments
 (0)