You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by Gary Gregory <ga...@gmail.com> on 2016/07/20 16:40:40 UTC

Hi,

Right I have to say:

import org.apache.logging.log4j.core.LoggerContext;

        final LoggerContext context = Configurator.initialize("Name",
aClassLoader, "path/to/config.xml");
        try {
          ...
        } finally {
          Configurator.shutdown(context);
        }

This would be nicer:

        try (LoggerContext context = Configurator.initialize("Name",
aClassLoader, "path/to/config.xml")) {
          ...
        }

Thoughts?

Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re:

Posted by Gary Gregory <ga...@gmail.com>.
Granted my use case might be unusual but it seems to fit having
LoggerContext implement Closeable. I'll put that on my TODO list.

Gary

On Wed, Jul 20, 2016 at 10:32 AM, Ralph Goers <ra...@dslextreme.com>
wrote:

> AutoCloseable?
>
> I guess I wouldn’t think it would be all that common to use that, but OK.
> Most of the time I expect it will get used in some other initialize method
> and shutdown would be called in some sort of termination handler, much like
> the Servlet spec does.  So unlike something like a JDBC connection I
> wouldn’t expect this to get used a lot.
>
> Ralph
>
> On Jul 20, 2016, at 9:40 AM, Gary Gregory <ga...@gmail.com> wrote:
>
> Hi,
>
> Right I have to say:
>
> import org.apache.logging.log4j.core.LoggerContext;
>
>         final LoggerContext context = Configurator.initialize("Name",
> aClassLoader, "path/to/config.xml");
>         try {
>           ...
>         } finally {
>           Configurator.shutdown(context);
>         }
>
> This would be nicer:
>
>         try (LoggerContext context = Configurator.initialize("Name",
> aClassLoader, "path/to/config.xml")) {
>           ...
>         }
>
> Thoughts?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>
>
>


-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re:

Posted by Ralph Goers <ra...@dslextreme.com>.
AutoCloseable? 

I guess I wouldn’t think it would be all that common to use that, but OK.  Most of the time I expect it will get used in some other initialize method and shutdown would be called in some sort of termination handler, much like the Servlet spec does.  So unlike something like a JDBC connection I wouldn’t expect this to get used a lot.

Ralph

> On Jul 20, 2016, at 9:40 AM, Gary Gregory <ga...@gmail.com> wrote:
> 
> Hi,
> 
> Right I have to say:
> 
> import org.apache.logging.log4j.core.LoggerContext;
> 
>         final LoggerContext context = Configurator.initialize("Name", aClassLoader, "path/to/config.xml");
>         try {
>           ...
>         } finally {
>           Configurator.shutdown(context);
>         }
> 
> This would be nicer:
> 
>         try (LoggerContext context = Configurator.initialize("Name", aClassLoader, "path/to/config.xml")) {
>           ...
>         }
> 
> Thoughts?
> 
> Gary
> 
> -- 
> E-Mail: garydgregory@gmail.com <ma...@gmail.com> | ggregory@apache.org  <ma...@apache.org>
> Java Persistence with Hibernate, Second Edition <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com <http://garygregory.wordpress.com/> 
> Home: http://garygregory.com/ <http://garygregory.com/>
> Tweet! http://twitter.com/GaryGregory <http://twitter.com/GaryGregory>