2

I would like to create rolling files that contains statistical data about my service. for example, logging each request that contained parameter X with a certain result set. I have to write these files to comply with other systems statistical data:

  • Roll the file every half an hour
  • Each file have to have column headers
  • I have to follow a strict file name convention such as tracking.display.1314116577.done

My service is written in Java.

Since I need to roll files, using loggers seems like a good direction so I have tried an approach where I would log the data using logback logger (my logger of choise), but the conventional rolling file appender cannot role the file every half an hour (or am i wrong?), cannot add column headers and has a strict naming convention of its own. I have tried to write my own RollingPolicy, but can't find enough resources or examples of how it's done.

Can anyone show/refer me how to accomplish this? If not, would you recommend a different approach?

Thank you!

Orka
  • 23
  • 5

2 Answers2

2

Yes, you can do it with a logback appender.

Take a look at TimeBasedRollingPolicy of RollingFileAppender you can easily roll the file each half hour.

To write the header you can extend RollingFileAppender and add the header based on your needs.

aleroot
  • 71,077
  • 30
  • 176
  • 213
  • The rolling policy seems to rely on SimpleDateFormat and I can't make it roll every half an hour, only hour or minute on the minute/hour. how is it easily done? I'll try your lead of extending the file appender. thanks! – Orka Jan 05 '12 at 13:26
0

A very dumb answer: getting logging right costs much time. So it is easier to implement your own logger from scratch. It seems you have very rigid requirements. For instance that ".done" - you probably first write it as ".part" and then rename it when done.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138