We are using Log4cplus to generate logs in our Linux based home appliance. These logs are currently available on the home appliance on which a web server is running. We also show this logfile through a web browser. However since the log file is text (i.e. not in html format), the file is not formatted and it is difficult to view each log separately.
We would like to view these logs through the web server with logs formatted at html. log4j supports output logs in html format, however we have not found a way to generate html formatted logs using log4cplus. This posting is to gather ideas of how this may be possible to do this using log4cplus. Either within log4cplus or post processing but real-time since we are looking for logs in real-time.
aha Could be a starting point to produce an html file, but to get a richer formatting you could probably write some script using awk to html-ize your output.
For example, considering the following output file:
2014-07-02 20:52:39 DEBUG className:200 - This is debug message
2014-07-02 20:52:39 DEBUG className:201 - This is debug message2
The following script will produce some valid html table based on the three first fields:
#!/usr/bin/awk -f
BEGIN { print "<table>"; }
{ print "<tr><td>" $1 "<td></td>" $2 "<td></td>" $3 "</td></tr>" }
END { print "</table>" }
Just expand on this.
To get realtime handling, you will need to daemonize it.
log4cplus currently (2015-04-18) does not support HTML formatted file output in any specific way. You could sort of fake it using a layout. Or you could write your own Appender
instance.
来源:https://stackoverflow.com/questions/29692159/write-logs-in-html-file-using-log4cplus-in-c-linux