o 3a9 @sHddlZddlZddlmZddlmZddlmZddlmZddl m Z ddl m Z e dZd d d d id d iddddddiddgddddddddgdddddgdddgdd d d!d"Zd#d$ZGd%d&d&ejZGd'd(d(ejZGd)d*d*ejZGd+d,d,ejZGd-d.d.ejZddeddd/d0d1ZdS)2N)copy)settings)mail)get_connection) color_style) import_stringzdjango.requestF()z"django.utils.log.RequireDebugFalsez!django.utils.log.RequireDebugTrue)require_debug_falserequire_debug_true django.serverz django.utils.log.ServerFormatterz[{server_time}] {message}{)r formatstyleINFOr zlogging.StreamHandler)levelfiltersclass)rr formatterERRORr z"django.utils.log.AdminEmailHandler)consoler mail_adminsrr)handlersr)rr propagate)djangor )versiondisable_existing_loggersr formattersrloggerscCs0|rt|}tjt|r||dSdSdSN)rloggingconfig dictConfigDEFAULT_LOGGING)logging_configlogging_settingslogging_config_funcr'2/usr/lib/python3/dist-packages/django/utils/log.pyconfigure_loggingBs  r)csBeZdZdZdfdd ZddZdd Zd d Zd d ZZ S)AdminEmailHandlerzAn exception log handler that emails log entries to site admins. If the request is passed as the first argument to the log record, request data will be provided in the email report. FNcs*t||_||_t|ptj|_dSr)super__init__ include_html email_backendrrDEFAULT_EXCEPTION_REPORTERreporter_class)selfr-r.r0 __class__r'r(r,Us zAdminEmailHandler.__init__c Csz|j}d|j|jdtjvrdnd|f}Wnty.d|j|f}d}Ynw||}t |}d|_ d|_ |j rE|j }nd|df}|j |g|Rddi}d| ||f}|jrj|nd}|j||d|d dS) Nz%s (%s IP): %s REMOTE_ADDRinternalEXTERNALz%s: %sis_emailTz%s %s) fail_silently html_message)request levelnameMETAgetr INTERNAL_IPS getMessage Exceptionformat_subjectrexc_infoexc_textr0rget_traceback_textr-get_traceback_html send_mail) r1recordr:subject no_exc_recordrBreportermessager9r'r'r(emit[s4  zAdminEmailHandler.emitcOs&tj||g|Rd|i|dS)N connection)rrrM)r1rHrKargskwargsr'r'r(rF|s&zAdminEmailHandler.send_mailcCst|jddS)NT)backendr8)rr.r1r'r'r(rMszAdminEmailHandler.connectioncCs|ddddS)z. Escape CR and LF characters.  z\n z\r)replace)r1rHr'r'r(rAsz AdminEmailHandler.format_subject)FNN) __name__ __module__ __qualname____doc__r,rLrFrMrA __classcell__r'r'r2r(r*Ns!r*c@s eZdZdZddZddZdS)CallbackFilterz A logging filter that checks the return value of a given callable (which takes the record-to-be-logged as its only parameter) to decide whether to log a record. cCs ||_dSrcallback)r1r\r'r'r(r,s zCallbackFilter.__init__cCs||rdSdS)Nrrr[r1rGr'r'r(filters zCallbackFilter.filterN)rUrVrWrXr,r^r'r'r'r(rZs rZc@eZdZddZdS)RequireDebugFalsecCstj SrrDEBUGr]r'r'r(r^szRequireDebugFalse.filterNrUrVrWr^r'r'r'r(r` r`c@r_)RequireDebugTruecCstjSrrar]r'r'r(r^szRequireDebugTrue.filterNrcr'r'r'r(rerdrecs4eZdZdZfddZfddZddZZS)ServerFormatterz%d/%b/%Y %H:%M:%Scst|_tj|i|dSr)rrr+r,)r1rNrOr2r'r(r,szServerFormatter.__init__cs|j}t|dd}|rsd|krdkrnn|j|}nUd|kr(dkr1nn|j|}nB|dkr<|j|}n7d|krFdkrOnn|j|}n$|dkrZ|j|}nd|krddkrmnn|j|}n|j |}| rt |d s| ||j |_||_t|S) N status_codei,di0i server_time)msggetattrr HTTP_SUCCESS HTTP_INFOHTTP_NOT_MODIFIED HTTP_REDIRECTHTTP_NOT_FOUNDHTTP_BAD_REQUESTHTTP_SERVER_ERRORuses_server_timehasattr formatTimedatefmtrlr+r)r1rGrmrgr2r'r(rs(   zServerFormatter.formatcCs|jddkS)Nz {server_time}r)_fmtfindrQr'r'r(rvsz ServerFormatter.uses_server_time)rUrVrWdefault_time_formatr,rrvrYr'r'r2r(rfs   rf)responser:loggerrrBcGslt|ddrdS|dur|jdkrd}n |jdkrd}nd}t|||g|R|j|d |d d |_dS) a Log errors based on HttpResponse status. Log 5xx responses as errors and 4xx responses as warnings (unless a level is given as a keyword argument). The HttpResponse status_code and the request are passed to the logger's extra parameter. _has_been_loggedFNrkerrorrjwarninginfo)rgr:)extrarBT)rnrgr)rKr}r:r~rrBrNr'r'r( log_responses&    r)r logging.configr django.confr django.corerdjango.core.mailrdjango.core.management.colorrdjango.utils.module_loadingr getLoggerrequest_loggerr#r)Handlerr*FilterrZr`re Formatterrfrr'r'r'r(sf         1 ;'