Writing logs to html file using log4cplus in c ++ linux

We are using Log4cplus to generate logs on our Linux based home device. These logs are currently available on the home device running the web server. We also display this log file 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 via a web server with html formatted logs. log4j supports html formatted output logs, however we haven't found a way to generate html formatted logs using log4cplus. This post should collect ideas on how this can be done using log4cplus. Either in log4cplus or after processing, but in real time, as we look for logs in real time.

+3


source to share


2 answers


aha Might be a starting point for creating an html file, but for richer formatting you could probably write some script using awk to html-ize your output.

For example, given 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 create some valid html table based on the first three fields:



#!/usr/bin/awk -f

BEGIN { print "<table>"; }
      { print "<tr><td>" $1 "<td></td>" $2 "<td></td>" $3  "</td></tr>"    }
END   { print "</table>"  }

      

Just open it up.

To get real-time processing, you need to demote it .

+1


source


log4cplus currently (2015-04-18) does not support HTML output in any way. You could fake it with a mock. Or you can write your own Appender

instance.



0


source







All Articles