Providing access to log/appender in application

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

Providing access to log/appender in application

Fred Eisele
My current application has a "log panel" where certain messages are posted.
We are converting this application to use log4j2.
What is a good way to route an appender to an in memory list of messages in
the application?

* Construct an appender programmatically passing the java list to the
constructor
* Construct an appender based on either OutputStreamAppender or
MemoryMappedFileAppender, and access its manager programmatically


On a related note---
Is it possible to programmatically access an appender by name without first
going through a logger?
Reply | Threaded
Open this post in threaded view
|

Re: Providing access to log/appender in application

Ralph Goers
I would recommend you create a variant of the ListAppender. I wouldn’t recommend using it directly as it isn’t meant for production use. You will find this in log4j-core’s test classes. We make extensive use of this in our unit tests. If you look at one of the tests that use it you can see how it can be accessed from your code. Essentially, you get the configuration from the LoggerContext and then find the appender you want from that.

Ralph

> On Aug 15, 2019, at 5:12 AM, Fred Eisele <[hidden email]> wrote:
>
> My current application has a "log panel" where certain messages are posted.
> We are converting this application to use log4j2.
> What is a good way to route an appender to an in memory list of messages in
> the application?
>
> * Construct an appender programmatically passing the java list to the
> constructor
> * Construct an appender based on either OutputStreamAppender or
> MemoryMappedFileAppender, and access its manager programmatically
>
>
> On a related note---
> Is it possible to programmatically access an appender by name without first
> going through a logger?



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

Reply | Threaded
Open this post in threaded view
|

Re: Providing access to log/appender in application

Fred Eisele
Yes, that looks like what I want to do.

On Thu, Aug 15, 2019 at 8:33 AM Ralph Goers <[hidden email]>
wrote:

> I would recommend you create a variant of the ListAppender. I wouldn’t
> recommend using it directly as it isn’t meant for production use. You will
> find this in log4j-core’s test classes. We make extensive use of this in
> our unit tests. If you look at one of the tests that use it you can see how
> it can be accessed from your code. Essentially, you get the configuration
> from the LoggerContext and then find the appender you want from that.
>
> Ralph
>
> > On Aug 15, 2019, at 5:12 AM, Fred Eisele <[hidden email]>
> wrote:
> >
> > My current application has a "log panel" where certain messages are
> posted.
> > We are converting this application to use log4j2.
> > What is a good way to route an appender to an in memory list of messages
> in
> > the application?
> >
> > * Construct an appender programmatically passing the java list to the
> > constructor
> > * Construct an appender based on either OutputStreamAppender or
> > MemoryMappedFileAppender, and access its manager programmatically
> >
> >
> > On a related note---
> > Is it possible to programmatically access an appender by name without
> first
> > going through a logger?
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>