3

I am writing a logger in C++ that generates an HTML5 output in real time. So the HTML file must be readable at any time, even while growing.

So far I open the file, I delete the last few lines that close the block (</body></html>), I add the new log messages and I close the block again.

Is this a good approach, or are there any better solutions?

Pietro
  • 12,086
  • 26
  • 100
  • 193
  • This question may be of interest. http://stackoverflow.com/questions/29692159/write-logs-in-html-file-using-log4cplus-in-c-linux – niyasc Aug 08 '16 at 12:18
  • It's a file concurency access issue, no ? – Al Foиce ѫ Aug 08 '16 at 12:18
  • 1
    I would want to avoid outputting `HTML` directly. If possible I would rather output just the log data and have some other program (filter) convert the log file to `HTML` on-request. (Or output `HTML` elements and just add the surrounding `` & `` tags upon request). – Galik Aug 08 '16 at 12:22
  • @Galik - That is what I actually do. My tools basically converts a classic log file into an HTML one, in real time. – Pietro Aug 08 '16 at 12:31
  • @AlFonce - Not really, it is just a real time HTML update issue. The file can be locked while updating. – Pietro Aug 08 '16 at 12:34

1 Answers1

1
  1. Another approach would be to read (through XMLHttpRequest) the log file directly by JavaScript inside HTML file and generate HTML within the browser. This may end up being quite slow for large log files though (100 MB+).
  2. If the only thing you need is just to wrap your textual log file with a header and a footer, you can just create a markup as needed and add an <iframe src="log.txt"> tag between a header and footer, which src attribute would point to the raw textual log file. This wouldn't suite you if you need to format the log somehow, of course.
Andrew Sklyarevsky
  • 2,095
  • 14
  • 17
  • I cannot follow option 1, since I do not want any external tools involved, but just a few lines of code inside my project. Regarding option 2, I provide syntax highlighting directly in the HTML file, and this is dependent on the text file contents and a set of internal parameters. So I think this is not an option I can follow, either. – Pietro Aug 08 '16 at 13:09