o
    biZ                     @   s   U 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 d dlmZmZ d d	lmZ G d
d deZG dd deZe
 Zeed< eddeG dd dZde_dS )    N)ABCabstractmethod)	dataclassfield)Set)default_impl)LOGRECORD_STANDARD_ATTRS)CoreContextFilter)JSONFormatterTextFormatter)	PublicAPIc                   @   s0   e Zd Zedee fddZed	ddZdS )
LoggingConfiguratorreturnc                 C      t NNotImplementedErrorself r   [/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/ray_logging/logging_config.pyget_supported_encodings      z+LoggingConfigurator.get_supported_encodingslogging_configLoggingConfigc                 C   r   r   r   )r   r   r   r   r   	configure   r   zLoggingConfigurator.configureNr   r   )__name__
__module____qualname__r   r   strr   r   r   r   r   r   r      s
    r   c                   @   s0   e Zd Zdd Zdee fddZddd	Zd
S )DefaultLoggingConfiguratorc                 C   s   t  t d| _d S )N)TEXTJSON)r   r
   _encoding_to_formatterr   r   r   r   __init__   s   z#DefaultLoggingConfigurator.__init__r   c                 C   s
   | j  S r   )r$   keysr   r   r   r   r      s   
z2DefaultLoggingConfigurator.get_supported_encodingsr   r   c                 C   s   | j |j }||j t }t }||j |	| |
| t }||j || td}||j |jd d  D ]}|| qD|| d|_d S )NrayF)r$   encoding!set_additional_log_standard_attrsadditional_log_standard_attrsr	   loggingStreamHandlersetLevel	log_levelsetFormatter	addFilter	getLogger
addHandlerhandlersremoveHandler	propagate)r   r   	formattercore_context_filterhandlerroot_logger
ray_loggerhr   r   r   r   !   s$   





z$DefaultLoggingConfigurator.configureNr   )r   r   r   r%   r   r    r   r   r   r   r   r   r!      s    r!   _logging_configuratoralpha)	stabilityc                   @   sP   e Zd ZU dZeed< dZeed< eedZ	eed< dd Z
d	d
 Zdd ZdS )r   r"   r(   INFOr.   )default_factoryr*   c                 C   sX   | j t vrtd| j  dtt  | jD ]}|tvr)td| dt qd S )NzInvalid encoding type: z. Valid encoding types are: z+Unknown python logging standard attribute: z. The valid attributes are: )r(   r<   r   
ValueErrorlistr*   r   )r   attrr   r   r   __post_init__K   s   


zLoggingConfig.__post_init__c                 C   s   t |  dS )z9Set up the logging configuration for the current process.N)r<   r   r   r   r   r   _configure_logging[   s   z LoggingConfig._configure_loggingc                 C   s   |    dS )z!Set up the logging configuration.N)rE   r   r   r   r   _apply_   s   zLoggingConfig._applyN)r   r   r   r(   r    __annotations__r.   r   rB   r*   rD   rE   rF   r   r   r   r   r   B   s   
 r   aK  
    Logging configuration for a Ray job. These configurations are used to set up the
    root logger of the driver process and all Ray tasks and actor processes that belong
    to the job.

    Examples: 1. Configure the logging to use TEXT encoding.
        .. testcode::

            import ray
            import logging

            ray.init(
                logging_config=ray.LoggingConfig(encoding="TEXT", log_level="INFO", additional_log_standard_attrs=['name'])
            )

            @ray.remote
            def f():
                logger = logging.getLogger(__name__)
                logger.info("This is a Ray task")

            ray.get(f.remote())
            ray.shutdown()

        .. testoutput::
            :options: +MOCK

            2025-02-12 12:25:16,836 INFO test-log-config.py:11 -- This is a Ray task name=__main__ job_id=01000000 worker_id=51188d9448be4664bf2ea26ac410b67acaaa970c4f31c5ad3ae776a5 node_id=f683dfbffe2c69984859bc19c26b77eaf3866c458884c49d115fdcd4 task_id=c8ef45ccd0112571ffffffffffffffffffffffff01000000 task_name=f task_func_name=test-log-config.f timestamp_ns=1739391916836884000

    2. Configure the logging to use JSON encoding.
        .. testcode::

            import ray
            import logging

            ray.init(
                logging_config=ray.LoggingConfig(encoding="JSON", log_level="INFO", additional_log_standard_attrs=['name'])
            )

            @ray.remote
            def f():
                logger = logging.getLogger(__name__)
                logger.info("This is a Ray task")

            ray.get(f.remote())
            ray.shutdown()

        .. testoutput::
            :options: +MOCK

            {"asctime": "2025-02-12 12:25:48,766", "levelname": "INFO", "message": "This is a Ray task", "filename": "test-log-config.py", "lineno": 11, "name": "__main__", "job_id": "01000000", "worker_id": "6d307578014873fcdada0fa22ea6d49e0fb1f78960e69d61dfe41f5a", "node_id": "69e3a5e68bdc7eb8ac9abb3155326ee3cc9fc63ea1be04d11c0d93c7", "task_id": "c8ef45ccd0112571ffffffffffffffffffffffff01000000", "task_name": "f", "task_func_name": "test-log-config.f", "timestamp_ns": 1739391948766949000}

    Args:
        encoding: Encoding type for the logs. The valid values are
            {list(_logging_configurator.get_supported_encodings())}
        log_level: Log level for the logs. Defaults to 'INFO'. You can set
            it to 'DEBUG' to receive more detailed debug logs.
        additional_log_standard_attrs: List of additional standard python logger attributes to
            include in the log. Defaults to an empty list. The list of already
            included standard attributes are: "asctime", "levelname", "message",
            "filename", "lineno", "exc_text". The list of valid attributes are specified
            here: http://docs.python.org/library/logging.html#logrecord-attributes
    )r+   abcr   r   dataclassesr   r   typingr   ray._private.ray_loggingr   "ray._private.ray_logging.constantsr    ray._private.ray_logging.filtersr	   #ray._private.ray_logging.formattersr
   r   ray.util.annotationsr   r   r!   get_logging_configuratorr<   rG   r   __doc__r   r   r   r   <module>   s    
 
#
 