
    uYf                         d dl Z d dlZd dlZd dlZd dlmZ ej
                  rd dlmZ d dlmZ d dlmZ d Z	d Z
 G d d	ej                        Zy)
    N)cast)Any)DefaultDict)Tuplec                     t         j                  j                  }| |j                  v r|j                  |    }t	        |j                  |    t         j
                        r|}t        |       }||j                  | <   t        |d      r|j                  ||       t        |d      rJ|j                  |       n8t        |       }||j                  | <   t        |d      r|j                  |       t        t        |      S )aZ  
    Retrieve or create a ``DDLogger`` instance.

    This function mirrors the behavior of `logging.getLogger`.

    If no logger with the provided name has been fetched before then
    a new one is created.

    If a previous logger has been created then it is returned.

    DEV: We do not want to mess with `logging.setLoggerClass()`
         That will totally mess with the user's loggers, we want
         just our own, selective loggers to be DDLoggers

    :param name: The name of the logger to fetch or create
    :type name: str
    :return: The logger instance
    :rtype: ``DDLogger``
    )name_fixupChildren_fixupParents)loggingLoggermanager
loggerDict
isinstancePlaceHolderDDLoggerhasattrr	   r
   r   )r   r   loggerplaceholders       W/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/ddtrace/internal/logger.py
get_loggerr      s    . nn$$G w!!!##D)g((.0C0CD K4(F'-Gt$ w 01&&{F;w0%%f-t$#)4 7O,!!&) &!!    c                 p    | }d}|r/|j                   rd}	 |S |j                  s	 |S |j                  }|r/|S )a  
    See if this logger has any handlers configured.
    Loop through all handlers for this logger and its parents in the
    logger hierarchy. Return True if a handler was found, else False.
    Stop searching up the hierarchy whenever a logger with the "propagate"
    attribute set to zero is found - that will be the last logger which
    is checked for the existence of handlers.

    https://github.com/python/cpython/blob/8f192d12af82c4dc40730bf59814f6a68f68f950/Lib/logging/__init__.py#L1629
    FT)handlers	propagateparent)selfcrvs      r   hasHandlersr   B   sQ     	A	B
::B
 I	 {{ I A  Ir   c                   R     e Zd ZdZ ej
                  dd      Z fdZ fdZ xZ	S )r   z
    Custom rate limited logger used by ``ddtrace``

    This logger class is used to rate limit the output of
    log messages from within the ``ddtrace`` package.
    LoggingBucket)bucketskippedc                     t        t        | 
  |i | t        j                  d       | _        t        j                  dd      }|t        |      | _	        yd| _	        y)zConstructor for ``DDLogger``c                  .    t         j                  dd      S )Nr   )r   r!    r   r   <lambda>z#DDLogger.__init__.<locals>.<lambda>m   s    H**1a0 r   DD_TRACE_LOGGING_RATEN)default<   )
superr   __init__collectionsdefaultdictbucketsosgetenvint
rate_limit)r   argskwargsr3   	__class__s       r   r,   zDDLogger.__init__f   s[     	h&77 #..0
 YY6E
!!*oDO DOr   c                    |j                   t        j                  k\  ryddlm} t
        j                  j                  |j                  |j                        }|j                  j                  d|j                  |j                  z  ||j                         | j                  r!| j!                         t        j"                  k(  rt$        t&        | S  |       yt+        |j,                  | j                  z        }|j.                  |j                   |j                  |j                  f}| j0                  |   }|j2                  |k7  r|j4                  r?dj7                  |j                        |_        |j                  |j4                  fz   |_        t&        j9                  |d      | j0                  |<   t$        t&        | S  |       yt&        j9                  |j2                  |j4                  dz         | j0                  |<   y)a  
        Function used to call the handlers for a log line.

        This implementation will first determine if this log line should
        be logged or rate limited, and then call the base ``logging.Logger.handle``
        function if it should be logged

        DEV: This method has all of it's code inlined to reduce on functions calls

        :param record: The log record being logged
        :type record: ``logging.LogRecord``
        r   )	telemetry   Nz"{}, %s additional messages skipped)levelnor   ERRORddtrace.internalr8   r0   pathjoinpathnamefilenametelemetry_writer	add_errormsgr4   linenor3   getEffectiveLevelDEBUGr+   r   handler2   createdr   r/   r"   r#   formatr!   )r   recordr8   full_file_namecurrent_bucketkeylogging_bucketr6   s          r   rG   zDDLogger.handlez   s    >>W]]*2  WW\\&//6??KN&&00FJJ4Ln^d^k^kl $"8"8":gmm"K(D(0 V^^doo=> {{FNNFOOV]]K c*  N2%%AHHT
$kk^-C-C,EE !) 6 6~q IDLL (D(0 !) 6 6~7L7LnNdNdghNh iDLLr   )
__name__
__module____qualname____doc__r-   
namedtupler!   r,   rG   __classcell__)r6   s   @r   r   r   [   s0     +K**?<QRM!(9j 9jr   r   )r-   r   r0   typingr   TYPE_CHECKINGr   r   r   r   r   r   r   r&   r   r   <module>rW      sG      	   
"1"h2Xjw~~ Xjr   