mò =¬rCc@s£dZdkZdkZdkZdkZdkZdfd„ƒYZdefd„ƒYZeieƒdefd„ƒYZ eie ƒdfd „ƒYZ dS( s! A rotating, browsable log file. Nt BaseLogFilecBsntZdZddgZed„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z RS( s7The base class for a log file that can be rotated. twritetrotatecCs®||_tii|iƒpt‚||_tii||ƒ|_|djoCtii |iƒo-t tdƒoti |iƒd|_n ||_|i ƒdS(Ntchmodi(t directorytselftostpathtisdirtAssertionErrortnametjoint defaultModetNonetexiststhasattrtstatt _openFile(RR RR ((tn/home/radix/Projects/Twisted/branches/releases/twisted-core-2.5.x-2329-2/Twisted.exp/twisted/python/logfile.pyt__init__s  3 cCs t‚dS(sQOverride with a method to that returns true if the log should be rotatedN(tNotImplementedError(R((Rt shouldRotate#scCs®d|_tii|iƒo/t|iddƒ|_|iiddƒnt|iddƒ|_|idj o4yti |i|iƒWqªt j oqªXndS(sOpen the log file.isr+iisw+N( RtclosedRRRtopent_filetseekR R RtOSError(R((RR(s cCs|iiƒ}|d=|S(NR(Rt__dict__tcopytstate(RR((Rt __getstate__8scCs||_|iƒdS(N(RRRR(RR((Rt __setstate__=s cCs9|iƒo|iƒ|iƒn|ii|ƒdS(sWrite some data to the file.N(RRtflushRRRtdata(RR!((RRAs   cCs|iiƒdS(sFlush the file.N(RRR (R((RR HscCs#d|_|iiƒd|_dS(sZClose the file. The file cannot be used once it has been closed. iN(RRRtcloseR (R((RR"Ls  cCs t|iƒS(s,Return a LogReader for the current log file.N(t LogReaderRR(R((Rt getCurrentLogUs(t__name__t __module__t__doc__t synchronizedR RRRRRRR R"R$(((RRs         tLogFilecBs\tZdZded„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z RS( seA log file that can be rotated. A rotateLength of None disables automatic log rotation. i@BcCs#ti||||ƒ||_dS(N(RRRR RR t rotateLength(RR RR*R ((RR^scCs#ti|ƒ|iiƒ|_dS(N(RRRRttelltsize(R((RRbs cCs|io|i|ijS(s9Rotate when the log file size is larger than rotateLengthN(RR*R,(R((RRfscCs=d|i|f}tii|ƒp td‚nt|ƒS(s9Given an integer, return a LogReader for an old log file.s%s.%dsno such logfile existsN(RRt identifiertfilenameRRt ValueErrorR#(RR-R.((RtgetLogjs  cCs)ti||ƒ|it|ƒ7_dS(sWrite some data to the fileN(RRRR!R,tlen(RR!((RRqscCsÄti|itiƒoti|itiƒpdSn|iƒ}|iƒx<|D]4}ti d|i|fd|i|dfƒqWW|i i ƒti |id|iƒ|i ƒdS(s§Rotate the file and create a new one. If it's not possible to open new logfile, this will fail silently, and continue logging to old logfile. Ns%s.%dis%s.1(RtaccessRRtW_OKRtlistLogstlogstreversetitrenameRR"R(RR7R5((RRvs2  2 cCsƒg}xltid|iƒD]T}y8tti|dƒdƒ}|o|i |ƒnWqt j oqXqW|i ƒ|S(s;Return sorted list of integers - the old logs' identifiers.s%s.*t.iÿÿÿÿN( tresulttglobRRR tinttstringtsplittcountertappendR/tsort(RR R?R:((RR4†s  cCsti|ƒ}|d=|S(NR,(RRRR(RR((RR“s( R%R&R'R RRRR0RRR4R(((RR)Ys       t DailyLogFilecBsVtZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z RS( sFA log file that is rotated daily (at or after midnight localtime) cCs3ti|ƒ|iti|iƒdƒ|_dS(Ni(RRRttoDateRRRtlastDate(R((RRžs cCs|iƒ|ijS(s1Rotate when the date has changed since last writeN(RRCRD(R((RR¢scGsti|Œd S(s Convert a unixtime to (year, month, day) localtime tuple, or return the current (year, month, day) localtime tuple. This function primarily exists so you may overload it with gmtime, or some cruft to make unit testing possible. iN(ttimet localtimetargs(RRG((RRC¦scCsGyditt|ƒƒSWn&ditt|i|ƒƒƒSnXdS(s>Return the suffix given a (year, month, day) tuple or unixtimet_N(R tmaptstrt tupledateRRC(RRK((Rtsuffix°s cCsm|i|ƒ|ijo|iƒSnd|i|i|ƒf}tii |ƒp t d‚nt |ƒS(s:Given a unix time, return a LogReader for an old log file.s%s.%ssno such logfile existsN( RRCR-RDR$RRLR.RRR/R#(RR-R.((RR0¸s cCs/ti||ƒt|i|iƒƒ|_dS(sWrite some data to the log fileN(RRRR!tmaxRDRC(RR!((RRÁscCs¢ti|itiƒoti|itiƒpdSnd|i|i|iƒf}tii |ƒodSn|i i ƒti |i|ƒ|i ƒdS(s§Rotate the file and create a new one. If it's not possible to open new logfile, this will fail silently, and continue logging to old logfile. Ns%s.%s(RR2RRR3RRLRDtnewpathRRR"R8R(RRN((RRÉs2 cCsti|ƒ}|d=|S(NRD(RRRR(RR((RRØs( R%R&R'RRRCRLR0RRR(((RRB›s      R#cBs,tZdZd„Zdd„Zd„ZRS(sRead from a log file.cCst|dƒ|_dS(Ntr(RR RR(RR ((RRãsi cCsIg}x<t|ƒD].}|iiƒ}|pPn|i|ƒqW|S(s‡Read a list of lines from the log file. This doesn't returns all of the files lines - call it multiple times. N( R:trangetlinesR7RRtreadlinetlineR@(RRQR7R:RS((Rt readLinesæs cCs|iiƒdS(N(RRR"(R((RR"ós(R%R&R'RRTR"(((RR#às   ( R'RR;R=REt threadableRR)t synchronizeRBR#( RUR=R#R;RRER)RRB((Rt? s$ G? B