U kf!@sUdZddlmZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z dd lm Z dd lm Z d d l mZd d l mZd dlmZerdZerdnd ZndZdZe dddZe deedfZedZejejkreejdddddZeZde d<ddd d!d"Z!d#d#d d$d%Z"e ej#d&fZ$Gd'ddZ%Gd(d&d&Z&d/dd)dd*d+d,Z'Gd-d.d.Z(dS)0aLogging control and utilities. Control of logging for SA can be performed from the regular python logging module. The regular dotted module namespace is used, starting at 'sqlalchemy'. For class-level logging, the class name is appended. The "echo" keyword parameter, available on SQLA :class:`_engine.Engine` and :class:`_pool.Pool` objects, corresponds to a logger specific to that instance only. ) annotationsN)Any)Optional)overload)Set)Type)TypeVar)Union)py311)py38)LiteralTF_IT Identified)bounddebugZ sqlalchemyzlogging.LoggerNone)loggerreturncCs*ttj}|td||dS)Nz.%(asctime)s %(levelname)s %(name)s %(message)s)logging StreamHandlersysstdout setFormatter Formatter addHandler)rhandlerr>/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/log.py_add_default_handler:s  r zSet[Type[Identified]]_logged_classesType[Identified]str)clsrcCst|ddp|jd|jS)NZ_sqla_logger_namespace.)getattr __module____name__r$rrr_qual_logger_name_for_clsEs r*z Type[_IT]cs>tt|fdd|_fdd|_|_t||S)Ncs tjSN) isEnabledForrDEBUGselfrrrNszclass_logger..cs tjSr+)r,rINFOr.r0rrr1Qs)r getLoggerr*_should_log_debug_should_log_inforr!addr)rr0r class_loggerLs  r7InstanceLoggerc@sJeZdZUdZdZded<ded<ded<d d d d Zd d d dZdS)rrNz Optional[str] logging_name_IdentifiedLoggerTyper _EchoFlagType_echoboolrcCs|jtjSr+)rr,rr-r.rrrr4eszIdentified._should_log_debugcCs|jtjSr+)rr,rr2r.rrrr5hszIdentified._should_log_info)r(r' __qualname__ __slots__r9__annotations__r4r5rrrrr\s  c@seZdZUdZejejejejdZde d<dZ ddddd Z dd d d d d dZ dd d d d ddZ dd d d d ddZeZdd d d d ddZdd d d d ddZdd d d d ddZddd d d dddZddddd Zdd!d"d#Zd$S)%r8aA logger adapter (wrapper) for :class:`.Identified` subclasses. This allows multiple instances (e.g. Engine or Pool instances) to share a logger, but have its verbosity controlled on a per-instance basis. The basic functionality is to return a logging level which is based on an instance's echo setting. Default implementation is: 'debug' -> logging.DEBUG True -> logging.INFO False -> Effective level of underlying logger ( logging.WARNING by default) None -> same as False )NFTrr;r<)echorr#)rBnamecCs8||_t||_|j|tjkr4|jjs4t|jdSr+)rBrr3r _echo_mapr2handlersr )r/rBrCrrr__init__s zInstanceLogger.__init__rr)msgargskwargsrcOs|jtj|f||dS)z/Delegate a debug call to the underlying logger.N)logrr-r/rGrHrIrrrrszInstanceLogger.debugcOs|jtj|f||dS)z/Delegate an info call to the underlying logger.N)rJrr2rKrrrinfoszInstanceLogger.infocOs|jtj|f||dS)z1Delegate a warning call to the underlying logger.N)rJrWARNINGrKrrrwarningszInstanceLogger.warningcOs|jtj|f||dS)zB Delegate an error call to the underlying logger. NrJrERRORrKrrrerrorszInstanceLogger.errorcOs"d|d<|jtj|f||dS)z4Delegate an exception call to the underlying logger.r exc_infoNrOrKrrr exceptionszInstanceLogger.exceptioncOs|jtj|f||dS)z2Delegate a critical call to the underlying logger.N)rJrCRITICALrKrrrcriticalszInstanceLogger.criticalint)levelrGrHrIrcOsj|jjj|krdS|j|j}|tjkr2|j}||krftrR| ddt |d<|jj |||f|dS)zDelegate a log call to the underlying logger. The level here is determined by the echo flag as well as that of the underlying logger, and logger._log() is called directly. N stacklevelr ) rmanagerdisablerDrBrNOTSETgetEffectiveLevel STACKLEVELgetSTACKLEVEL_OFFSET_log)r/rWrGrHrIZselected_levelrrrrJs    zInstanceLogger.logr=)rWrcCs|jjj|krdS||kS)z)Is this logger enabled for level 'level'?F)rrYrZr\r/rWrrrr,szInstanceLogger.isEnabledForr>cCs$|j|j}|tjkr |j}|S)z+What's the effective level for this logger?)rDrBrr[rr\rarrrr\s   z InstanceLogger.getEffectiveLevelN)r(r'r?__doc__rr[r2r-rDrAr@rFrrLrNwarnrQrSrUrJr,r\rrrrr8ls&  r;)instanceechoflagrcCsT|jrdt|j|jf}n t|j}||_|dkr@t|}n t||}||_dS)zEcreate a logger for an instance that implements :class:`.Identified`.z%s.%s)FNN)r9r* __class__r<rr3r8r)rdrerCrrrrinstance_loggers   rgc@s`eZdZdZeddddddZeddddd dZd dd dd dZddd dddZdS) echo_propertya} When ``True``, enable log output for this element. This has the effect of setting the Python logging level for the namespace of this element's class and object reference. A value of boolean ``True`` indicates that the loglevel ``logging.INFO`` will be set for the logger, whereas the string value ``debug`` will set the loglevel to ``logging.DEBUG``. z Literal[None]r")rdownerrcCsdSr+rr/rdrirrr__get__ szecho_property.__get__rr;cCsdSr+rrjrrrrkszOptional[Identified]z#Union[echo_property, _EchoFlagType]cCs|dkr |S|jSdSr+)r<rjrrrrksr)rdvaluercCst||ddS)N)re)rg)r/rdrlrrr__set__szecho_property.__set__N)r(r'r?rbrrkrmrrrrrhs rh)N))rb __future__rrrtypingrrrrrrr utilr r Z util.typingr r]r_rr=r;r3Z rootloggerrWr[setLevelWARNr setr!rAr*r7Loggerr:rr8rgrhrrrr sB                y