Write logs in html file using log4cplus in C++ lin

2019-05-10 20:42发布

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.

2条回答
Anthone
2楼-- · 2019-05-10 21:00

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.

查看更多
唯我独甜
3楼-- · 2019-05-10 21:10

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.

查看更多
登录 后发表回答