o ]Lb@sddlmZddlZddlmZmZddlmZmZm Z dddZ dd Z d d Z Gd d d e ZGddde ZGddde ZdS))absolute_importN)encodingpycompat)dateutilprocutil stringutilc sfdd}|dkrNz|}Wn tyYn3w|j|krN|}t|dddD]}|d||dfd||fdq/|||dkoK|dd|d d d S) z{Open log file in append mode, with optional rotation If maxsize > 0, the log file will be rotated up to maxfiles. c sz|Wn%ty,}z|jtjkr"d|t|jfWYd}~nd}~wwz|r9||WdSWdStyi}z"|jtjkr^d||t|jfWYd}~dSWYd}~dSd}~ww)Ns warning: cannot remove '%s': %s s(warning: cannot rename '%s' to '%s': %s ) unlinkOSErrorerrnoENOENTdebugr strtolocalstrerrorrename)oldpathnewpatherruivfs7/usr/lib/python3/dist-packages/mercurial/loggingutil.pyrotates2  zopenlogfile..rotaterrs%s.%d)rrs.1aF)makeparentdirs)statr st_sizejoinrxrange) rrnamemaxfilesmaxsizerstpathirrr openlogfiles     r'cCs"tjdd}t}d|||fS)Ns%Y/%m/%d %H:%M:%S)formats %s (%d)> %s)rdatestrrgetpid)msgdatepidrrr_formatloglineCs r.cCsd|vp||vS)N*r)eventtrackedrrr _matcheventIsr2c@s*eZdZdZd ddZddZddZd S) fileloggerz;Basic logger backed by physical file with optional rotationrcCs&||_||_t||_||_||_dSN)_vfs_nameset_trackedevents _maxfiles_maxsize)selfrr!r1r"r#rrr__init__Ps   zfilelogger.__init__cC t||jSr4r2r8r;r0rrrr1W zfilelogger.trackedc Cst|}z't||j|j|j|jd}||WdWdS1s$wYWdStyK}z|d|jt |fWYd}~dSd}~ww)N)r"r#cannot write to %s: %s ) r.r'r5r6r9r:writeIOErrorr r forcebytestr)r;rr0r+optslinefprrrrlogZs( &zfilelogger.logNrr__name__ __module__ __qualname____doc__r<r1rHrrrrr3Ms   r3c@(eZdZdZddZddZddZdS) fileobjectloggerz'Basic logger backed by file-like objectcCs||_t||_dSr4)_fpr7r8)r;rGr1rrrr<oszfileobjectlogger.__init__cCr=r4r>r?rrrr1sr@zfileobjectlogger.trackedc Csnt|}z|j||jWdSty6}z|dt|jjt|fWYd}~dSd}~ww)NrA) r.rQrBflushrCr rrDr!)r;rr0r+rErFrrrrrHvs  zfileobjectlogger.logNrJrrrrrPls  rPc@rO) proxyloggerz4Forward log events to another logger to be set latercCs d|_dSr4)logger)r;rrrr<s zproxylogger.__init__cCs|jduo |j|Sr4)rTr1r?rrrr1szproxylogger.trackedcCs$|jdusJ|j||||dSr4)rTrH)r;rr0r+rErrrrHszproxylogger.logNrJrrrrrSs  rSrI) __future__rr rrutilsrrrr'r.r2objectr3rPrSrrrrs  *