You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-user@logging.apache.org by Fred Eisele <fr...@gmail.com> on 2019/08/15 12:12:55 UTC

Providing access to log/appender in application

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?

Re: Providing access to log/appender in application

Posted by Fred Eisele <fr...@gmail.com>.
Yes, that looks like what I want to do.

On Thu, Aug 15, 2019 at 8:33 AM Ralph Goers <ra...@dslextreme.com>
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 <fr...@gmail.com>
> 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: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
>
>

Re: Providing access to log/appender in application

Posted by Ralph Goers <ra...@dslextreme.com>.
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 <fr...@gmail.com> 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: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org