I am designing a custom Appender(How to create a own Appender in log4j?) in Log4j to meet my requirement.
The log files on which I have to do some operation is of the form
{JSONObject}
{JSONObject}
...........
...........
{JSONObject}
Each JSON Object is in the form of
{"operation":"ABC","operation":"xyz","ID":"123".......}
ID in each Object is unique.
I have created my custom Appender.
In append(LoggingEvent event)
function, How should I deal with event
such that I can easily deal with JSON Object ??
I want to segregate each JSON Object.
I came across with an Idea that I will format the event in Strings and at end of each line I will change into Strings.
protected void append(LoggingEvent loggingEvent) {
changetoJSON(this.layout.format(loggingEvent));
In changetoJSON
function I will check for "\n"
and convert the string till "\n"
to a JSONObject. and save the corresponding index and again do the same thing till end.
Here, In this method my doubt is How does LoggingEvent
deals with log files?
Does It take the whole log file in a single line ?
Is there any other way to deal with this situation ?
As I am new to log4j so I don't have too much idea of different functions of log4j. So any help in designing solution for this situation will be quite helpful for me.I am using JAVA for coding.
Thanks,