
    ,YHh(                    8   U d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lm	Z	 d dl
Z
d dlZd dlZd dlZg d
Z ej                         Zded<   daded<   ddZddZddZddZd dZd dZd!dZd"dZd#dZd dZd dZd dZd dZy)$    )annotationsN)CRITICAL)DEBUG)ERROR)FATAL)INFO)WARN)WARNING)r   r   r   r   r   r	   r
   zthreading.Lock_lockzlogging.Handler | None_default_handlerc                     d} d}t               rt        j                  d|  d|       S t        j                  |  d|       S )z}Create a default formatter of log messages.

    This function is not supposed to be directly accessed by library users.
    z[%(levelname)1.1s %(asctime)s]z%(message)sz%(log_color)sz
%(reset)s  )_color_supportedcolorlogColoredFormatterlogging	Formatter)headermessages     G/var/www/html/planif/env/lib/python3.12/site-packages/optuna/logging.pycreate_default_formatterr       sU    
 .FG((F8:gY7
 	
 xq	233    c                     t         j                  j                  dd      ryt        t        j
                  d      rt        j
                  j                         syy)zDetection of color support.NO_COLORNFisattyT)osenvirongethasattrsysstderrr    r   r   r   r   .   s<     
zz~~j$'3::x(

0A0A0Cr   c                 2    t         j                  d      d   S )N.r   )__name__splitr"   r   r   _get_library_namer'   :   s    >>#q!!r   c                 <    t        j                  t                     S N)r   	getLoggerr'   r"   r   r   _get_library_root_loggerr+   >   s    .011r   c                 F   t         5  t        r
	 d d d        y t        j                         at        j	                  t                      t               } | j                  t               | j                  t        j                         d| _
        d d d        y # 1 sw Y   y xY w)NF)r   r   r   StreamHandlersetFormatterr   r+   
addHandlersetLevelr   	propagatelibrary_root_loggers    r   _configure_library_root_loggerr4   B   s     
 .. . #002%%&>&@A /G.H&&'78$$W\\2(-%. . .s   BA6BB c                     t         5  t        s
	 d d d        y t               } | j                  t               | j	                  t
        j                         d ad d d        y # 1 sw Y   y xY wr)   )r   r   r+   removeHandlerr0   r   NOTSETr2   s    r   _reset_library_root_loggerr8   S   s_     
      /G.H))*:;$$W^^4     s   A!A A!!A*c                @    t                t        j                  |       S )zzReturn a logger with the specified name.

    This function is not supposed to be directly accessed by library users.
    )r4   r   r*   )names    r   
get_loggerr;   `   s     #$T""r   c                 F    t                t               j                         S )a  Return the current level for the Optuna's root logger.

    Example:

        Get the default verbosity level.

        .. testsetup::

            def objective(trial):
                x = trial.suggest_float("x", -100, 100)
                y = trial.suggest_categorical("y", [-1, 0, 1])
                return x**2 + y

        .. testcode::

            import optuna

            # The default verbosity level of Optuna is `optuna.logging.INFO`.
            print(optuna.logging.get_verbosity())
            # 20
            print(optuna.logging.INFO)
            # 20

            # There are logs of the INFO level.
            study = optuna.create_study()
            study.optimize(objective, n_trials=5)
            # [I 2021-10-31 05:35:17,232] A new study created ...
            # [I 2021-10-31 05:35:17,238] Trial 0 finished with value: ...
            # [I 2021-10-31 05:35:17,245] Trial 1 finished with value: ...
            # ...

        .. testoutput::
           :hide:

           20
           20
    Returns:
        Logging level, e.g., ``optuna.logging.DEBUG`` and ``optuna.logging.INFO``.

    .. note::
        Optuna has following logging levels:

        - ``optuna.logging.CRITICAL``, ``optuna.logging.FATAL``
        - ``optuna.logging.ERROR``
        - ``optuna.logging.WARNING``, ``optuna.logging.WARN``
        - ``optuna.logging.INFO``
        - ``optuna.logging.DEBUG``
    )r4   r+   getEffectiveLevelr"   r   r   get_verbosityr>   j   s    d #$#%7799r   c                J    t                t               j                  |        y)aa  Set the level for the Optuna's root logger.

    Example:

        Set the logging level ``optuna.logging.WARNING``.

        .. testsetup::

            def objective(trial):
                x = trial.suggest_int("x", -10, 10)
                return x**2

        .. testcode::

            import optuna

            # There are INFO level logs.
            study = optuna.create_study()
            study.optimize(objective, n_trials=10)
            # [I 2021-10-31 02:59:35,088] Trial 0 finished with value: 16.0 ...
            # [I 2021-10-31 02:59:35,091] Trial 1 finished with value: 1.0 ...
            # [I 2021-10-31 02:59:35,096] Trial 2 finished with value: 1.0 ...

            # Setting the logging level WARNING, the INFO logs are suppressed.
            optuna.logging.set_verbosity(optuna.logging.WARNING)
            study.optimize(objective, n_trials=10)

        .. testcleanup::

            optuna.logging.set_verbosity(optuna.logging.INFO)


    Args:
        verbosity:
            Logging level, e.g., ``optuna.logging.DEBUG`` and ``optuna.logging.INFO``.

    .. note::
        Optuna has following logging levels:

        - ``optuna.logging.CRITICAL``, ``optuna.logging.FATAL``
        - ``optuna.logging.ERROR``
        - ``optuna.logging.WARNING``, ``optuna.logging.WARN``
        - ``optuna.logging.INFO``
        - ``optuna.logging.DEBUG``
    N)r4   r+   r0   )	verbositys    r   set_verbosityrA      s    ^ #$''	2r   c                 b    t                t        J t               j                  t               y)a  Disable the default handler of the Optuna's root logger.

    Example:

        Stop and then resume logging to :obj:`sys.stderr`.

        .. testsetup::

            def objective(trial):
                x = trial.suggest_float("x", -100, 100)
                y = trial.suggest_categorical("y", [-1, 0, 1])
                return x**2 + y

        .. testcode::

            import optuna

            study = optuna.create_study()

            # There are no logs in sys.stderr.
            optuna.logging.disable_default_handler()
            study.optimize(objective, n_trials=10)

            # There are logs in sys.stderr.
            optuna.logging.enable_default_handler()
            study.optimize(objective, n_trials=10)
            # [I 2020-02-23 17:00:54,314] Trial 10 finished with value: ...
            # [I 2020-02-23 17:00:54,356] Trial 11 finished with value: ...
            # ...

    N)r4   r   r+   r6   r"   r   r   disable_default_handlerrC      s)    B #$''',,-=>r   c                 b    t                t        J t               j                  t               y)zEnable the default handler of the Optuna's root logger.

    Please refer to the example shown in :func:`~optuna.logging.disable_default_handler()`.
    N)r4   r   r+   r/   r"   r   r   enable_default_handlerrE      s(     #$'''))*:;r   c                 6    t                dt               _        y)a  Disable propagation of the library log outputs.

    Note that log propagation is disabled by default. You only need to use this function
    to stop log propagation when you use :func:`~optuna.logging.enable_propagation()`.

    Example:

        Stop propagating logs to the root logger on the second optimize call.

        .. testsetup::

            def objective(trial):
                x = trial.suggest_float("x", -100, 100)
                y = trial.suggest_categorical("y", [-1, 0, 1])
                return x**2 + y

        .. testcode::

            import optuna
            import logging

            optuna.logging.disable_default_handler()  # Disable the default handler.
            logger = logging.getLogger()

            logger.setLevel(logging.INFO)  # Setup the root logger.
            logger.addHandler(logging.FileHandler("foo.log", mode="w"))

            optuna.logging.enable_propagation()  # Propagate logs to the root logger.

            study = optuna.create_study()

            logger.info("Logs from first optimize call")  # The logs are saved in the logs file.
            study.optimize(objective, n_trials=10)

            optuna.logging.disable_propagation()  # Stop propogating logs to the root logger.

            logger.info("Logs from second optimize call")
            # The new logs for second optimize call are not saved.
            study.optimize(objective, n_trials=10)

            with open("foo.log") as f:
                assert f.readline().startswith("A new study created")
                assert f.readline() == "Logs from first optimize call\n"
                # Check for logs after second optimize call.
                assert f.read().split("Logs from second optimize call\n")[-1] == ""

    FNr4   r+   r1   r"   r   r   disable_propagationrH     s    b #$+0(r   c                 6    t                dt               _        y)a  Enable propagation of the library log outputs.

    Please disable the Optuna's default handler to prevent double logging if the root logger has
    been configured.

    Example:

        Propagate all log output to the root logger in order to save them to the file.

        .. testsetup::

            def objective(trial):
                x = trial.suggest_float("x", -100, 100)
                y = trial.suggest_categorical("y", [-1, 0, 1])
                return x**2 + y

        .. testcode::

            import optuna
            import logging

            logger = logging.getLogger()

            logger.setLevel(logging.INFO)  # Setup the root logger.
            logger.addHandler(logging.FileHandler("foo.log", mode="w"))

            optuna.logging.enable_propagation()  # Propagate logs to the root logger.
            optuna.logging.disable_default_handler()  # Stop showing logs in sys.stderr.

            study = optuna.create_study()

            logger.info("Start optimization.")
            study.optimize(objective, n_trials=10)

            with open("foo.log") as f:
                assert f.readline().startswith("A new study created")
                assert f.readline() == "Start optimization.\n"

    TNrG   r"   r   r   enable_propagationrJ   ;  s    R #$+/(r   )returnzlogging.Formatter)rK   bool)rK   str)rK   logging.Logger)rK   None)r:   rM   rK   rN   )rK   int)r@   rP   rK   rO   ) 
__future__r   r   r   r   r   r   r   r	   r
   r   r    	threadingr   __all__Lockr   __annotations__r   r   r   r'   r+   r4   r8   r;   r>   rA   rC   rE   rH   rJ   r"   r   r   <module>rV      s    "         	 
   '	(~ (+/ ( /4	"2."
 #3:l03f$?N	<21j*0r   