
    ljt                        d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	 ddl
mZmZ ddl
mZ ddlmZ ddlmZ dd	lmZ erdd
lmZ g dZg dZdZddZd dZd!dZ G d dej                  ZdS )"a{  Utilities to create and set the logger.

Manim's logger can be accessed as ``manim.logger``, or as
``logging.getLogger("manim")``, once the library has been imported.  Manim also
exports a second object, ``console``, which should be used to print on screen
messages that need not be logged.

Both ``logger`` and ``console`` use the ``rich`` library to produce rich text
format.

    )annotationsN)TYPE_CHECKINGAny)colorerrors)print)Console)RichHandler)Theme)Path)make_loggerparse_themeset_file_loggerJSONFormatter)Played
animationssceneReadingWritingscript	argumentsInvalidAbortingmoduleFile	RenderingRenderedz
[logging.level.error]Your colour configuration couldn't be parsed.
Loading the default color configuration.[/logging.level.error]
parserconfigparser.SectionProxy	verbositystrreturn'tuple[logging.Logger, Console, Console]c                   t          |           }t          |          }t          |d          }t          ||                     dd          t                    }t          j        d          }|                    |           |                    |           d|_	        t          j                    x}
                                s*|                    |           |                    |           |||fS )	a  Make the manim logger and console.

    Parameters
    ----------
    parser
        A parser containing any .cfg files in use.

    verbosity
        The verbosity level of the logger.

    Returns
    -------
    :class:`logging.Logger`, :class:`rich.Console`, :class:`rich.Console`
        The manim logger and consoles. The first console outputs
        to stdout, the second to stderr. All use the theme returned by
        :func:`parse_theme`.

    See Also
    --------
    :func:`~._config.utils.make_config_parser`, :func:`parse_theme`

    Notes
    -----
    The ``parser`` is assumed to contain only the options related to
    configuring the logger at the top level.

    )themeT)r%   stderrlog_timestampsF)fallback)console	show_timekeywordsmanim)r   r	   r
   
getbooleanHIGHLIGHTED_KEYWORDSlogging	getLogger
addHandlersetLevel	propagatehasHandlers)r   r    r%   r)   error_consolerich_handlerloggerlibav_loggers           U/home/agentuser/manim-venv/lib/python3.11/site-packages/manim/_config/logger_utils.pyr   r   6   s    @ EE"""G%555M ##$4u#EE%  L w''F
l###
OOIF#-///L<<>> )---i(((7M))    Theme | Nonec                     fd D             }|d         dk    rdnt          |d                   |d<   |d         dk    rdnt          |d                   |d<   d|d<   	 t          d |                                D                       }n7# t          j        t
          j        f$ r t          t                     d}Y nw xY w|S )	a5  Configure the rich style of logger and console output.

    Parameters
    ----------
    parser
        A parser containing any .cfg files in use.

    Returns
    -------
    :class:`rich.Theme`
        The rich theme to be used by the manim logger.

    See Also
    --------
    :func:`make_logger`.

    c                J    i | ]}|                     d d          |          S )_.)replace).0keyr   s     r9   
<dictcomp>zparse_theme.<locals>.<dictcomp>   s-    RRRCS[[c22F3KRRRr:   	log.widthz-1N
log.heightFlog.timestampsc                "    i | ]\  }}|d v	||S ))rD   rE   rF    )rA   kvs      r9   rC   zparse_theme.<locals>.<dictcomp>   s4       AqIII 1IIIr:   )	intr   itemsr   ColorParseErrorr   StyleSyntaxErrorprintfWRONG_COLOR_CONFIG_MSG)r   r%   custom_themes   `  r9   r   r   o   s   $ SRRR6RRRE!&{!3t!;!;U;EWAXAXE+l#t++U<5H1I1I 
, $E

 !KKMM  
 
 !6#:;   %&&& s   "+B 1CC
scene_namemodule_namelog_dirr   Nonec                   | d|  d}||z  }t          j        |d          }|                    t                                 t          j        d          }|                    |           |                    dd|i           dS )	ai  Add a file handler to manim logger.

    The path to the file is built using ``config.log_dir``.

    Parameters
    ----------
    scene_name
        The name of the scene, used in the name of the log file.
    module_name
        The name of the module, used in the name of the log file.
    log_dir
        Path to the folder where log files are stored.
    r>   z.logw)moder,   z%Log file will be saved in %(logpath)slogpathN)r/   FileHandlersetFormatterr   r0   r1   info)rR   rS   rT   log_file_namelog_file_pathfile_handlerr7   s          r9   r   r      s    $ #55Z555Mm+M&}3???Lmoo...w''F
l###
KK7)]9STTTTTr:   c                  $     e Zd ZdZd fdZ xZS )r   zuA formatter that outputs logs in a custom JSON format.

    This class is used internally for testing purposes.

    recordlogging.LogRecordr"   r!   c                R   t          j        |          }|j        rKt          |j        t                    r|j        D ]}d|j        |<   ndt          |j                  z  |_        t          j        |j        |j	        t                                          |          d          S )z*Format the record in a custom JSON format.<>)rd   )	levelnamer   message)copydeepcopyargs
isinstancedictlenjsondumpsre   r   superformat)selfra   record_carg	__class__s       r9   rp   zJSONFormatter.format   s    =((= 	=(-.. =#= . .C)-HM#&&. !(#hm*<*< <z%/"/ 77>>(33 
 
 	
r:   )ra   rb   r"   r!   )__name__
__module____qualname____doc__rp   __classcell__)rt   s   @r9   r   r      sG         
 
 
 
 
 
 
 
 
 
r:   r   )r   r   r    r!   r"   r#   )r   r   r"   r;   )rR   r!   rS   r!   rT   r   r"   rU   )rx   
__future__r   configparserrg   rm   r/   typingr   r   richr   r   r   rO   rich.consoler	   rich.loggingr
   
rich.themer   pathlibr   __all__r.   rP   r   r   r   	Formatterr   rH   r:   r9   <module>r      sz  
 
 # " " " " "        % % % % % % % %                                 $ $ $ $ $ $       
L
L
L     6* 6* 6* 6*r% % % %PU U U U:
 
 
 
 
G% 
 
 
 
 
r:   