3 ft`r(@sddlmZddlmZddlZddlZddlZddlZddlZ ddl Z ddl Z ddl Z ddl Z ddlZddlZddlZdZe jZe jZe jZe jZe jZdZdZdZdZd d ZGd d d eZee je je je je je jeeeed ZddZee je jdZ ddZ!ddZ"d%Z#ddZ$Gddde j%j&Z'ddZ(ddZ)Gdd d eZ*Gd!d"d"eZ+e j,j-j.ee j,j-j/ee j,j-j0ee j,j-j1ee j,j-j2ee j,j-j3ee j,j-j4eiZ5Gd#d$d$e j,j-Z6e6Z7e j,j8j9e7dS)&)absolute_import)unicode_literalsNdcsddfdd}|S)zGMethod decorator turning the method into noop on second or later calls.c_sdS)N)Z_argsZ_kwargsr r /usr/lib/python3.6/logging.pynoop3szonly_once..noopcs"|f||t|jdS)N)setattr__name__)selfargskwargs)funcr r r swan_song5szonly_once..swan_songr )rrr )rr r only_once1src@seZdZddZddZdS)_MaxLevelFiltercCs ||_dS)N) max_level)rrr r r __init__;sz_MaxLevelFilter.__init__cCs|j|jkrdSdS)Nr)Zlevelnor)rrecordr r r filter>s z_MaxLevelFilter.filterN)r __module__ __qualname__rrr r r r r:sr) rrrrrr cCs(d|kodknsttj|tS)Nrr )AssertionError_VERBOSE_VAL_MAPPINGgetTRACE) cfg_errvalr r r _cfg_verbose_val2levelQsr&)rrrcCs*d|kodknsttj|tjS)Nrr )r!_ERR_VAL_MAPPINGr#loggingWARNING)r%r r r _cfg_err_val2level^sr*cCs|dS)Nz.gzr )namer r r compression_namercsr,icCs\t|d>}tj|d&}x|jt}|s,P|j|qWWdQRXWdQRXtj|dS)Nrbwb)opengzipread CHUNK_SIZEwriteosremove)sourcedestZsfZwfdatar r r compression_rotatorjs  "r:cs&eZdZd fdd ZddZZS) MultiprocessRotatingFileHandlerarNFcs.tt|j||||||tjjdd|_dS)Nz /var/log/T)superr;rdnflockZbuild_log_lock rotate_lock)rfilenamemodemaxBytes backupCountencodingZdelay) __class__r r rvs z(MultiprocessRotatingFileHandler.__init__cCsxyR|j|rD|j*tj|jj}|jtj|j|WdQRXtj j ||dSt j j t j jfk r~tjdYqtk r|j|dSXqWdS)Ng{Gz?)ZshouldRolloverr@r5statZ baseFilenamest_modeZ doRolloverchmodr(Z FileHandleremitr> exceptionsZProcessLockErrorZThreadLockErrortimeZsleep ExceptionZ handleError)rrrBr r r rJ{s  z$MultiprocessRotatingFileHandler.emit)r<rrNF)r rrrrJ __classcell__r r )rFr r;usr;cCsltjj|s,tjjtjj|tjj|t|||d}t j dd}t j |_ |j||rht|_t|_|S)N)rCrDz%%(asctime)s %(levelname)s %(message)sz%Y-%m-%dT%H:%M:%S%z)r5pathexistsr>utilZ ensure_dirdirnameZtouchr;r(Z FormatterrLZ localtimeZ converterZ setFormatterr:Zrotatorr,Znamer)logfilelog_size log_rotate log_compresshandlerZ formatterr r r _create_filehandlers   rXcCs|jttjjdS)N)logINFOr>constZ LOG_MARKER)Zloggerr r r _paint_marksr\c@sBeZdZddZeddZeddZeddZd d d Zd S)LoggingcCsPd|_|_tjtdtjtdtjtdtjtdtjddt_ dS)NDDEBUGSUBDEBUGr$ALLTF) stdout_handlerstderr_handlerr(Z addLevelNamer^r_r$r`ZcaptureWarningsZraiseExceptions)rr r r rs      zLogging.__init__cCsttjd}|jttjtj}|jt|jt tj |j |||_ tjtj }|jt |j |||_dS)Nr>)r( getLoggersetLevelr$Z StreamHandlersysstdoutrZZ addFilterrr) addHandlerrastderrrb)r logger_dnfrfrhr r r _presetups        zLogging._presetupc Cstjd}|jttjj|tjj }t ||||}|j||j |tjd} | j |tjd} | jttjj|tjj }t ||||}| j |t jjj ||tktjd} d| _| jttjj|tjj}t ||||}| j |dS)Nr>z py.warningslibrepozdnf.rpmF)r(rcrdr$r5rOjoinr>r[ZLOGrXrgZ LOG_LIBREPOlibdnfZrepoZ LibrepoLogr`Z propagater_ZLOG_RPM) r logfile_levellogdirrTrUrVrirSrWlogger_warningsZlogger_librepo logger_rpmr r r _setup_file_loggerss(           zLogging._setup_file_loggersc Cs|j|j|||||tjd}|j|jtjd} | j|j| j|jtjd} |jjt|jjtt | t | |jj||jj|dS)Nz py.warningszdnf.rpmr>) rjrrr(rcrgrbrardr)r\) rZ verbose_levelZ error_levelrnrorTrUrVrprqrir r r _setups         zLogging._setupFc Csft|j}t|j}t|j}|j}|j}|j}|j} |rL|j ||||| S|j ||||||| SdS)N) r&Z debuglevelr*Z errorlevelZ logfilelevelrorTrUrVrrrs) rZconfZfile_loggers_onlyZverbose_level_rZ error_level_rZlogfile_level_rrorTrUrVr r r _setup_from_dnf_confs   zLogging._setup_from_dnf_confN)F) r rrrrrjrrrsrtr r r r r]s    r]c@seZdZddZddZdS)TimercCs||_tj|_dS)N)whatrLstart)rrvr r r rszTimer.__init__cCs6tj|j}d|j|df}tjdjt|dS)Nztimer: %s: %d msir>)rLrwrvr(rcrYr^)rZdiffmsgr r r __call__szTimer.__call__N)r rrrryr r r r rusrucs$eZdZfddZddZZS)LibdnfLoggerCBcs*tt|jtjd|_tjd|_dS)Nr>rk)r=rzrr(rc _dnf_logger_librepo_logger)r)rFr r rs zLibdnfLoggerCB.__init__cGsft|dkr|\}}nt|dkr.|\}}}}|tjjjkrP|jjt||n|jjt||dS)zoLog message. source -- integer, defines origin (libdnf, librepo, ...) of message, 0 - unknown rrN) lenrmutilsLoggerZLOG_SOURCE_LIBREPOr|rY_LIBDNF_TO_DNF_LOGLEVEL_MAPPINGr{)rr7rlevelmessagerLpidr r r r4s    zLibdnfLoggerCB.write)r rrrr4rNr r )rFr rzs rzi):Z __future__rrZdnf.exceptionsr>Z dnf.constZdnf.lockZdnf.utilZ libdnf.repormr(Zlogging.handlersr5rerLwarningsr1Z SUPERCRITICALZCRITICALZERRORr)rZDEBUGr^r_r$r`robjectrr"r&r'r*r,r3r:ZhandlersZRotatingFileHandlerr;rXr\r]rur~rZLevel_CRITICALZ Level_ERRORZ Level_WARNINGZ Level_NOTICEZ Level_INFOZ Level_DEBUGZ Level_TRACErrzZlibdnfLoggerCBZLogZ setLoggerr r r r sv      a