
     h              
          d dl Z d dlZ d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ  e j        d          Zd	d
ddiddiddddddiddgddddddddgdddddgdddgdd
d d!d"Zd# Z G d$ d%e j                  Z G d& d'e j                  Z G d( d)e j                  Z G d* d+e j                  Z G d, d-e j                  Zddeddd.d/ZdS )0    N)copy)settings)mail)get_connection)color_style)import_stringzdjango.request   F()z"django.utils.log.RequireDebugFalsez!django.utils.log.RequireDebugTrue)require_debug_falserequire_debug_truedjango.serverz django.utils.log.ServerFormatterz[{server_time}] {message}{)r
   formatstyleINFOr   zlogging.StreamHandler)levelfiltersclass)r   r   	formatterERRORr   z"django.utils.log.AdminEmailHandler)consoler   mail_adminsr   r   )handlersr   )r   r   	propagate)djangor   )versiondisable_existing_loggersr   
formattersr   loggersc                     | rBt          |           }t          j                            t                     |r ||           d S d S d S N)r   loggingconfig
dictConfigDEFAULT_LOGGING)logging_configlogging_settingslogging_config_funcs      O/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/django/utils/log.pyconfigure_loggingr*   C   sd     2+N;;!!/222  	2 0111112 2	2 	2    c                   <     e Zd ZdZd	 fd	Zd Zd Zd Zd Z xZ	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.
    FNc                     t                                                       || _        || _        t	          |pt
          j                  | _        d S r!   )super__init__include_htmlemail_backendr   r   DEFAULT_EXCEPTION_REPORTERreporter_class)selfr1   r2   r4   	__class__s       r)   r0   zAdminEmailHandler.__init__V   sL    (*+AhA
 
r+   c                    	 |j         }|j        d|j                            d          t          j        v rdndd|                                }n0# t          $ r# |j        d|                                }d }Y nw xY w|                     |          }t          |          }d |_
        d |_        |j
        r|j
        }nd |                                d f} | j        |g|R ddi}|                     |          d	|                                }| j        r|                                nd }|                     ||d|
           d S )Nz (REMOTE_ADDRinternalEXTERNALz IP): z: is_emailTz

)fail_silentlyhtml_message)request	levelnameMETAgetr   INTERNAL_IPS
getMessage	Exceptionformat_subjectr   exc_infoexc_textr4   r   get_traceback_textr1   get_traceback_html	send_mail)	r5   recordr>   subjectno_exc_recordrF   reportermessager=   s	            r)   emitzAdminEmailHandler.emit^   s   	nG    |''66(:OOO J#$ $ !!###GG  	 	 	"("2"2"2F4E4E4G4G4GHGGGG	 %%g.. V!%!%? 	9HHf//1148H&4&wIIIIIIKK&&&&'')))
 9=8ISx22444twt,WWWWWs   AA *B ?B c                 Z    t          j        ||g|R d|                                 i| d S )N
connection)r   r   rR   )r5   rL   rO   argskwargss        r)   rJ   zAdminEmailHandler.send_mail   sR    W	
#	
 	
 	
040A0A	
EK	
 	
 	
 	
 	
r+   c                 .    t          | j        d          S )NT)backendr<   )r   r2   r5   s    r)   rR   zAdminEmailHandler.connection   s    d&8MMMMr+   c                 V    |                     dd                               dd          S )z.
        Escape CR and LF characters.
        
z\nz\r)replace)r5   rL   s     r)   rE   z AdminEmailHandler.format_subject   s(     tU++33D%@@@r+   )FNN)
__name__
__module____qualname____doc__r0   rP   rJ   rR   rE   __classcell__r6   s   @r)   r-   r-   O   s         
 
 
 
 
 
"X "X "XH
 
 

N N NA A A A A A Ar+   r-   c                       e Zd ZdZd Zd ZdS )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.
    c                     || _         d S r!   callback)r5   rf   s     r)   r0   zCallbackFilter.__init__   s     r+   c                 4    |                      |          rdS dS )Nr	   r   re   r5   rK   s     r)   filterzCallbackFilter.filter   s     ==   	1qr+   N)r\   r]   r^   r_   r0   ri    r+   r)   rc   rc      s<         ! ! !    r+   rc   c                       e Zd Zd ZdS )RequireDebugFalsec                     t           j         S r!   r   DEBUGrh   s     r)   ri   zRequireDebugFalse.filter   s    >!!r+   Nr\   r]   r^   ri   rj   r+   r)   rl   rl      s#        " " " " "r+   rl   c                       e Zd Zd ZdS )RequireDebugTruec                     t           j        S r!   rn   rh   s     r)   ri   zRequireDebugTrue.filter   s
    ~r+   Nrp   rj   r+   r)   rr   rr      s#            r+   rr   c                   2     e Zd ZdZ fdZ fdZd Z xZS )ServerFormatterz%d/%b/%Y %H:%M:%Sc                 `    t                      | _         t                      j        |i | d S r!   )r   r   r/   r0   )r5   rS   rT   r6   s      r)   r0   zServerFormatter.__init__   s0     ]]
$)&)))))r+   c                 "   |j         }t          |dd           }|rd|cxk    rdk     rn n| j                            |          }nd|cxk    rdk     rn n| j                            |          }n|dk    r| j                            |          }nd|cxk    rdk     rn n| j                            |          }nf|dk    r| j                            |          }nEd|cxk    rdk     rn n| j                            |          }n| j        	                    |          }| 
                                r0t          |d	          s |                     || j                  |_        ||_         t                                          |          S )
Nstatus_code   i,  d   i0    i    server_time)msggetattrr   HTTP_SUCCESS	HTTP_INFOHTTP_NOT_MODIFIEDHTTP_REDIRECTHTTP_NOT_FOUNDHTTP_BAD_REQUESTHTTP_SERVER_ERRORuses_server_timehasattr
formatTimedatefmtr}   r/   r   )r5   rK   r~   rx   r6   s       r)   r   zServerFormatter.format   s   jfmT:: 	8k''''C'''''j--c22))))c)))))j**3//##j22377))))c)))))j..s33##j//44))))c)))))j11#66 j22377  "" 	G76=+I+I 	G!%!F!FF
ww~~f%%%r+   c                 >    | j                             d          dk    S )Nz{server_time}r   )_fmtfindrW   s    r)   r   z ServerFormatter.uses_server_time   s    y~~o..!33r+   )r\   r]   r^   default_time_formatr0   r   r   r`   ra   s   @r)   ru   ru      sf        -* * * * *& & & & &84 4 4 4 4 4 4r+   ru   )responser>   loggerr   	exceptionc                    t          |dd          rdS ||j        dk    rd}n|j        dk    rd}nd} t          ||          | g|R |j        |d	|d
 d|_        dS )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_loggedFNr|   errorr{   warninginfo)rx   r>   )extrarF   T)r   rx   r   )rO   r   r>   r   r   r   rS   s          r)   log_responser      s    ( x+U33 }3&&EE!S((EEEGFE	  $/
 
     !%Hr+   )r"   logging.configr   django.confr   django.corer   django.core.mailr   django.core.management.colorr   django.utils.module_loadingr   	getLoggerrequest_loggerr%   r*   Handlerr-   Filterrc   rl   rr   	Formatterru   r   rj   r+   r)   <module>r      s                                + + + + + + 4 4 4 4 4 4 5 5 5 5 5 5""#344  % 6 
 5
	  	41
 
 ,-,
 
 ,(
 
 -.9
 
 & #M2
 

 ))
 

 
G. .b	2 	2 	2?A ?A ?A ?A ?A ?A ?A ?AD    W^    " " " " " " " "
    w~   
$4 $4 $4 $4 $4g' $4 $4 $4T 
(% (% (% (% (% (% (%r+   