Trimming Large Log File
If you have a very large web access log and you cannot afford to shutdown the web server in order to cleanup or rotate the log file, you may want to use this trick. Copy the content to a separate file, if the content is worth saving. Once that is done, copy the
/dev/null
to overwrite the existing web access log. Don't worry, your web server is still having the same file handler to the existing web access log.
I tested it out by writing a simple Tcl program to append line to a file every 0.1 seconds to simulate the log generation. In a separate terminal, I overwrite the file with /dev/null. The file got trimmed and the Tcl program still keep on appending to the file. The Tcl program looks like this:
$ tclsh % set fp [open access.log a] % fconfigure $fp -buffering line % set n 0 % while 1 { puts $fp "[incr n] appending line to log file ..." after 100 }
You may loose some records but at least you do not have to worry about the large log file filling up your file system.
0 Comments:
Post a Comment
<< Home