U
    W+d                     @   sT   d dl Z d dlmZ d dlmZ d dlZd dlmZ d dlmZ G dd deZ	dS )    N)datetime)Thread)RequestHook)	long_typec                   @   s,   e Zd ZdZdddZdddZdd	 Zd
S )RequestLoggerzf
    This class implements a request logger that uses a single thread to
    write to a log file.
    /tmp/request_log.csvc                 C   s,   t |d| _td| _t| jd  d S )Nwd   )target)openrequest_log_fileQueuerequest_log_queuer   _request_log_workerstart)selffilename r   3/tmp/pip-unpacked-wheel-dlxw5sjy/boto/requestlog.py__init__   s    zRequestLogger.__init__Fc           	   	   C   sz   |rdn| d}t }|d}||j }|jt|j|jd d  d  d }| j	
d||j|||jd f  d S )	Nr   zContent-Lengthz%Y-%m-%d %H:%M:%S   i  g    .Az'%s', '%s', '%s', '%s', '%s'
Action)	getheaderr   nowstrftime
start_timemicrosecondsr   secondsdaysr   putstatusparams)	r   requestresponseerrorlenr   timetddurationr   r   r   handle_request_data   s    

&z!RequestLogger.handle_request_datac                 C   sZ   z0| j d}| j| | j  | j   W q    dd l}|jtj	d Y q X q d S )NTr   )file)
r   getr   writeflush	task_done	traceback	print_excsysstdout)r   itemr/   r   r   r   r      s    
z!RequestLogger._request_log_workerN)r   )F)__name__
__module____qualname____doc__r   r)   r   r   r   r   r   r   
   s   


r   )
r1   r   	threadingr   r   Z
boto.utilsr   Zboto.compatr   r   r   r   r   r   <module>   s   