Well, if you never edit the log by hand then it's quite easy to ensure that the last line of the file is always
</body></html>
which is 14 characters. So, you open the file for appending, seek to 14 bytes before the end and just write, it will overwrite the end tags.

Though I really recommend you log to XML and then use XSLT to transform to (X)HTML for display.