Skip to content

Commit 9e17ad3

Browse files
committed
(tweak) Add system hardware to logs
1 parent 3be3d9a commit 9e17ad3

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

BabbleApp/logger.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,41 @@
22
import logging
33
import os
44
import sys
5+
import platform
6+
import psutil
57

68
def strip_ansi_codes(text):
79
"""Remove ANSI color codes from a string."""
810
ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
911
return ansi_escape.sub('', text)
1012

13+
def log_system_info(logger):
14+
"""
15+
Logs basic system and hardware information to the provided logger.
16+
"""
17+
try:
18+
# Operating system details
19+
os_name = platform.system()
20+
os_version = platform.version()
21+
os_release = platform.release()
22+
machine = platform.machine()
23+
processor = platform.processor()
24+
25+
# CPU and Memory
26+
cpu_count = psutil.cpu_count(logical=True)
27+
total_memory = psutil.virtual_memory().total // (1024 ** 2) # Convert bytes to MB
28+
29+
logger.info("========== System Information ==========")
30+
logger.info(f"Operating System: {os_name} {os_release} (Version: {os_version})")
31+
logger.info(f"Architecture: {machine}")
32+
logger.info(f"Processor: {processor}")
33+
logger.info(f"Logical CPUs: {cpu_count}")
34+
logger.info(f"Total Memory: {total_memory} MB")
35+
logger.info("========================================")
36+
except Exception as e:
37+
logger.error(f"Failed to log system information: {e}")
38+
39+
1140
def setup_logging():
1241
# Determine the user's Documents directory
1342
documents_dir = os.path.join(os.path.expanduser("~"), "Documents")
@@ -43,4 +72,6 @@ def flush(self):
4372
self.stream.flush()
4473

4574
sys.stdout = StreamToLogger(sys.stdout, logging.INFO)
46-
sys.stderr = StreamToLogger(sys.stderr, logging.ERROR)
75+
sys.stderr = StreamToLogger(sys.stderr, logging.ERROR)
76+
77+
log_system_info(logger)

0 commit comments

Comments
 (0)