99import contextlib
1010import logging as _std_logging
1111
12- from . import logxide
12+ try :
13+ from . import logxide
14+ except ImportError :
15+ # Handle case where Rust extension is not available
16+ class logxide : # type: ignore[no-redef]
17+ class logging :
18+ @staticmethod
19+ def getLogger (name = None ):
20+ return object ()
21+
22+ @staticmethod
23+ def basicConfig (** kwargs ):
24+ pass
25+
26+ @staticmethod
27+ def flush ():
28+ pass
29+
30+ @staticmethod
31+ def set_thread_name (name ):
32+ pass
33+
34+ PyLogger = object
35+ LogRecord = object
36+
37+
1338from .compat_functions import (
1439 addLevelName ,
1540 disable ,
3560from .logger_wrapper import _migrate_existing_loggers , basicConfig , getLogger
3661
3762# Get references to Rust functions
38- flush = logxide .logging .flush
39- register_python_handler = logxide .logging .register_python_handler
40- set_thread_name = logxide .logging .set_thread_name
41- PyLogger = logxide .logging .PyLogger
63+ flush = logxide .logging .flush # type: ignore[attr-defined]
64+ register_python_handler = logxide .logging .register_python_handler # type: ignore[attr-defined]
65+ set_thread_name = logxide .logging .set_thread_name # type: ignore[attr-defined]
66+ PyLogger = logxide .logging .PyLogger # type: ignore[attr-defined]
4267
4368
4469class _LoggingModule :
@@ -157,7 +182,7 @@ def __init__(self):
157182 # Create mock shutdown function that delegates to standard logging
158183 def shutdown ():
159184 # Flush all handlers
160- logxide .logging .flush () # Flush LogXide's internal buffers
185+ logxide .logging .flush () # type: ignore[attr-defined] # Flush LogXide's internal buffers
161186 for handler in _std_logging .root .handlers :
162187 with contextlib .suppress (builtins .BaseException ):
163188 handler .flush ()
@@ -237,12 +262,12 @@ def getHandlerNames(self):
237262 @property
238263 def config (self ):
239264 """Provide access to logging.config for compatibility"""
240- return _std_logging .config
265+ return _std_logging .config # type: ignore[attr-defined]
241266
242267 @property
243268 def handlers (self ):
244269 """Provide access to logging.handlers for compatibility"""
245- return _std_logging .handlers
270+ return _std_logging .handlers # type: ignore[attr-defined]
246271
247272
248273# Create the global logging manager instance
@@ -276,13 +301,13 @@ def install():
276301
277302 # Store the original getLogger function
278303 if not hasattr (std_logging , "_original_getLogger" ):
279- std_logging ._original_getLogger = std_logging .getLogger
304+ std_logging ._original_getLogger = std_logging .getLogger # type: ignore[attr-defined]
280305
281306 # Replace getLogger with our version
282307 def logxide_getLogger (name = None ):
283308 """Get a logxide logger that wraps the standard logger"""
284309 # Get the standard logger first
285- std_logger = std_logging ._original_getLogger (name )
310+ std_logger = std_logging ._original_getLogger (name ) # type: ignore[attr-defined]
286311
287312 # Create a logxide logger
288313 logxide_logger = getLogger (name )
@@ -321,25 +346,25 @@ def exception_wrapper(msg, *args, **kwargs):
321346
322347 # Also replace basicConfig to use logxide
323348 if not hasattr (std_logging , "_original_basicConfig" ):
324- std_logging ._original_basicConfig = std_logging .basicConfig
349+ std_logging ._original_basicConfig = std_logging .basicConfig # type: ignore[attr-defined]
325350
326351 def logxide_basicConfig (** kwargs ):
327352 """Use logxide basicConfig but also call original for compatibility"""
328353 import contextlib
329354
330355 with contextlib .suppress (Exception ):
331- std_logging ._original_basicConfig (** kwargs )
356+ std_logging ._original_basicConfig (** kwargs ) # type: ignore[attr-defined]
332357 return basicConfig (** kwargs )
333358
334359 std_logging .basicConfig = logxide_basicConfig
335360
336361 # Also add flush method if it doesn't exist
337362 if not hasattr (std_logging , "flush" ):
338- std_logging .flush = flush
363+ std_logging .flush = flush # type: ignore[attr-defined]
339364
340365 # Add set_thread_name method if it doesn't exist
341366 if not hasattr (std_logging , "set_thread_name" ):
342- std_logging .set_thread_name = set_thread_name
367+ std_logging .set_thread_name = set_thread_name # type: ignore[attr-defined]
343368
344369 # Migrate any loggers that might have been created before install()
345370 _migrate_existing_loggers ()
@@ -355,12 +380,12 @@ def uninstall():
355380
356381 # Restore original getLogger if it exists
357382 if hasattr (std_logging , "_original_getLogger" ):
358- std_logging .getLogger = std_logging ._original_getLogger
383+ std_logging .getLogger = std_logging ._original_getLogger # type: ignore[attr-defined]
359384 delattr (std_logging , "_original_getLogger" )
360385
361386 # Restore original basicConfig if it exists
362387 if hasattr (std_logging , "_original_basicConfig" ):
363- std_logging .basicConfig = std_logging ._original_basicConfig
388+ std_logging .basicConfig = std_logging ._original_basicConfig # type: ignore[attr-defined]
364389 delattr (std_logging , "_original_basicConfig" )
365390
366391
0 commit comments