a
    ø£Be·  ã                   @   sh   d Z ddlZddlZddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ G dd„ deƒZdS )z&A mixin for adding a debug log file.

é    N)ÚUnicode)ÚConfigurablec                   @   s(   e Zd Zedddd�Zejdd„ ƒZdS )ÚDebugLogFileMixinÚ Tz"Path to use for the debug log file)ÚconfigÚhelpc              
   c   s°  | j }tj |¡r tj |d¡}|s@tjddd�\}}t |¡ | j}|j	D ]}| 
| j¡ qL| 
d¡ tj|dddd	�}| j| j| jd
�}| |¡ | 
d¡ | |¡ z
d V  W n® t�yb } z”t ¡ \}}}	t |j||	¡}
|
D ]}| j |¡ qèt|tƒ�rt d|›�¡ ‚ t d¡ t |
d  ¡ ¡ t d|›�¡ |  d¡ W Y d }~nHd }~0 0 |  |¡ | !¡  | ¡  zt "|¡ W n t#�y    Y n0 |  |¡ d S )Nzjupyterlab-debug.logzjupyterlab-debug-z.log)ÚprefixÚsuffixÚDEBUGÚwÚutf8T)Údelay)ÚfmtÚdatefmtz1An error occurred. See the log file for details: zAn error occurred.éÿÿÿÿzSee the log file for details: é   )$Údebug_log_pathÚosÚpathÚisdirÚjoinÚtempfileÚmkstempÚcloseÚlogÚhandlersÚsetLevelÚ	log_levelÚloggingÚFileHandlerZ_log_formatter_clsZ
log_formatZlog_datefmtÚsetFormatterÚ
addHandlerÚ	ExceptionÚsysÚexc_infoÚ	tracebackÚformat_exceptionÚ	__class__ÚdebugÚ
isinstanceÚ
SystemExitÚwarningsÚwarnÚstripÚexitÚremoveHandlerÚflushÚremoveÚFileNotFoundError)ÚselfÚlog_pathÚhandler   ÚhZ_debug_handlerZ_log_formatterÚexÚ_Úexc_tracebackÚmsgÚline© r<   úV/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyterlab/debuglog.pyÚdebug_logging   sJ    







 
zDebugLogFileMixin.debug_loggingN)Ú__name__Ú
__module__Ú__qualname__r   r   Ú
contextlibÚcontextmanagerr>   r<   r<   r<   r=   r      s   r   )Ú__doc__rB   r   r   r#   r   r%   r+   Z	traitletsr   Ztraitlets.configr   r   r<   r<   r<   r=   Ú<module>   s   