zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
U
¸ý°dØ"ã@s†UdZddlmZddlZddlZddlmZddlmZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z d d l mZd d l mZd dlmZer°dZerªdnd ZndZdZe dddZe deedfZe d¡Zejejkrøe ej¡dddœdd„ZeƒZde d<ddd œd!d"„Z!d#d#d œd$d%„Z"e ej#d&fZ$Gd'd„dƒZ%Gd(d&„d&ƒZ&d/dd)dd*œd+d,„Z'Gd-d.„d.ƒZ(dS)0a”Logging 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)ÚLiteralTéFÚ_ITÚ
Identified)ÚboundÚdebugZ
sqlalchemyzlogging.LoggerÚNone)ÚloggerÚreturncCs*t tj¡}| t d¡¡| |¡dS)Nz.%(asctime)s %(levelname)s %(name)s %(message)s)ÚloggingÚ StreamHandlerÚsysÚstdoutÚ setFormatterÚ    FormatterÚ
addHandler)rÚhandler©rúEd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/log.pyÚ_add_default_handler:s
 ÿr zSet[Type[Identified]]Ú_logged_classesúType[Identified]Ústr)ÚclsrcCst|ddƒp|jd|jS)NZ_sqla_logger_namespaceÚ.)ÚgetattrÚ
__module__Ú__name__©r$rrrÚ_qual_logger_name_for_clsEs þr*z    Type[_IT]cs>t t|ƒ¡‰‡fdd„|_‡fdd„|_ˆ|_t |¡|S)Ncs ˆ tj¡S©N)Ú isEnabledForrÚDEBUG©Úself©rrrÚ<lambda>Nsÿzclass_logger.<locals>.<lambda>cs ˆ tj¡Sr+)r,rÚINFOr.r0rrr1Qsÿ)rÚ    getLoggerr*Ú_should_log_debugÚ_should_log_inforr!Úaddr)rr0rÚ class_loggerLs 
r7ÚInstanceLoggerc@sJeZdZUdZdZded<ded<ded<d    d
œd d „Zd    d
œd d„ZdS)rrNz Optional[str]Ú logging_nameÚ_IdentifiedLoggerTyperÚ _EchoFlagTypeÚ_echoÚbool©rcCs|j tj¡Sr+)rr,rr-r.rrrr4eszIdentified._should_log_debugcCs|j tj¡Sr+)rr,rr2r.rrrr5hszIdentified._should_log_info)r(r'Ú __qualname__Ú    __slots__r9Ú__annotations__r4r5rrrrr\s
 c@sôeZdZUdZejejejejdœZde    d<dZ
dddœdd    „Z dd
d
d d œd d„Z dd
d
d d œdd„Z dd
d
d d œdd„ZeZdd
d
d d œdd„Zdd
d
d d œdd„Zdd
d
d d œdd„Zddd
d
d dœdd„Zdddœdd „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#)rBÚnamecCs8||_t |¡|_|j|tjkr4|jjs4t|jƒdSr+)rBrr3rÚ    _echo_mapr2Úhandlersr )r/rBrCrrrÚ__init__‹s zInstanceLogger.__init__rr)ÚmsgÚargsÚkwargsrcOs|jtj|f|ž|ŽdS)z/Delegate a debug call to the underlying logger.N)Úlogrr-©r/rGrHrIrrrr—szInstanceLogger.debugcOs|jtj|f|ž|ŽdS)z/Delegate an info call to the underlying logger.N)rJrr2rKrrrÚinfoœszInstanceLogger.infocOs|jtj|f|ž|ŽdS)z1Delegate a warning call to the underlying logger.N)rJrÚWARNINGrKrrrÚwarning¡szInstanceLogger.warningcOs|jtj|f|ž|ŽdS)zB
        Delegate an error call to the underlying logger.
        N©rJrÚERRORrKrrrÚerror¨szInstanceLogger.errorcOs"d|d<|jtj|f|ž|ŽdS)z4Delegate an exception call to the underlying logger.r
Úexc_infoNrOrKrrrÚ    exception®szInstanceLogger.exceptioncOs|jtj|f|ž|ŽdS)z2Delegate a critical call to the underlying logger.N)rJrÚCRITICALrKrrrÚcritical´szInstanceLogger.criticalÚint)ÚlevelrGrHrIrcOsj|jjj|krdS|j|j}|tjkr2|j ¡}||krftrR|     dd¡t
|d<|jj |||f|ŽdS)zÎDelegate 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
) rÚmanagerÚdisablerDrBrÚNOTSETÚgetEffectiveLevelÚ
STACKLEVELÚgetÚSTACKLEVEL_OFFSETÚ_log)r/rWrGrHrIZselected_levelrrrrJ¹s  
 
ÿ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@rFrrLrNÚwarnrQrSrUrJr,r\rrrrr8ls&
ü r;)ÚinstanceÚechoflagrcCsT|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)rdrerCrrrrÚinstance_loggeråsþ
 
rgc@s`eZdZdZeddddœdd„ƒZeddddœd    d„ƒZd
dd dœd d„Zddd dœdd„ZdS)Ú 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")rdÚownerrcCsdSr+r©r/rdrirrrÚ__get__szecho_property.__get__rr;cCsdSr+rrjrrrrkszOptional[Identified]z#Union[echo_property, _EchoFlagType]cCs|dkr |S|jSdSr+)r<rjrrrrksr)rdÚvaluercCst||ddS)N)re)rg)r/rdrlrrrÚ__set__"szecho_property.__set__N)r(r'r?rbrrkrmrrrrrhs
rh)N))rbÚ
__future__rrrÚtypingrrrrrrr    Úutilr r Z util.typingr r]r_rr=r;r3Z
rootloggerrWr[ÚsetLevelÚWARNr Úsetr!rAr*r7ÚLoggerr:rr8rgrhrrrrÚ<module>    sB            
   zÿ