
    AHj                     B    d Z ddlZddlmZmZ ddlmZ  G d de      Zy)z
A Textual Logging handler.

If there is an active Textual app, then log messages will go via the app (and logged via textual console).

If there is *no* active app, then log messages will go to stderr or stdout, depending on configuration.
    N)Handler	LogRecord)
active_appc                   B     e Zd ZdZd	dededdf fdZdeddfdZ xZS )
TextualHandlerz#A Logging handler for Textual apps.stderrstdoutreturnNc                 >    t         |           || _        || _        y)zInitialize a Textual logging handler.

        Args:
            stderr: Log to stderr when there is no active app.
            stdout: Log to stdout when there is no active app.
        N)super__init___stderr_stdout)selfr   r	   	__class__s      G/root/tools/cai/cai_env/lib/python3.12/site-packages/textual/logging.pyr   zTextualHandler.__init__   s     	    recordc                 H   | j                  |      }	 t        j                         }|j                  j	                  |       y# t
        $ rU | j                  rt        |t        j                         Y y| j                  rt        |t        j                         Y yY yw xY w)zInvoked by logging.)fileN)formatr   getlogloggingLookupErrorr   printsysr   r   r	   )r   r   messageapps       r   emitzTextualHandler.emit   ss    ++f%	%.."C GGOOG$  	0||gCJJ/gCJJ/ 	0s   A 0B!5'B! B!)TF)	__name__
__module____qualname____doc__boolr   r   r    __classcell__)r   s   @r   r   r      s3    -	t 	D 	T 	%9 % %r   r   )r$   r   r   r   r   textual._contextr   r    r   r   <module>r)      s!     & '%W %r   