13
13
import os
14
14
import re
15
15
import subprocess
16
+ import logging # Added logging
16
17
from typing import Optional
17
18
19
+ # Configure logging
20
+ logging .basicConfig (level = logging .INFO )
21
+ logger = logging .getLogger (__name__ )
18
22
19
23
def analyze_debug_log (log_file : str = "debug.log" ) -> None :
20
24
"""
21
25
Analyze a debug log file for common issues.
22
26
"""
23
27
if not os .path .exists (log_file ):
24
- print (f"Error: Log file '{ log_file } ' not found" ) # noqa: T201
28
+ logger . error (f"Log file '{ log_file } ' not found" )
25
29
return
26
30
27
- print (f"Analyzing { log_file } ..." ) # noqa: T201
31
+ logger . info (f"Analyzing { log_file } ..." )
28
32
with open (log_file , "r" ) as f :
29
33
content = f .read ()
30
34
@@ -41,11 +45,11 @@ def analyze_debug_log(log_file: str = "debug.log") -> None:
41
45
line_end = len (content )
42
46
43
47
line = content [line_start :line_end ].strip ()
44
- print (f"Potential issue found: { line } " ) # noqa: T201
48
+ logger . warning (f"Potential issue found: { line } " )
45
49
errors_found = True
46
50
47
51
if not errors_found :
48
- print ("No obvious errors found in the log file." ) # noqa: T201
52
+ logger . info ("No obvious errors found in the log file." )
49
53
50
54
51
55
def test_connectivity (server_url : Optional [str ] = None ) -> None :
@@ -63,48 +67,46 @@ def test_connectivity(server_url: Optional[str] = None) -> None:
63
67
break
64
68
65
69
if not server_url :
66
- print (
67
- "Error: No server URL provided and couldn't find one in ~/.zuliprc"
68
- ) # noqa: T201
70
+ logger . error (
71
+ "No server URL provided and couldn't find one in ~/.zuliprc"
72
+ )
69
73
return
70
74
71
- print (f"Testing connectivity to { server_url } ..." ) # noqa: T201
75
+ logger . info (f"Testing connectivity to { server_url } ..." )
72
76
try :
73
77
import requests
74
78
75
79
response = requests .get (f"{ server_url } /api/v1/server_settings" )
76
80
if response .status_code == 200 :
77
- print (f"Successfully connected to { server_url } " ) # noqa: T201
81
+ logger . info (f"Successfully connected to { server_url } " )
78
82
try :
79
83
settings = response .json ()
80
- print (
84
+ logger . info (
81
85
f"Server version: { settings .get ('zulip_version' , 'unknown' )} "
82
- ) # noqa: T201
86
+ )
83
87
except json .JSONDecodeError :
84
- print ("Received response, but couldn't parse as JSON" ) # noqa: T201
88
+ logger . error ("Received response, but couldn't parse as JSON" )
85
89
else :
86
- print (
87
- f"Failed to connect: HTTP status { response .status_code } "
88
- ) # noqa: T201
90
+ logger .error (f"Failed to connect: HTTP status { response .status_code } " )
89
91
except Exception as e :
90
- print (f"Connection error: { e } " ) # noqa: T201
92
+ logger . error (f"Connection error: { e } " )
91
93
92
94
93
95
def check_terminal_capabilities () -> None :
94
96
"""
95
97
Check for terminal capabilities that might affect Zulip Terminal.
96
98
"""
97
- print ("Checking terminal capabilities..." ) # noqa: T201
99
+ logger . info ("Checking terminal capabilities..." )
98
100
99
101
# Check for color support
100
102
colors = os .environ .get ("TERM" , "unknown" )
101
- print (f"TERM environment: { colors } " ) # noqa: T201
103
+ logger . info (f"TERM environment: { colors } " )
102
104
103
105
if "COLORTERM" in os .environ :
104
- print (f"COLORTERM: { os .environ ['COLORTERM' ]} " ) # noqa: T201
106
+ logger . info (f"COLORTERM: { os .environ ['COLORTERM' ]} " )
105
107
106
108
# Check for Unicode support
107
- print ("\n Testing Unicode rendering capabilities:" ) # noqa: T201
109
+ logger . info ("\n Testing Unicode rendering capabilities:" )
108
110
test_chars = [
109
111
("Basic symbols" , "▶ ◀ ✓ ✗" ),
110
112
("Emoji (simple)" , "😀 🙂 👍" ),
@@ -113,17 +115,17 @@ def check_terminal_capabilities() -> None:
113
115
]
114
116
115
117
for name , chars in test_chars :
116
- print (f" { name } : { chars } " ) # noqa: T201
118
+ logger . info (f" { name } : { chars } " )
117
119
118
120
# Check for urwid compatibility
119
121
try :
120
122
import urwid # noqa: F401
121
123
122
- print ("\n Urwid detected. Running basic urwid test..." ) # noqa: T201
124
+ logger . info ("\n Urwid detected. Running basic urwid test..." )
123
125
# This doesn't actually run a visual test - just checks if urwid can be imported
124
- print ("Urwid import successful" ) # noqa: T201
126
+ logger . info ("Urwid import successful" )
125
127
except ImportError :
126
- print ("Urwid not found. This may indicate installation issues." ) # noqa: T201
128
+ logger . warning ("Urwid not found. This may indicate installation issues." )
127
129
128
130
129
131
def main () -> None :
@@ -162,7 +164,7 @@ def main() -> None:
162
164
cmd = ["zulip-term" , "-d" ]
163
165
if args .profile :
164
166
cmd .append ("--profile" )
165
- print (f"Running: { ' ' .join (cmd )} " ) # noqa: T201
167
+ logger . info (f"Running: { ' ' .join (cmd )} " )
166
168
subprocess .run (cmd )
167
169
else :
168
170
parser .print_help ()
0 commit comments