1313import os
1414import re
1515import subprocess
16+ import logging # Added logging
1617from typing import Optional
1718
19+ # Configure logging
20+ logging .basicConfig (level = logging .INFO )
21+ logger = logging .getLogger (__name__ )
1822
1923def analyze_debug_log (log_file : str = "debug.log" ) -> None :
2024 """
2125 Analyze a debug log file for common issues.
2226 """
2327 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" )
2529 return
2630
27- print (f"Analyzing { log_file } ..." ) # noqa: T201
31+ logger . info (f"Analyzing { log_file } ..." )
2832 with open (log_file , "r" ) as f :
2933 content = f .read ()
3034
@@ -41,11 +45,11 @@ def analyze_debug_log(log_file: str = "debug.log") -> None:
4145 line_end = len (content )
4246
4347 line = content [line_start :line_end ].strip ()
44- print (f"Potential issue found: { line } " ) # noqa: T201
48+ logger . warning (f"Potential issue found: { line } " )
4549 errors_found = True
4650
4751 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." )
4953
5054
5155def test_connectivity (server_url : Optional [str ] = None ) -> None :
@@ -63,48 +67,46 @@ def test_connectivity(server_url: Optional[str] = None) -> None:
6367 break
6468
6569 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+ )
6973 return
7074
71- print (f"Testing connectivity to { server_url } ..." ) # noqa: T201
75+ logger . info (f"Testing connectivity to { server_url } ..." )
7276 try :
7377 import requests
7478
7579 response = requests .get (f"{ server_url } /api/v1/server_settings" )
7680 if response .status_code == 200 :
77- print (f"Successfully connected to { server_url } " ) # noqa: T201
81+ logger . info (f"Successfully connected to { server_url } " )
7882 try :
7983 settings = response .json ()
80- print (
84+ logger . info (
8185 f"Server version: { settings .get ('zulip_version' , 'unknown' )} "
82- ) # noqa: T201
86+ )
8387 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" )
8589 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 } " )
8991 except Exception as e :
90- print (f"Connection error: { e } " ) # noqa: T201
92+ logger . error (f"Connection error: { e } " )
9193
9294
9395def check_terminal_capabilities () -> None :
9496 """
9597 Check for terminal capabilities that might affect Zulip Terminal.
9698 """
97- print ("Checking terminal capabilities..." ) # noqa: T201
99+ logger . info ("Checking terminal capabilities..." )
98100
99101 # Check for color support
100102 colors = os .environ .get ("TERM" , "unknown" )
101- print (f"TERM environment: { colors } " ) # noqa: T201
103+ logger . info (f"TERM environment: { colors } " )
102104
103105 if "COLORTERM" in os .environ :
104- print (f"COLORTERM: { os .environ ['COLORTERM' ]} " ) # noqa: T201
106+ logger . info (f"COLORTERM: { os .environ ['COLORTERM' ]} " )
105107
106108 # Check for Unicode support
107- print ("\n Testing Unicode rendering capabilities:" ) # noqa: T201
109+ logger . info ("\n Testing Unicode rendering capabilities:" )
108110 test_chars = [
109111 ("Basic symbols" , "▶ ◀ ✓ ✗" ),
110112 ("Emoji (simple)" , "😀 🙂 👍" ),
@@ -113,17 +115,17 @@ def check_terminal_capabilities() -> None:
113115 ]
114116
115117 for name , chars in test_chars :
116- print (f" { name } : { chars } " ) # noqa: T201
118+ logger . info (f" { name } : { chars } " )
117119
118120 # Check for urwid compatibility
119121 try :
120122 import urwid # noqa: F401
121123
122- print ("\n Urwid detected. Running basic urwid test..." ) # noqa: T201
124+ logger . info ("\n Urwid detected. Running basic urwid test..." )
123125 # 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" )
125127 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." )
127129
128130
129131def main () -> None :
@@ -162,7 +164,7 @@ def main() -> None:
162164 cmd = ["zulip-term" , "-d" ]
163165 if args .profile :
164166 cmd .append ("--profile" )
165- print (f"Running: { ' ' .join (cmd )} " ) # noqa: T201
167+ logger . info (f"Running: { ' ' .join (cmd )} " )
166168 subprocess .run (cmd )
167169 else :
168170 parser .print_help ()
0 commit comments