log event pojo from log file/ parse file back to log event

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

log event pojo from log file/ parse file back to log event

Tushar Kapila
Am sure this has been asked before but i could not find code that works

Looking for an example of code where there is no UI. Batch mode, give a
file path, a config file (log4j2),
get call backs of log events read to a listener method. Possible in
chainsaw or other FOSS?

Psudedo code:

Set it up:
File myLogFile = new File("path/a.log")
File myConfigFile = new File("path/log4j.xml")
myListener listr = new MyLsitenter();

theLibrary.process(listr, myConfigFile, myLogFile);

In the listener

public void onEvnt(LogRecord logRecord){
    logRecord.getDate();
    logRecord.getThread()
    logRecord.getLevel();
    logRecord.getMessage() ; //could be multiline too,etc

--
Regards
Tushar Kapila
Reply | Threaded
Open this post in threaded view
|

Re: log event pojo from log file/ parse file back to log event

Ralph Goers
You would want to create an Appender that publishes to registered listeners. Log4j currently doesn’t have one but it would be pretty simple to create one.

Ralph

> On Feb 2, 2018, at 6:09 AM, Tushar Kapila <[hidden email]> wrote:
>
> Am sure this has been asked before but i could not find code that works
>
> Looking for an example of code where there is no UI. Batch mode, give a
> file path, a config file (log4j2),
> get call backs of log events read to a listener method. Possible in
> chainsaw or other FOSS?
>
> Psudedo code:
>
> Set it up:
> File myLogFile = new File("path/a.log")
> File myConfigFile = new File("path/log4j.xml")
> myListener listr = new MyLsitenter();
>
> theLibrary.process(listr, myConfigFile, myLogFile);
>
> In the listener
>
> public void onEvnt(LogRecord logRecord){
>    logRecord.getDate();
>    logRecord.getThread()
>    logRecord.getLevel();
>    logRecord.getMessage() ; //could be multiline too,etc
>
> --
> Regards
> Tushar Kapila



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: log event pojo from log file/ parse file back to log event

Ralph Goers
Actually I should clarify this a bit.  Log4j does have Appenders that will write to Kafka or similar frameworks, but I am gathering from what you asked for that you want something that is entirely in the application.

Ralph

> On Feb 2, 2018, at 2:58 PM, Ralph Goers <[hidden email]> wrote:
>
> You would want to create an Appender that publishes to registered listeners. Log4j currently doesn’t have one but it would be pretty simple to create one.
>
> Ralph
>
>> On Feb 2, 2018, at 6:09 AM, Tushar Kapila <[hidden email]> wrote:
>>
>> Am sure this has been asked before but i could not find code that works
>>
>> Looking for an example of code where there is no UI. Batch mode, give a
>> file path, a config file (log4j2),
>> get call backs of log events read to a listener method. Possible in
>> chainsaw or other FOSS?
>>
>> Psudedo code:
>>
>> Set it up:
>> File myLogFile = new File("path/a.log")
>> File myConfigFile = new File("path/log4j.xml")
>> myListener listr = new MyLsitenter();
>>
>> theLibrary.process(listr, myConfigFile, myLogFile);
>>
>> In the listener
>>
>> public void onEvnt(LogRecord logRecord){
>>   logRecord.getDate();
>>   logRecord.getThread()
>>   logRecord.getLevel();
>>   logRecord.getMessage() ; //could be multiline too,etc
>>
>> --
>> Regards
>> Tushar Kapila
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: log event pojo from log file/ parse file back to log event

Tushar Kapila
App A uses log4j2 logs to files. It's not too much data. I want to do what
chain saw does but without the UI. I want to read the log file. Get the
info back as a java objects. Then process them. Many lines are multiline.
So don't want to write this code my self. Yes I want the object back I'm on
my App B for further processing. APP A has many flavours with different
log4j2 config files with different patterns. But all writing to file system.
Just not sure what code parses lines from a log to create a log event in
Java?

Thank you for your time.

On 3 Feb 2018 03:30, "Ralph Goers" <[hidden email]> wrote:

> Actually I should clarify this a bit.  Log4j does have Appenders that will
> write to Kafka or similar frameworks, but I am gathering from what you
> asked for that you want something that is entirely in the application.
>
> Ralph
>
> > On Feb 2, 2018, at 2:58 PM, Ralph Goers <[hidden email]>
> wrote:
> >
> > You would want to create an Appender that publishes to registered
> listeners. Log4j currently doesn’t have one but it would be pretty simple
> to create one.
> >
> > Ralph
> >
> >> On Feb 2, 2018, at 6:09 AM, Tushar Kapila <[hidden email]> wrote:
> >>
> >> Am sure this has been asked before but i could not find code that works
> >>
> >> Looking for an example of code where there is no UI. Batch mode, give a
> >> file path, a config file (log4j2),
> >> get call backs of log events read to a listener method. Possible in
> >> chainsaw or other FOSS?
> >>
> >> Psudedo code:
> >>
> >> Set it up:
> >> File myLogFile = new File("path/a.log")
> >> File myConfigFile = new File("path/log4j.xml")
> >> myListener listr = new MyLsitenter();
> >>
> >> theLibrary.process(listr, myConfigFile, myLogFile);
> >>
> >> In the listener
> >>
> >> public void onEvnt(LogRecord logRecord){
> >>   logRecord.getDate();
> >>   logRecord.getThread()
> >>   logRecord.getLevel();
> >>   logRecord.getMessage() ; //could be multiline too,etc
> >>
> >> --
> >> Regards
> >> Tushar Kapila
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: log event pojo from log file/ parse file back to log event

Remko Popma-2
If you want to reconstruct log event objects from the log file, we recommend the JSON layout. The log file will contains more details than with PatternLayout and is easiest to parse back to objects.

Remko

(Shameless plug) Every java main() method deserves http://picocli.info

> On Feb 3, 2018, at 9:16, Tushar Kapila <[hidden email]> wrote:
>
> App A uses log4j2 logs to files. It's not too much data. I want to do what
> chain saw does but without the UI. I want to read the log file. Get the
> info back as a java objects. Then process them. Many lines are multiline.
> So don't want to write this code my self. Yes I want the object back I'm on
> my App B for further processing. APP A has many flavours with different
> log4j2 config files with different patterns. But all writing to file system.
> Just not sure what code parses lines from a log to create a log event in
> Java?
>
> Thank you for your time.
>
>> On 3 Feb 2018 03:30, "Ralph Goers" <[hidden email]> wrote:
>>
>> Actually I should clarify this a bit.  Log4j does have Appenders that will
>> write to Kafka or similar frameworks, but I am gathering from what you
>> asked for that you want something that is entirely in the application.
>>
>> Ralph
>>
>>> On Feb 2, 2018, at 2:58 PM, Ralph Goers <[hidden email]>
>> wrote:
>>>
>>> You would want to create an Appender that publishes to registered
>> listeners. Log4j currently doesn’t have one but it would be pretty simple
>> to create one.
>>>
>>> Ralph
>>>
>>>> On Feb 2, 2018, at 6:09 AM, Tushar Kapila <[hidden email]> wrote:
>>>>
>>>> Am sure this has been asked before but i could not find code that works
>>>>
>>>> Looking for an example of code where there is no UI. Batch mode, give a
>>>> file path, a config file (log4j2),
>>>> get call backs of log events read to a listener method. Possible in
>>>> chainsaw or other FOSS?
>>>>
>>>> Psudedo code:
>>>>
>>>> Set it up:
>>>> File myLogFile = new File("path/a.log")
>>>> File myConfigFile = new File("path/log4j.xml")
>>>> myListener listr = new MyLsitenter();
>>>>
>>>> theLibrary.process(listr, myConfigFile, myLogFile);
>>>>
>>>> In the listener
>>>>
>>>> public void onEvnt(LogRecord logRecord){
>>>>  logRecord.getDate();
>>>>  logRecord.getThread()
>>>>  logRecord.getLevel();
>>>>  logRecord.getMessage() ; //could be multiline too,etc
>>>>
>>>> --
>>>> Regards
>>>> Tushar Kapila
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: log event pojo from log file/ parse file back to log event

Tushar Kapila
Unfortunately I don't have control if that. Luckily they are printing full
date time, then thread id, a unique Id per txn, log level, class name,
mmethod name and msg then \n.

Multi line msg difficult.  Look ahead for valid date? If yes new record
else append line to previous msg?

On 3 Feb 2018 09:25, "Remko Popma" <[hidden email]> wrote:

> If you want to reconstruct log event objects from the log file, we
> recommend the JSON layout. The log file will contains more details than
> with PatternLayout and is easiest to parse back to objects.
>
> Remko
>
> (Shameless plug) Every java main() method deserves http://picocli.info
>
> > On Feb 3, 2018, at 9:16, Tushar Kapila <[hidden email]> wrote:
> >
> > App A uses log4j2 logs to files. It's not too much data. I want to do
> what
> > chain saw does but without the UI. I want to read the log file. Get the
> > info back as a java objects. Then process them. Many lines are multiline.
> > So don't want to write this code my self. Yes I want the object back I'm
> on
> > my App B for further processing. APP A has many flavours with different
> > log4j2 config files with different patterns. But all writing to file
> system.
> > Just not sure what code parses lines from a log to create a log event in
> > Java?
> >
> > Thank you for your time.
> >
> >> On 3 Feb 2018 03:30, "Ralph Goers" <[hidden email]> wrote:
> >>
> >> Actually I should clarify this a bit.  Log4j does have Appenders that
> will
> >> write to Kafka or similar frameworks, but I am gathering from what you
> >> asked for that you want something that is entirely in the application.
> >>
> >> Ralph
> >>
> >>> On Feb 2, 2018, at 2:58 PM, Ralph Goers <[hidden email]>
> >> wrote:
> >>>
> >>> You would want to create an Appender that publishes to registered
> >> listeners. Log4j currently doesn’t have one but it would be pretty
> simple
> >> to create one.
> >>>
> >>> Ralph
> >>>
> >>>> On Feb 2, 2018, at 6:09 AM, Tushar Kapila <[hidden email]> wrote:
> >>>>
> >>>> Am sure this has been asked before but i could not find code that
> works
> >>>>
> >>>> Looking for an example of code where there is no UI. Batch mode, give
> a
> >>>> file path, a config file (log4j2),
> >>>> get call backs of log events read to a listener method. Possible in
> >>>> chainsaw or other FOSS?
> >>>>
> >>>> Psudedo code:
> >>>>
> >>>> Set it up:
> >>>> File myLogFile = new File("path/a.log")
> >>>> File myConfigFile = new File("path/log4j.xml")
> >>>> myListener listr = new MyLsitenter();
> >>>>
> >>>> theLibrary.process(listr, myConfigFile, myLogFile);
> >>>>
> >>>> In the listener
> >>>>
> >>>> public void onEvnt(LogRecord logRecord){
> >>>>  logRecord.getDate();
> >>>>  logRecord.getThread()
> >>>>  logRecord.getLevel();
> >>>>  logRecord.getMessage() ; //could be multiline too,etc
> >>>>
> >>>> --
> >>>> Regards
> >>>> Tushar Kapila
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [hidden email]
> >>> For additional commands, e-mail: [hidden email]
> >>>
> >>>
> >>
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: [hidden email]
> >> For additional commands, e-mail: [hidden email]
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>