
    Mh<                       d Z ddlmZ ddlZddlmZ ddlZdZ G d dej                  Z G d d	ej	                  Z
d
                                D ].Z	  eej	        e          Zn# e$ r Y w xY w ee
ed            /dS )a  pyzmq logging handlers.

This mainly defines the PUBHandler object for publishing logging messages over
a zmq.PUB socket.

The PUBHandler can be used with the regular logging module, as in::

    >>> import logging
    >>> handler = PUBHandler('tcp://127.0.0.1:12345')
    >>> handler.root_topic = 'foo'
    >>> logger = logging.getLogger('foobar')
    >>> logger.setLevel(logging.DEBUG)
    >>> logger.addHandler(handler)

Or using ``dictConfig``, as in::

    >>> from logging.config import dictConfig
    >>> socket = Context.instance().socket(PUB)
    >>> socket.connect('tcp://127.0.0.1:12345')
    >>> dictConfig({
    >>>     'version': 1,
    >>>     'handlers': {
    >>>         'zmq': {
    >>>             'class': 'zmq.log.handlers.PUBHandler',
    >>>             'level': logging.DEBUG,
    >>>             'root_topic': 'foo',
    >>>             'interface_or_socket': socket
    >>>         }
    >>>     },
    >>>     'root': {
    >>>         'level': 'DEBUG',
    >>>         'handlers': ['zmq'],
    >>>     }
    >>> })


After this point, all messages logged by ``logger`` will be published on the
PUB socket.

Code adapted from StarCluster:

    https://github.com/jtriley/StarCluster/blob/StarCluster-0.91/starcluster/logger.py
    )annotationsN)copyz::c                      e Zd ZU dZded<   ded<   	 	 dddZedd            Zej        dd            ZddZ	e
j        fdZd Zd ZdS )
PUBHandlera|  A basic logging handler that emits log messages through a PUB socket.

    Takes a PUB socket already bound to interfaces or an interface to bind to.

    Example::

        sock = context.socket(zmq.PUB)
        sock.bind('inproc://log')
        handler = PUBHandler(sock)

    Or::

        handler = PUBHandler('inproc://loc')

    These are equivalent.

    Log messages handled by this handler are broadcast with ZMQ topics
    ``this.root_topic`` comes first, followed by the log level
    (DEBUG,INFO,etc.), followed by any additional subtopics specified in the
    message by: log.debug("subtopic.subsub::the real message")
    zzmq.Contextctxz
zmq.SocketsocketN interface_or_socketstr | zmq.Socketcontextzmq.Context | None
root_topicstrreturnNonec                   t           j                            |            || _        t           j        t          j        d          t           j        t          j        d          t           j        t          j        d          t           j        t          j        d          t           j	        t          j        d          i| _
        t          |t          j                  r|| _        | j        j        | _        d S |pt          j                    | _        | j                            t          j                  | _        | j                            |           d S )Nz4%(levelname)s %(filename)s:%(lineno)d - %(message)s
z%(message)s
zC%(levelname)s %(filename)s:%(lineno)d - %(message)s - %(exc_info)s
)loggingHandler__init__r   DEBUG	FormatterINFOWARNERRORCRITICAL
formatters
isinstancezmqSocketr   r   r   ContextPUBbind)selfr
   r   r   s       P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/zmq/log/handlers.pyr   zPUBHandler.__init__U   s    	  &&&$M7,G  L'+O<<L'+G  M7,V  g/G 
 )3:66 	2-DK{*DHHH/#+--DH(//#'22DKK011111    c                    | j         S N)_root_topic)r#   s    r$   r   zPUBHandler.root_topict   s    r%   valuec                0    |                      |           d S r'   )setRootTopic)r#   r)   s     r$   r   zPUBHandler.root_topicx   s    %     r%   c                h    t          |t                    r|                    d          }|| _        dS )a|  Set the root topic for this handler.

        This value is prepended to all messages published by this handler, and it
        defaults to the empty string ''. When you subscribe to this socket, you must
        set your subscription to an empty string, or to at least the first letter of
        the binary representation of this string to ensure you receive any messages
        from this handler.

        If you use the default empty string root topic, messages will begin with
        the binary representation of the log level string (INFO, WARN, etc.).
        Note that ZMQ SUB sockets can have multiple subscriptions.
        utf8N)r   bytesdecoder(   )r#   r   s     r$   r+   zPUBHandler.setRootTopic|   s7     j%(( 	3#**622J%r%   c                    |t           j        k    r(| j                                        D ]}|| j        |<   dS || j        |<   dS )zSet the Formatter for this handler.

        If no level is provided, the same format is used for all levels. This
        will overwrite all selective formatters set in the object constructor.
        N)r   NOTSETr   keys)r#   fmtlevel	fmt_levels       r$   setFormatterzPUBHandler.setFormatter   s[     GN""!_1133 1 1	-0	**1 1 &)DOE"""r%   c                L    | j         |j                                     |          S )zFormat a record.)r   levelnoformat)r#   records     r$   r9   zPUBHandler.format   s    v~.55f===r%   c                   	 t          |j                                      t          d          \  }}t	          |          }||_        n# t
          $ r d}Y nw xY w	 |                     |                              d          }n&# t          $ r | 	                    |           Y dS w xY wg }| j
        r|                    | j
                   |                    |j                   |r|                    |           d                    |                              dd          }| j                            ||g           dS )z Emit a log message on my socket.   r	   r-   N.replace)r   msgsplitTOPIC_DELIMr   
ValueErrorr9   encode	ExceptionhandleErrorr   append	levelnamejoinr   send_multipart)r#   r:   topicr?   bmsg
topic_listbtopics          r$   emitzPUBHandler.emit   s[   	VZ..{A>>JE3
 &\\FFJJ  	 	 	EEE		;;v&&--f55DD 	 	 	V$$$FF	 
? 	/do...&*+++ 	%e$$$*%%,,VY??""FD>22222s#   0A	 	AA(B B('B()Nr	   )r
   r   r   r   r   r   r   r   )r   r   )r)   r   )r   r   )__name__
__module____qualname____doc____annotations__r   propertyr   setterr+   r   r1   r6   r9   rN    r%   r$   r   r   ;   s          , 
 '+	2 2 2 2 2>       X  ! ! ! !& & & &" '.n 
) 
) 
) 
)> > >3 3 3 3 3r%   r   c                      e Zd ZdZd ZdS )TopicLoggera   A simple wrapper that takes an additional argument to log methods.

    All the regular methods exist, but instead of one msg argument, two
    arguments: topic, msg are passed.

    That is::

        logger.debug('msg')

    Would become::

        logger.debug('topic.sub', 'msg')
    c                T    t          j        j        | || t           | g|R i | dS )a  Log 'msg % args' with level and topic.

        To pass exception information, use the keyword argument exc_info
        with a True value::

            logger.log(level, "zmq.fun", "We have a %s",
                    "mysterious problem", exc_info=1)
        N)r   LoggerlogrA   r#   r4   rJ   r?   argskwargss         r$   r[   zTopicLogger.log   sA     	45(D+(Ds(D(DVtVVVvVVVVVr%   N)rO   rP   rQ   rR   r[   rV   r%   r$   rX   rX      s2         	W 	W 	W 	W 	Wr%   rX   z'debug warn warning error critical fatalc                <    t          | ||t          z   |z   g|R i |S r'   )methrA   r\   s         r$   <lambda>ra      s;    %,s2:
59:
 :
 :
=C:
 :
 r%   )rR   
__future__r   r   r   r   rA   r   r   rZ   rX   r@   namegetattrr`   AttributeErrorsetattrrV   r%   r$   <module>rg      sD  * *X # " " " " "        



 A3 A3 A3 A3 A3 A3 A3 A3HW W W W W'. W W W: 6;;==  Dww~t,,    G	
 	
    s   A((A0/A0