2

I have a requirement to log to an excel sheet in the server, the same way a normal log4j appender would except to an excel sheet (This is in java).

I currently have found no proper information about this. Is there any library that provides an appender or such which can be used? Also was wondering are there any implications of appending to an excel file instead of a normal text file log, performance, probable errors and such?

Jayan
  • 18,003
  • 15
  • 89
  • 143
MilindaD
  • 7,533
  • 9
  • 43
  • 63
  • have you considered http://logsaw.sourceforge.net/. It is mentioned in this question: http://stackoverflow.com/questions/144807/java-log-viewer – Jayan Aug 06 '12 at 05:22

3 Answers3

3

Directly logging to an excel sheet does not seems to be good idea. You are mixing two responsibilities "logging" and "analyzing the logs" into one code.

You may want to import data to a spreadsheet for specific analysis. In that case you may want specific formatting (about which data goes to what table )as well. Consider writing a specific parser and then importing data to an excel sheet- Using api like apache-poi this will be straight forward.

If you really want a special logging, start with Log to a database using log4j which explains about database logging and then make excel out out it.

Logging is unlimited as long as file system allows. Excel --depending on its version -- has limit on number of records that can be stored. (other problems in bemace's comments).

Community
  • 1
  • 1
Jayan
  • 18,003
  • 15
  • 89
  • 143
  • +1, Excel will also take up much more disk space than standard log formats, and could create a performance bottleneck. – Brad Mace Aug 06 '12 at 05:15
  • Agreed, we simply seperated the log with "\t" and simply then imported it into excel for viewing and had the columns automatically created by excel which was far easier than directly logging to an excel spreadsheet – MilindaD Aug 18 '12 at 06:33
2

I think that a direct answer to your questions can be: "you can create your own log4j appender" (this is how you can do that). Technically log4j comes with a plethora of appenders and you can always create a new one.

This appender will probably use the Apache POI (link) which provides a Java API for creating and formatting excel spreadsheets.

This is all good, and will technically work but I would think twice before doing this. After all using Excel for logs sounds awkward :)

I can propose a compromise if you still to have an excel spreadsheet. Use the 'File Appender' to create the CSV file (comma separated value). The excel will easily read such a file and its good enough for initial processing. You won't need even to write your appender just make sure you are configuring your layout properly.

Alternatively I can point you on some tools that can help in logs processing:

Apache Chainsaw

Lilith

There is a nice list of log viewers here, I'm sure you can google for more.

Hope this helps

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
0

Log a CSV format using log4j and a patternlayout. Then use Chainsaw to analyze the log - the latest developer snapshot of Chainsaw revamped the configuration UI and has a ton of new features, making this easy:

http://people.apache.org/~sdeboy

Scott
  • 1,728
  • 11
  • 11