o znh%@sdZddlZddlZedZejejkreejddZ e Z ddZ Gdd d e ZGd d d e Zdd d ZGddde ZdS)aLogging 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` and :class:`.Pool` objects, corresponds to a logger specific to that instance only. N sqlalchemycCs*ttj}|td||dS)Nz.%(asctime)s %(levelname)s %(name)s %(message)s)logging StreamHandlersysstdout setFormatter Formatter addHandler)loggerhandlerr 9/usr/local/lib/python3.10/dist-packages/sqlalchemy/log.py_add_default_handler!s rcsFt|jd|jfdd|_fdd|_|_t||S)N.c tjSN) isEnabledForrDEBUGselfr r r . zclass_logger..crr)rrINFOrrr r r/r) r getLogger __module____name___should_log_debug_should_log_infor _logged_classesadd)clsr rr class_logger,s  r"c@s eZdZdZddZddZdS) IdentifiedNcC|jtjSr)r rrrrr r r r8zIdentified._should_log_debugcCr$r)r rrrrr r r r;r%zIdentified._should_log_info)rr __qualname__ logging_namerrr r r r r#5s r#c@szeZdZdZejejejejdZddZ ddZ ddZ d d Z e Z d d Zd dZddZddZddZddZdS)InstanceLoggeraA 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 )NFTdebugcCs@||_t||_|j|tjkr|jjst|jdSdSdSr)echorrr _echo_maprhandlersr)rr*namer r r __init__Zs  zInstanceLogger.__init__cO |jtj|g|Ri|dS)z/Delegate a debug call to the underlying logger.N)logrrrmsgargskwargsr r r r)f zInstanceLogger.debugcOr/)z/Delegate an info call to the underlying logger.N)r0rrr1r r r infokr5zInstanceLogger.infocOr/)z1Delegate a warning call to the underlying logger.N)r0rWARNINGr1r r r warningpr5zInstanceLogger.warningcOr/)zB Delegate an error call to the underlying logger. Nr0rERRORr1r r r errorws zInstanceLogger.errorcOs(d|d<|jtj|g|Ri|dS)z4Delegate an exception call to the underlying logger.exc_infoNr9r1r r r exception}s zInstanceLogger.exceptioncOr/)z2Delegate a critical call to the underlying logger.N)r0rCRITICALr1r r r criticalr5zInstanceLogger.criticalcOsZ|jjj|kr dS|j|j}|tjkr|j}||kr+|jj|||fi|dSdS)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) r managerdisabler+r*rNOTSETgetEffectiveLevel_log)rlevelr2r3r4selected_levelr r r r0s    zInstanceLogger.logcCs|jjj|kr dS||kS)z)Is this logger enabled for level 'level'?F)r rArBrDrrFr r r rs zInstanceLogger.isEnabledForcCs$|j|j}|tjkr|j}|S)z+What's the effective level for this logger?)r+r*rrCr rDrHr r r rDs   z InstanceLogger.getEffectiveLevelN)rrr&__doc__rrCrrr+r.r)r6r8warnr;r>r@r0rrDr r r r r(?s$  r(cCsb|jrd|jj|jj|jf}n d|jj|jjf}||_|dvr't|}nt||}||_dS)zEcreate a logger for an instance that implements :class:`.Identified`.z%s.%s.%sz%s.%s)FNN) r' __class__rr_echorrr(r )instanceechoflagr-r r r r instance_loggers   rOc@s eZdZdZddZddZdS) 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``. cCs|dur|S|jSr)rL)rrMownerr r r __get__szecho_property.__get__cCst||ddS)N)rN)rO)rrMvaluer r r __set__szecho_property.__set__N)rrr&rIrRrTr r r r rPs rPr)rIrrr rootloggerrFrCsetLevelWARNrsetrr"objectr#r(rOrPr r r r s      o