I need to log information with the following requirements:
- it is for writing data to files, that will latter be processed
- output lines have a predefined structure
- has to be really fast
- it should buffer the data and write it to files in background.
- it should support rotating the file and also should allow manual file rotation whenever required
Do you happen to know any good library that supports this?
Or would you recommend writing it on my own? I wouldn’t mind implementing one on my own, but I would like to know what my options are before taking a decision.
Most common Java logging libraries support most of what you are asking for, except perhaps for the asynchronous writing part. You might want to have a look at the following widely-used libraries:
Log4J – Log4J is extremely configurable, but it does have some issues that are supposed to be resolved in the new 2.x version series, which is about to be released.
Logback – This was designed as a successor to Log4J 1.2 – Log4J 2.x will include several improvements made by Logback.
SLF4J – This library can act as a proxy to a number of underlying logging libraries, allowing the logging framework to be switched as necessary. This might actually be the best choice to avoid binding yourself to a specific logging library, although it is probably not as efficient as using the underlying API directly.
As for the asynchronous writing requirement, if necessary it should be relatively easy to push all logging to a separate thread of your own.
EDIT:
Apparently, Log4J does have support for asynchronous logging.