AlkantarClanX12

Your IP : 18.223.43.106


Current Path : /usr/lib/python3.6/site-packages/tuned/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/tuned/__pycache__/logs.cpython-36.pyc

3

�<�e��
@sddlZddlZddlZddlZddlZddlZddljZddlZddl	Z	ddl
Z
yddlmZWnddlmZYnXdgZ
daiZe
j�ZGdd�de�Zdd�Zdd	�Zd
d�Zdd�ZGd
d�dej��Zejejej�eje�ejej�dS)�N)�StringIO�getc@seZdZdd�ZdS)�
LogHandlercCs||_||_dS)N)�handler�stream)�selfrr�r�/usr/lib/python3.6/logs.py�__init__szLogHandler.__init__N)�__name__�
__module__�__qualname__r
rrrr	rsrcCs<tj�}tjtj}d}xt|�D]}||j|�7}q"W|S)N�)�randomZSystemRandom�stringZ
ascii_lettersZdigits�rangeZchoice)Zlength�r�chars�res�irrr	�_random_stringsrc
Cs�t��x&td�D]}td�}|tkrPqWdSt�}tj|�}|j|�tjd�}|j	|�t
j|�t||�}|t|<t
j
d|�|SQRXdS)N�
�z%%(levelname)-8s %(name)s: %(message)szAdded log handler %s.)�log_handlers_lockrr�log_handlersr�logging�
StreamHandler�setLevel�	Formatter�setFormatter�root_logger�
addHandlerr�debug)Z	log_levelr�tokenrrZ	formatter�log_handlerrrr	�log_capture_start$s"




r%cCsjt�\yt|}Wntk
r&dSX|jj�}|jj�tj|j�t|=tj	d|�|SQRXdS)NzRemoved log handler %s.)
rr�KeyErrorr�getvalue�closer �
removeHandlerrr")r#r$Zcontentrrr	�log_capture_finish8s

r*cCs|tdkrtjd�atj�j}|jd}|dkr6d}tS|jd�rp|jdd�\}}tj	|�}|j
�|jd�|Sdsxt�dS)	NZtunedr�__main__ztuned.�.�ZNOTSETF)
r rZ	getLogger�inspectZcurrentframe�f_back�f_locals�
startswith�splitZgetChild�remove_all_handlersr�AssertionError)Zcalling_module�name�rootZchildZchild_loggerrrr	rEs





csxeZdZdZejd�ZdZdZ�fdd�Z	dd�Z
dd	�Zej
ejejfd
d�Zdd
�Zedd��Zedd��Z�ZS)�TunedLoggerz!Custom TuneD daemon logger class.z1%(asctime)s %(levelname)-8s %(name)s: %(message)sNcs*tt|�j||�|jtj�|j�dS)N)�superr7r
rr�INFO�switch_to_console)r�args�kwargs)�	__class__rr	r
^szTunedLogger.__init__cOs|jtj|f|�|�dS)N)�log�consts�LOG_LEVEL_CONSOLE)r�msgr;r<rrr	�consolecszTunedLogger.consolecCs |j�|j�|j|j�dS)N)�_setup_console_handlerr3r!�_console_handler)rrrr	r:fszTunedLogger.switch_to_consolecCs&|j|||�|j�|j|j�dS)N)�_setup_file_handlerr3r!�
_file_handler)r�filename�maxBytes�backupCountrrr	�switch_to_filekszTunedLogger.switch_to_filecCs"|j}x|D]}|j|�qWdS)N)�handlersr))rZ	_handlersrrrr	r3rs
zTunedLogger.remove_all_handlerscCs*|jdk	rdStj�|_|jj|j�dS)N)rDrrr�
_formatter)�clsrrr	rCws

z"TunedLogger._setup_console_handlercCsj|jdk	rdStjj|�}|dkr&d}tjj|�s<tj|�tjj|t	|�t	|�d�|_|jj
|j�dS)Nrr,)rHrI)rF�os�path�dirname�exists�makedirsrrKZRotatingFileHandler�intrrL)rMrGrHrIZ
log_directoryrrr	rEs

zTunedLogger._setup_file_handler)rrr
�__doc__rrrLrDrFr
rBr:r?ZLOG_FILEZLOG_FILE_MAXBYTESZLOG_FILE_COUNTrJr3�classmethodrCrE�
__classcell__rr)r=r	r7Xs
r7) �atexitrZlogging.handlersrNZos.pathr.Ztuned.constsr?rrZ	threadingr�io�__all__r rZLockr�objectrrr%r*rZgetLoggerClassr7ZaddLevelNamer@ZLOG_LEVEL_CONSOLE_NAMEZsetLoggerClass�registerZshutdownrrrr	�<module>s4

6