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

空扰寡人 提交于 2019-12-22 09:53:14

问题


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.


回答1:


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.




回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!