Έλεγχος για rotation log αρχείου

Christos Ricudis ricudis at itc.auth.gr
Wed Sep 16 11:23:26 EEST 2009


George Notaras wrote:
> Πού θα βασιστεί ένας έλεγχος για το αν ένα logfile έχει υποστεί
> rotation; Τι ακριβώς συμβαίνει στο αρχείο κατά το rotation;
>
> Θέλω να κάνω κάτι σαν το "tail -f" σε python, το οποίο όμως να ανιχνεύει
> το rotation και θέλω να σιγουρευτώ για κάποια πράγματα.
>
>   

H swsth apanthsh s'ayth thn erwthsh einai "kalytera na mhn ksereis".

Oi dyo profaneis tropoi na ginei rotate ena log file einai :

1) close the log, rename(3) it to log.XXX, open a new log file, continue 
writing to it.

2) copy the old log file to log.XXX, unlink(3) or truncate(3) it,  open 
a new log file, continue writing to it.

O monos tropos na anixneuseis ti egine, einai na anoikseis ksana to log 
file - epeidh o file descriptor ton opoio exeis hdh anoixto den 
prokeitai na katalabei xristo sthn periptwsh pou to log file exei ginei 
rename h unlink kai oxi truncate - na kaneis mia stat(3), kai na 
sygkrineis to mege8os me to (apo8hkeymeno apo to prohgoumeno iteration 
ths stat(3)).

An to arxeio exei mikrynei, kapoios to ekane rotate.

Ektos an kapoios prolabe na grapsei arketa dedomena sto endiameso gia na 
spasei ayth th logikh.

H swsth lysh gi ayto poy 8eleis na kaneis einai na pairneis ena 
antigrafo toy log output *prin* katalhksei sto log file to opoio ginetai 
rotate. Analogws me to ti log file einai, poios to grafei, ktl ktl, 
yparxoun arketoi tropoi na ginei ayto, all of which involve pipes.

Sthn kalyterh periptwsh, mporeis na peis ston log writer "grapse ayto to 
log sto shmeio A (arxeio) kai sto shmeio B (pipe). Esy to diabazeis apo 
to pipe.

Sth xeiroterh periptwsh, les ston log writer "grapse ayto to log sto 
shmeio B (pipe)". Esy to diabazeis apo to pipe, kai taytoxronws to 
kaneis "tail -f" kai to grafeis sto shmeio A (arxeio) to opoio meta 
ginetai rotate.

Genikws to log rotation sto unix einai kati pou gia para pollous logous 
aggizei ta oria tou entelws broken.


More information about the Linux-greek-users mailing list