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 2017/04/12 00:13:51 UTC

org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Hi All:

Using 2.8.2, I
call org.apache.logging.log4j.core.config.Configurator.initialize(String,
String) with a non-exiting file location.

The method does not return null because it found another log4j2.xml file on
my classpath. So I get a LoggerContext but not what I expect...

That does not sound right to me, it should return null, and then I can look
in the status logger to see what went wrong (if I happen to have it set to
DEBUG in the log4j2.xml file it did find.)

Thoughts?

Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Remko Popma <re...@gmail.com>.
It may be good if we add more status logs during initialization for all the
locations where we currently try to find the config file.
I remember that log4j-web prints all locations.
A more compact version of that may be useful.

Config file not found is a common theme with Log4j2 on StackOverflow...

On Thu, Apr 13, 2017 at 3:14 AM, Gary Gregory <ga...@gmail.com>
wrote:

> I wonder how tricky such a refactoring would be. I could also imagine an
> enum listing all possible config locations and an API that takes an enum
> var arg for where to look. The default would be look everywhere. We getting
> out in left field WRT logging here... but it is still important IMO.
>
> Gary
>
>
> On Apr 12, 2017 8:19 AM, "Remko Popma" <re...@gmail.com> wrote:
>
> The javadoc doesn't tell the full story here, which is that the current
> method searches the classpath next if the specified file doesn't exist. I
> guess it returns null after exhausting all options.
>
> Gary wants a way to stop in the middle.
>
> Sent from my iPhone
>
> > On Apr 12, 2017, at 17:53, Mikael Ståldal <mi...@magine.com>
> wrote:
> >
> > Given that the Javadoc since 1,5 years ago says:
> >
> > @return The LoggerContext or null if an error occurred (check the status
> > logger)
> >
> > I think it would be fine to return null if the given file is not found.
> >
> > On Wed, Apr 12, 2017 at 10:40 AM, Gary Gregory <ga...@gmail.com>
> > wrote:
> >
> >> On Wed, Apr 12, 2017 at 1:31 AM, Remko Popma <re...@gmail.com>
> >> wrote:
> >>
> >>> I'd avoid changing the semantics of existing methods.  I also favor 3.
> >>> (initializeStrict?)
> >>>
> >>
> >> Not a great method name but I am hard-pressed to come up with a better
> >> name:
> >>
> >> - initializeStrict
> >> - initializeChecked
> >> - initializeValidate
> >> - initializeValid
> >> - initializeVerify
> >> - initializeIfFound
> >> - initializeCleanly
> >>
> >> ?
> >>
> >> Gary
> >>
> >>
> >>>
> >>> Sent from my iPhone
> >>>
> >>>> On Apr 12, 2017, at 15:00, Matt Sicker <bo...@gmail.com> wrote:
> >>>>
> >>>> This is a nice showcase for an Either data type similar to Optional,
> >> but
> >>>> with a value or an error.
> >>>>
> >>>>> On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com>
> >> wrote:
> >>>>>
> >>>>> The problem with the API as it is now is that I have no idea if the
> >> API
> >>>>> did what I asked it to do. It does initialize log4j all right but not
> >>> in a
> >>>>> way I expect.
> >>>>>
> >>>>> I see that we could:
> >>>>>
> >>>>> 1) make the current API throw an IllegalArgumentException that means
> >>> "file
> >>>>> not found", this keeps the API signature the same.
> >>>>> 2) make the current API return null (but should it still initialize
> >>> log4j
> >>>>> with the 'next' config file it finds?). Not great as this would
> likely
> >>>>> break some apps.
> >>>>> 3) add a new API that throws an exception that means 'config file not
> >>>>> found'
> >>>>> 4) add a new API that returns null
> >>>>>
> >>>>> The nice thing about throwing an exception is that you can give a
> >>> detailed
> >>>>> error message. Returning null tells you something is wrong, not what,
> >>> still
> >>>>> a mystery.
> >>>>>
> >>>>> So I prefer 3).
> >>>>>
> >>>>> Regardless, we need some better Javadocs on the existing APIs... the
> >>>>> behavior is just too surprising IMO.
> >>>>>
> >>>>> Thoughts?
> >>>>>
> >>>>> Gary
> >>>>>
> >>>>>
> >>>>>
> >>>>> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <
> >>> ralph.goers@dslextreme.com>
> >>>>> wrote:
> >>>>>
> >>>>>> That’s a good point. It is a programmatic interface so it should
> >> return
> >>>>>> an error. But generally we want logging to do something reasonable
> >>> other
> >>>>>> than fail, so it should either use whatever configuration it finds
> or
> >>> use
> >>>>>> the default.
> >>>>>>
> >>>>>> Ralph
> >>>>>>
> >>>>>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com>
> >>> wrote:
> >>>>>>
> >>>>>> I thought Gary needed a way to detect that the specified location
> >>> didn't
> >>>>>> work. But perhaps a warning message is sufficient.
> >>>>>>
> >>>>>> Sent from my iPhone
> >>>>>>
> >>>>>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
> >>>>>> wrote:
> >>>>>>
> >>>>>> I'd prefer an error message but then have it continue with the
> >> current
> >>>>>> behavior.
> >>>>>>
> >>>>>> Sent from my iPhone
> >>>>>>
> >>>>>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com>
> >>> wrote:
> >>>>>>
> >>>>>> I can see both sides of the argument.
> >>>>>>
> >>>>>> Rather than changing the semantics of the existing method, what
> about
> >>>>>> adding a method `Configurator.initializeStrict(String, String)`
> >> which
> >>>>>> fails if the specified file doesn't exist? Not sure what the best
> way
> >>> to
> >>>>>> fail is: return null or throw exception...
> >>>>>>
> >>>>>> Sent from my iPhone
> >>>>>>
> >>>>>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com>
> >> wrote:
> >>>>>>
> >>>>>> Hi All:
> >>>>>>
> >>>>>> Using 2.8.2, I call org.apache.logging.log4j.
> >>>>>> core.config.Configurator.initialize(String, String) with a
> >> non-exiting
> >>>>>> file location.
> >>>>>>
> >>>>>> The method does not return null because it found another log4j2.xml
> >>> file
> >>>>>> on my classpath. So I get a LoggerContext but not what I expect...
> >>>>>>
> >>>>>> That does not sound right to me, it should return null, and then I
> >> can
> >>>>>> look in the status logger to see what went wrong (if I happen to
> have
> >>> it
> >>>>>> set to DEBUG in the log4j2.xml file it did find.)
> >>>>>>
> >>>>>> Thoughts?
> >>>>>>
> >>>>>> Gary
> >>>>>>
> >>>>>> --
> >>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >>>>>> Java Persistence with Hibernate, Second Edition
> >>>>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> >>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> >>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2
> b8>
> >>>>>>
> >>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> >>> am2&o=1&a=1617290459>
> >>>>>> JUnit in Action, Second Edition
> >>>>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> >>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> >>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> >> 18%22
> >>>>
> >>>>>>
> >>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> >>> am2&o=1&a=1935182021>
> >>>>>> Spring Batch in Action
> >>>>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> >>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> >>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> >>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> >>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> >>> am2&o=1&a=1935182951>
> >>>>>> 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
> >>>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> >>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> >>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2
> b8>
> >>>>>
> >>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
> >> garygregory-20&l=am2&o=1&a=
> >>> 1617290459>
> >>>>> JUnit in Action, Second Edition
> >>>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> >>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> >>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> >> 18%22
> >>>>
> >>>>>
> >>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
> >> garygregory-20&l=am2&o=1&a=
> >>> 1935182021>
> >>>>> Spring Batch in Action
> >>>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> >>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> >>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> >>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> >>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
> >> garygregory-20&l=am2&o=1&a=
> >>> 1935182951>
> >>>>> Blog: http://garygregory.wordpress.com
> >>>>> Home: http://garygregory.com/
> >>>>> Tweet! http://twitter.com/GaryGregory
> >>>>>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Matt Sicker <bo...@gmail.com>
> >>>>
> >>>>
> >>>>
> >>>> --
> >>>> Matt Sicker <bo...@gmail.com>
> >>>
> >>
> >>
> >>
> >> --
> >> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >> Java Persistence with Hibernate, Second Edition
> >> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> >> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> >> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2
> b8>
> >>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> >> 1617290459>
> >> JUnit in Action, Second Edition
> >> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> >> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> >> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> 18%22
> >>>
> >>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> >> 1935182021>
> >> Spring Batch in Action
> >> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> >> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> >> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> >> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> >> 1935182951>
> >> Blog: http://garygregory.wordpress.com
> >> Home: http://garygregory.com/
> >> Tweet! http://twitter.com/GaryGregory
> >>
> >
> >
> >
> > --
> > [image: MagineTV]
> >
> > *Mikael Ståldal*
> > Senior software developer
> >
> > *Magine TV*
> > mikael.staldal@magine.com
> > Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
> >
> > Privileged and/or Confidential Information may be contained in this
> > message. If you are not the addressee indicated in this message
> > (or responsible for delivery of the message to such a person), you may
> not
> > copy or deliver this message to anyone. In such case,
> > you should destroy this message and kindly notify the sender by reply
> > email.
>

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Gary Gregory <ga...@gmail.com>.
I wonder how tricky such a refactoring would be. I could also imagine an
enum listing all possible config locations and an API that takes an enum
var arg for where to look. The default would be look everywhere. We getting
out in left field WRT logging here... but it is still important IMO.

Gary


On Apr 12, 2017 8:19 AM, "Remko Popma" <re...@gmail.com> wrote:

The javadoc doesn't tell the full story here, which is that the current
method searches the classpath next if the specified file doesn't exist. I
guess it returns null after exhausting all options.

Gary wants a way to stop in the middle.

Sent from my iPhone

> On Apr 12, 2017, at 17:53, Mikael Ståldal <mi...@magine.com>
wrote:
>
> Given that the Javadoc since 1,5 years ago says:
>
> @return The LoggerContext or null if an error occurred (check the status
> logger)
>
> I think it would be fine to return null if the given file is not found.
>
> On Wed, Apr 12, 2017 at 10:40 AM, Gary Gregory <ga...@gmail.com>
> wrote:
>
>> On Wed, Apr 12, 2017 at 1:31 AM, Remko Popma <re...@gmail.com>
>> wrote:
>>
>>> I'd avoid changing the semantics of existing methods.  I also favor 3.
>>> (initializeStrict?)
>>>
>>
>> Not a great method name but I am hard-pressed to come up with a better
>> name:
>>
>> - initializeStrict
>> - initializeChecked
>> - initializeValidate
>> - initializeValid
>> - initializeVerify
>> - initializeIfFound
>> - initializeCleanly
>>
>> ?
>>
>> Gary
>>
>>
>>>
>>> Sent from my iPhone
>>>
>>>> On Apr 12, 2017, at 15:00, Matt Sicker <bo...@gmail.com> wrote:
>>>>
>>>> This is a nice showcase for an Either data type similar to Optional,
>> but
>>>> with a value or an error.
>>>>
>>>>> On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com>
>> wrote:
>>>>>
>>>>> The problem with the API as it is now is that I have no idea if the
>> API
>>>>> did what I asked it to do. It does initialize log4j all right but not
>>> in a
>>>>> way I expect.
>>>>>
>>>>> I see that we could:
>>>>>
>>>>> 1) make the current API throw an IllegalArgumentException that means
>>> "file
>>>>> not found", this keeps the API signature the same.
>>>>> 2) make the current API return null (but should it still initialize
>>> log4j
>>>>> with the 'next' config file it finds?). Not great as this would likely
>>>>> break some apps.
>>>>> 3) add a new API that throws an exception that means 'config file not
>>>>> found'
>>>>> 4) add a new API that returns null
>>>>>
>>>>> The nice thing about throwing an exception is that you can give a
>>> detailed
>>>>> error message. Returning null tells you something is wrong, not what,
>>> still
>>>>> a mystery.
>>>>>
>>>>> So I prefer 3).
>>>>>
>>>>> Regardless, we need some better Javadocs on the existing APIs... the
>>>>> behavior is just too surprising IMO.
>>>>>
>>>>> Thoughts?
>>>>>
>>>>> Gary
>>>>>
>>>>>
>>>>>
>>>>> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <
>>> ralph.goers@dslextreme.com>
>>>>> wrote:
>>>>>
>>>>>> That’s a good point. It is a programmatic interface so it should
>> return
>>>>>> an error. But generally we want logging to do something reasonable
>>> other
>>>>>> than fail, so it should either use whatever configuration it finds or
>>> use
>>>>>> the default.
>>>>>>
>>>>>> Ralph
>>>>>>
>>>>>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>>>>
>>>>>> I thought Gary needed a way to detect that the specified location
>>> didn't
>>>>>> work. But perhaps a warning message is sufficient.
>>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
>>>>>> wrote:
>>>>>>
>>>>>> I'd prefer an error message but then have it continue with the
>> current
>>>>>> behavior.
>>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>>>>
>>>>>> I can see both sides of the argument.
>>>>>>
>>>>>> Rather than changing the semantics of the existing method, what about
>>>>>> adding a method `Configurator.initializeStrict(String, String)`
>> which
>>>>>> fails if the specified file doesn't exist? Not sure what the best way
>>> to
>>>>>> fail is: return null or throw exception...
>>>>>>
>>>>>> Sent from my iPhone
>>>>>>
>>>>>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com>
>> wrote:
>>>>>>
>>>>>> Hi All:
>>>>>>
>>>>>> Using 2.8.2, I call org.apache.logging.log4j.
>>>>>> core.config.Configurator.initialize(String, String) with a
>> non-exiting
>>>>>> file location.
>>>>>>
>>>>>> The method does not return null because it found another log4j2.xml
>>> file
>>>>>> on my classpath. So I get a LoggerContext but not what I expect...
>>>>>>
>>>>>> That does not sound right to me, it should return null, and then I
>> can
>>>>>> look in the status logger to see what went wrong (if I happen to have
>>> it
>>>>>> set to DEBUG in the log4j2.xml file it did find.)
>>>>>>
>>>>>> Thoughts?
>>>>>>
>>>>>> Gary
>>>>>>
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>>>>>
>>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>>> am2&o=1&a=1617290459>
>>>>>> JUnit in Action, Second Edition
>>>>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
>> 18%22
>>>>
>>>>>>
>>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>>> am2&o=1&a=1935182021>
>>>>>> Spring Batch in Action
>>>>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>>> am2&o=1&a=1935182951>
>>>>>> 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
>>>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>>>>
>>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
>> garygregory-20&l=am2&o=1&a=
>>> 1617290459>
>>>>> JUnit in Action, Second Edition
>>>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
>> 18%22
>>>>
>>>>>
>>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
>> garygregory-20&l=am2&o=1&a=
>>> 1935182021>
>>>>> Spring Batch in Action
>>>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
>> garygregory-20&l=am2&o=1&a=
>>> 1935182951>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>>
>>>>
>>>>
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>
>>
>>
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1617290459>
>> JUnit in Action, Second Edition
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
18%22
>>>
>>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1935182021>
>> Spring Batch in Action
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1935182951>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>>
>
>
>
> --
> [image: MagineTV]
>
> *Mikael Ståldal*
> Senior software developer
>
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
>
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Remko Popma <re...@gmail.com>.
The javadoc doesn't tell the full story here, which is that the current method searches the classpath next if the specified file doesn't exist. I guess it returns null after exhausting all options. 

Gary wants a way to stop in the middle. 

Sent from my iPhone

> On Apr 12, 2017, at 17:53, Mikael Ståldal <mi...@magine.com> wrote:
> 
> Given that the Javadoc since 1,5 years ago says:
> 
> @return The LoggerContext or null if an error occurred (check the status
> logger)
> 
> I think it would be fine to return null if the given file is not found.
> 
> On Wed, Apr 12, 2017 at 10:40 AM, Gary Gregory <ga...@gmail.com>
> wrote:
> 
>> On Wed, Apr 12, 2017 at 1:31 AM, Remko Popma <re...@gmail.com>
>> wrote:
>> 
>>> I'd avoid changing the semantics of existing methods.  I also favor 3.
>>> (initializeStrict?)
>>> 
>> 
>> Not a great method name but I am hard-pressed to come up with a better
>> name:
>> 
>> - initializeStrict
>> - initializeChecked
>> - initializeValidate
>> - initializeValid
>> - initializeVerify
>> - initializeIfFound
>> - initializeCleanly
>> 
>> ?
>> 
>> Gary
>> 
>> 
>>> 
>>> Sent from my iPhone
>>> 
>>>> On Apr 12, 2017, at 15:00, Matt Sicker <bo...@gmail.com> wrote:
>>>> 
>>>> This is a nice showcase for an Either data type similar to Optional,
>> but
>>>> with a value or an error.
>>>> 
>>>>> On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com>
>> wrote:
>>>>> 
>>>>> The problem with the API as it is now is that I have no idea if the
>> API
>>>>> did what I asked it to do. It does initialize log4j all right but not
>>> in a
>>>>> way I expect.
>>>>> 
>>>>> I see that we could:
>>>>> 
>>>>> 1) make the current API throw an IllegalArgumentException that means
>>> "file
>>>>> not found", this keeps the API signature the same.
>>>>> 2) make the current API return null (but should it still initialize
>>> log4j
>>>>> with the 'next' config file it finds?). Not great as this would likely
>>>>> break some apps.
>>>>> 3) add a new API that throws an exception that means 'config file not
>>>>> found'
>>>>> 4) add a new API that returns null
>>>>> 
>>>>> The nice thing about throwing an exception is that you can give a
>>> detailed
>>>>> error message. Returning null tells you something is wrong, not what,
>>> still
>>>>> a mystery.
>>>>> 
>>>>> So I prefer 3).
>>>>> 
>>>>> Regardless, we need some better Javadocs on the existing APIs... the
>>>>> behavior is just too surprising IMO.
>>>>> 
>>>>> Thoughts?
>>>>> 
>>>>> Gary
>>>>> 
>>>>> 
>>>>> 
>>>>> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <
>>> ralph.goers@dslextreme.com>
>>>>> wrote:
>>>>> 
>>>>>> That’s a good point. It is a programmatic interface so it should
>> return
>>>>>> an error. But generally we want logging to do something reasonable
>>> other
>>>>>> than fail, so it should either use whatever configuration it finds or
>>> use
>>>>>> the default.
>>>>>> 
>>>>>> Ralph
>>>>>> 
>>>>>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>>>> 
>>>>>> I thought Gary needed a way to detect that the specified location
>>> didn't
>>>>>> work. But perhaps a warning message is sufficient.
>>>>>> 
>>>>>> Sent from my iPhone
>>>>>> 
>>>>>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
>>>>>> wrote:
>>>>>> 
>>>>>> I'd prefer an error message but then have it continue with the
>> current
>>>>>> behavior.
>>>>>> 
>>>>>> Sent from my iPhone
>>>>>> 
>>>>>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com>
>>> wrote:
>>>>>> 
>>>>>> I can see both sides of the argument.
>>>>>> 
>>>>>> Rather than changing the semantics of the existing method, what about
>>>>>> adding a method `Configurator.initializeStrict(String, String)`
>> which
>>>>>> fails if the specified file doesn't exist? Not sure what the best way
>>> to
>>>>>> fail is: return null or throw exception...
>>>>>> 
>>>>>> Sent from my iPhone
>>>>>> 
>>>>>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com>
>> wrote:
>>>>>> 
>>>>>> Hi All:
>>>>>> 
>>>>>> Using 2.8.2, I call org.apache.logging.log4j.
>>>>>> core.config.Configurator.initialize(String, String) with a
>> non-exiting
>>>>>> file location.
>>>>>> 
>>>>>> The method does not return null because it found another log4j2.xml
>>> file
>>>>>> on my classpath. So I get a LoggerContext but not what I expect...
>>>>>> 
>>>>>> That does not sound right to me, it should return null, and then I
>> can
>>>>>> look in the status logger to see what went wrong (if I happen to have
>>> it
>>>>>> set to DEBUG in the log4j2.xml file it did find.)
>>>>>> 
>>>>>> Thoughts?
>>>>>> 
>>>>>> Gary
>>>>>> 
>>>>>> --
>>>>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>>>>> Java Persistence with Hibernate, Second Edition
>>>>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>>>>> 
>>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>>> am2&o=1&a=1617290459>
>>>>>> JUnit in Action, Second Edition
>>>>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
>> 18%22
>>>> 
>>>>>> 
>>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>>> am2&o=1&a=1935182021>
>>>>>> Spring Batch in Action
>>>>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>>>>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
>>> am2&o=1&a=1935182951>
>>>>>> 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
>>>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>>>> 
>>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
>> garygregory-20&l=am2&o=1&a=
>>> 1617290459>
>>>>> JUnit in Action, Second Edition
>>>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
>> 18%22
>>>> 
>>>>> 
>>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
>> garygregory-20&l=am2&o=1&a=
>>> 1935182021>
>>>>> Spring Batch in Action
>>>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>>>>> <http:////ir-na.amazon-adsystem.com/e/ir?t=
>> garygregory-20&l=am2&o=1&a=
>>> 1935182951>
>>>>> Blog: http://garygregory.wordpress.com
>>>>> Home: http://garygregory.com/
>>>>> Tweet! http://twitter.com/GaryGregory
>>>>> 
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>>> 
>>>> 
>>>> 
>>>> --
>>>> Matt Sicker <bo...@gmail.com>
>>> 
>> 
>> 
>> 
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
>> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>> 
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1617290459>
>> JUnit in Action, Second Edition
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
>> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
>>> 
>> 
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1935182021>
>> Spring Batch in Action
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
>> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
>> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
>> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
>> 1935182951>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>> 
> 
> 
> 
> -- 
> [image: MagineTV]
> 
> *Mikael Ståldal*
> Senior software developer
> 
> *Magine TV*
> mikael.staldal@magine.com
> Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com
> 
> Privileged and/or Confidential Information may be contained in this
> message. If you are not the addressee indicated in this message
> (or responsible for delivery of the message to such a person), you may not
> copy or deliver this message to anyone. In such case,
> you should destroy this message and kindly notify the sender by reply
> email.

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Mikael Ståldal <mi...@magine.com>.
Given that the Javadoc since 1,5 years ago says:

@return The LoggerContext or null if an error occurred (check the status
logger)

I think it would be fine to return null if the given file is not found.

On Wed, Apr 12, 2017 at 10:40 AM, Gary Gregory <ga...@gmail.com>
wrote:

> On Wed, Apr 12, 2017 at 1:31 AM, Remko Popma <re...@gmail.com>
> wrote:
>
> > I'd avoid changing the semantics of existing methods.  I also favor 3.
> > (initializeStrict?)
> >
>
> Not a great method name but I am hard-pressed to come up with a better
> name:
>
> - initializeStrict
> - initializeChecked
> - initializeValidate
> - initializeValid
> - initializeVerify
> - initializeIfFound
> - initializeCleanly
>
> ?
>
> Gary
>
>
> >
> > Sent from my iPhone
> >
> > > On Apr 12, 2017, at 15:00, Matt Sicker <bo...@gmail.com> wrote:
> > >
> > > This is a nice showcase for an Either data type similar to Optional,
> but
> > > with a value or an error.
> > >
> > >> On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com>
> wrote:
> > >>
> > >> The problem with the API as it is now is that I have no idea if the
> API
> > >> did what I asked it to do. It does initialize log4j all right but not
> > in a
> > >> way I expect.
> > >>
> > >> I see that we could:
> > >>
> > >> 1) make the current API throw an IllegalArgumentException that means
> > "file
> > >> not found", this keeps the API signature the same.
> > >> 2) make the current API return null (but should it still initialize
> > log4j
> > >> with the 'next' config file it finds?). Not great as this would likely
> > >> break some apps.
> > >> 3) add a new API that throws an exception that means 'config file not
> > >> found'
> > >> 4) add a new API that returns null
> > >>
> > >> The nice thing about throwing an exception is that you can give a
> > detailed
> > >> error message. Returning null tells you something is wrong, not what,
> > still
> > >> a mystery.
> > >>
> > >> So I prefer 3).
> > >>
> > >> Regardless, we need some better Javadocs on the existing APIs... the
> > >> behavior is just too surprising IMO.
> > >>
> > >> Thoughts?
> > >>
> > >> Gary
> > >>
> > >>
> > >>
> > >> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <
> > ralph.goers@dslextreme.com>
> > >> wrote:
> > >>
> > >>> That’s a good point. It is a programmatic interface so it should
> return
> > >>> an error. But generally we want logging to do something reasonable
> > other
> > >>> than fail, so it should either use whatever configuration it finds or
> > use
> > >>> the default.
> > >>>
> > >>> Ralph
> > >>>
> > >>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com>
> > wrote:
> > >>>
> > >>> I thought Gary needed a way to detect that the specified location
> > didn't
> > >>> work. But perhaps a warning message is sufficient.
> > >>>
> > >>> Sent from my iPhone
> > >>>
> > >>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
> > >>> wrote:
> > >>>
> > >>> I'd prefer an error message but then have it continue with the
> current
> > >>> behavior.
> > >>>
> > >>> Sent from my iPhone
> > >>>
> > >>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com>
> > wrote:
> > >>>
> > >>> I can see both sides of the argument.
> > >>>
> > >>> Rather than changing the semantics of the existing method, what about
> > >>> adding a method `Configurator.initializeStrict(String, String)`
> which
> > >>> fails if the specified file doesn't exist? Not sure what the best way
> > to
> > >>> fail is: return null or throw exception...
> > >>>
> > >>> Sent from my iPhone
> > >>>
> > >>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com>
> wrote:
> > >>>
> > >>> Hi All:
> > >>>
> > >>> Using 2.8.2, I call org.apache.logging.log4j.
> > >>> core.config.Configurator.initialize(String, String) with a
> non-exiting
> > >>> file location.
> > >>>
> > >>> The method does not return null because it found another log4j2.xml
> > file
> > >>> on my classpath. So I get a LoggerContext but not what I expect...
> > >>>
> > >>> That does not sound right to me, it should return null, and then I
> can
> > >>> look in the status logger to see what went wrong (if I happen to have
> > it
> > >>> set to DEBUG in the log4j2.xml file it did find.)
> > >>>
> > >>> Thoughts?
> > >>>
> > >>> Gary
> > >>>
> > >>> --
> > >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > >>> Java Persistence with Hibernate, Second Edition
> > >>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> > linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> > >>>
> > >>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> > am2&o=1&a=1617290459>
> > >>> JUnit in Action, Second Edition
> > >>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> > linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> 18%22
> > >
> > >>>
> > >>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> > am2&o=1&a=1935182021>
> > >>> Spring Batch in Action
> > >>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> > linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> > 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> > >>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> > am2&o=1&a=1935182951>
> > >>> 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
> > >> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> > linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> > >>
> > >> <http:////ir-na.amazon-adsystem.com/e/ir?t=
> garygregory-20&l=am2&o=1&a=
> > 1617290459>
> > >> JUnit in Action, Second Edition
> > >> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> > linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de4
> 18%22
> > >
> > >>
> > >> <http:////ir-na.amazon-adsystem.com/e/ir?t=
> garygregory-20&l=am2&o=1&a=
> > 1935182021>
> > >> Spring Batch in Action
> > >> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> > tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> > linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> > 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> > >> <http:////ir-na.amazon-adsystem.com/e/ir?t=
> garygregory-20&l=am2&o=1&a=
> > 1935182951>
> > >> Blog: http://garygregory.wordpress.com
> > >> Home: http://garygregory.com/
> > >> Tweet! http://twitter.com/GaryGregory
> > >>
> > >
> > >
> > >
> > > --
> > > Matt Sicker <bo...@gmail.com>
> > >
> > >
> > >
> > > --
> > > Matt Sicker <bo...@gmail.com>
> >
>
>
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
> >
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
[image: MagineTV]

*Mikael Ståldal*
Senior software developer

*Magine TV*
mikael.staldal@magine.com
Grev Turegatan 3  | 114 46 Stockholm, Sweden  |   www.magine.com

Privileged and/or Confidential Information may be contained in this
message. If you are not the addressee indicated in this message
(or responsible for delivery of the message to such a person), you may not
copy or deliver this message to anyone. In such case,
you should destroy this message and kindly notify the sender by reply
email.

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Apr 12, 2017 at 1:31 AM, Remko Popma <re...@gmail.com> wrote:

> I'd avoid changing the semantics of existing methods.  I also favor 3.
> (initializeStrict?)
>

Not a great method name but I am hard-pressed to come up with a better name:

- initializeStrict
- initializeChecked
- initializeValidate
- initializeValid
- initializeVerify
- initializeIfFound
- initializeCleanly

?

Gary


>
> Sent from my iPhone
>
> > On Apr 12, 2017, at 15:00, Matt Sicker <bo...@gmail.com> wrote:
> >
> > This is a nice showcase for an Either data type similar to Optional, but
> > with a value or an error.
> >
> >> On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com> wrote:
> >>
> >> The problem with the API as it is now is that I have no idea if the API
> >> did what I asked it to do. It does initialize log4j all right but not
> in a
> >> way I expect.
> >>
> >> I see that we could:
> >>
> >> 1) make the current API throw an IllegalArgumentException that means
> "file
> >> not found", this keeps the API signature the same.
> >> 2) make the current API return null (but should it still initialize
> log4j
> >> with the 'next' config file it finds?). Not great as this would likely
> >> break some apps.
> >> 3) add a new API that throws an exception that means 'config file not
> >> found'
> >> 4) add a new API that returns null
> >>
> >> The nice thing about throwing an exception is that you can give a
> detailed
> >> error message. Returning null tells you something is wrong, not what,
> still
> >> a mystery.
> >>
> >> So I prefer 3).
> >>
> >> Regardless, we need some better Javadocs on the existing APIs... the
> >> behavior is just too surprising IMO.
> >>
> >> Thoughts?
> >>
> >> Gary
> >>
> >>
> >>
> >> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <
> ralph.goers@dslextreme.com>
> >> wrote:
> >>
> >>> That’s a good point. It is a programmatic interface so it should return
> >>> an error. But generally we want logging to do something reasonable
> other
> >>> than fail, so it should either use whatever configuration it finds or
> use
> >>> the default.
> >>>
> >>> Ralph
> >>>
> >>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com>
> wrote:
> >>>
> >>> I thought Gary needed a way to detect that the specified location
> didn't
> >>> work. But perhaps a warning message is sufficient.
> >>>
> >>> Sent from my iPhone
> >>>
> >>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
> >>> wrote:
> >>>
> >>> I'd prefer an error message but then have it continue with the current
> >>> behavior.
> >>>
> >>> Sent from my iPhone
> >>>
> >>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com>
> wrote:
> >>>
> >>> I can see both sides of the argument.
> >>>
> >>> Rather than changing the semantics of the existing method, what about
> >>> adding a method `Configurator.initializeStrict(String, String)` which
> >>> fails if the specified file doesn't exist? Not sure what the best way
> to
> >>> fail is: return null or throw exception...
> >>>
> >>> Sent from my iPhone
> >>>
> >>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
> >>>
> >>> Hi All:
> >>>
> >>> Using 2.8.2, I call org.apache.logging.log4j.
> >>> core.config.Configurator.initialize(String, String) with a non-exiting
> >>> file location.
> >>>
> >>> The method does not return null because it found another log4j2.xml
> file
> >>> on my classpath. So I get a LoggerContext but not what I expect...
> >>>
> >>> That does not sound right to me, it should return null, and then I can
> >>> look in the status logger to see what went wrong (if I happen to have
> it
> >>> set to DEBUG in the log4j2.xml file it did find.)
> >>>
> >>> Thoughts?
> >>>
> >>> Gary
> >>>
> >>> --
> >>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >>> Java Persistence with Hibernate, Second Edition
> >>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> >>>
> >>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> am2&o=1&a=1617290459>
> >>> JUnit in Action, Second Edition
> >>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
> >
> >>>
> >>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> am2&o=1&a=1935182021>
> >>> Spring Batch in Action
> >>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> >>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=
> am2&o=1&a=1935182951>
> >>> 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
> >> <https://www.amazon.com/gp/product/1617290459/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&
> linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
> >>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1617290459>
> >> JUnit in Action, Second Edition
> >> <https://www.amazon.com/gp/product/1935182021/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&
> linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22
> >
> >>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182021>
> >> Spring Batch in Action
> >> <https://www.amazon.com/gp/product/1935182951/ref=as_li_
> tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&
> linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%
> 7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> >> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=
> 1935182951>
> >> Blog: http://garygregory.wordpress.com
> >> Home: http://garygregory.com/
> >> Tweet! http://twitter.com/GaryGregory
> >>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
> >
> >
> >
> > --
> > Matt Sicker <bo...@gmail.com>
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Remko Popma <re...@gmail.com>.
I'd avoid changing the semantics of existing methods.  I also favor 3. (initializeStrict?)

Sent from my iPhone

> On Apr 12, 2017, at 15:00, Matt Sicker <bo...@gmail.com> wrote:
> 
> This is a nice showcase for an Either data type similar to Optional, but
> with a value or an error.
> 
>> On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com> wrote:
>> 
>> The problem with the API as it is now is that I have no idea if the API
>> did what I asked it to do. It does initialize log4j all right but not in a
>> way I expect.
>> 
>> I see that we could:
>> 
>> 1) make the current API throw an IllegalArgumentException that means "file
>> not found", this keeps the API signature the same.
>> 2) make the current API return null (but should it still initialize log4j
>> with the 'next' config file it finds?). Not great as this would likely
>> break some apps.
>> 3) add a new API that throws an exception that means 'config file not
>> found'
>> 4) add a new API that returns null
>> 
>> The nice thing about throwing an exception is that you can give a detailed
>> error message. Returning null tells you something is wrong, not what, still
>> a mystery.
>> 
>> So I prefer 3).
>> 
>> Regardless, we need some better Javadocs on the existing APIs... the
>> behavior is just too surprising IMO.
>> 
>> Thoughts?
>> 
>> Gary
>> 
>> 
>> 
>> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <ra...@dslextreme.com>
>> wrote:
>> 
>>> That’s a good point. It is a programmatic interface so it should return
>>> an error. But generally we want logging to do something reasonable other
>>> than fail, so it should either use whatever configuration it finds or use
>>> the default.
>>> 
>>> Ralph
>>> 
>>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com> wrote:
>>> 
>>> I thought Gary needed a way to detect that the specified location didn't
>>> work. But perhaps a warning message is sufficient.
>>> 
>>> Sent from my iPhone
>>> 
>>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
>>> wrote:
>>> 
>>> I'd prefer an error message but then have it continue with the current
>>> behavior.
>>> 
>>> Sent from my iPhone
>>> 
>>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com> wrote:
>>> 
>>> I can see both sides of the argument.
>>> 
>>> Rather than changing the semantics of the existing method, what about
>>> adding a method `Configurator.initializeStrict(String, String)` which
>>> fails if the specified file doesn't exist? Not sure what the best way to
>>> fail is: return null or throw exception...
>>> 
>>> Sent from my iPhone
>>> 
>>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>> Hi All:
>>> 
>>> Using 2.8.2, I call org.apache.logging.log4j.
>>> core.config.Configurator.initialize(String, String) with a non-exiting
>>> file location.
>>> 
>>> The method does not return null because it found another log4j2.xml file
>>> on my classpath. So I get a LoggerContext but not what I expect...
>>> 
>>> That does not sound right to me, it should return null, and then I can
>>> look in the status logger to see what went wrong (if I happen to have it
>>> set to DEBUG in the log4j2.xml file it did find.)
>>> 
>>> Thoughts?
>>> 
>>> Gary
>>> 
>>> --
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>>> Java Persistence with Hibernate, Second Edition
>>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>> 
>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
>>> JUnit in Action, Second Edition
>>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>>> 
>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
>>> Spring Batch in Action
>>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
>>> 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
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>> 
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
>> JUnit in Action, Second Edition
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>> 
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
>> Spring Batch in Action
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>> 
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>
> 
> 
> 
> -- 
> Matt Sicker <bo...@gmail.com>

Fwd: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Matt Sicker <bo...@gmail.com>.
This is a nice showcase for an Either data type similar to Optional, but
with a value or an error.

On 12 April 2017 at 00:41, Gary Gregory <ga...@gmail.com> wrote:

> The problem with the API as it is now is that I have no idea if the API
> did what I asked it to do. It does initialize log4j all right but not in a
> way I expect.
>
> I see that we could:
>
> 1) make the current API throw an IllegalArgumentException that means "file
> not found", this keeps the API signature the same.
> 2) make the current API return null (but should it still initialize log4j
> with the 'next' config file it finds?). Not great as this would likely
> break some apps.
> 3) add a new API that throws an exception that means 'config file not
> found'
> 4) add a new API that returns null
>
> The nice thing about throwing an exception is that you can give a detailed
> error message. Returning null tells you something is wrong, not what, still
> a mystery.
>
> So I prefer 3).
>
> Regardless, we need some better Javadocs on the existing APIs... the
> behavior is just too surprising IMO.
>
> Thoughts?
>
> Gary
>
>
>
> On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <ra...@dslextreme.com>
> wrote:
>
>> That’s a good point. It is a programmatic interface so it should return
>> an error. But generally we want logging to do something reasonable other
>> than fail, so it should either use whatever configuration it finds or use
>> the default.
>>
>> Ralph
>>
>> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com> wrote:
>>
>> I thought Gary needed a way to detect that the specified location didn't
>> work. But perhaps a warning message is sufficient.
>>
>> Sent from my iPhone
>>
>> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com>
>> wrote:
>>
>> I'd prefer an error message but then have it continue with the current
>> behavior.
>>
>> Sent from my iPhone
>>
>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com> wrote:
>>
>> I can see both sides of the argument.
>>
>> Rather than changing the semantics of the existing method, what about
>> adding a method `Configurator.initializeStrict(String, String)` which
>> fails if the specified file doesn't exist? Not sure what the best way to
>> fail is: return null or throw exception...
>>
>> Sent from my iPhone
>>
>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
>>
>> Hi All:
>>
>> Using 2.8.2, I call org.apache.logging.log4j.
>> core.config.Configurator.initialize(String, String) with a non-exiting
>> file location.
>>
>> The method does not return null because it found another log4j2.xml file
>> on my classpath. So I get a LoggerContext but not what I expect...
>>
>> That does not sound right to me, it should return null, and then I can
>> look in the status logger to see what went wrong (if I happen to have it
>> set to DEBUG in the log4j2.xml file it did find.)
>>
>> Thoughts?
>>
>> Gary
>>
>> --
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> Java Persistence with Hibernate, Second Edition
>> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>>
>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
>> JUnit in Action, Second Edition
>> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>>
>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
>> Spring Batch in Action
>> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
>> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
>> 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
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>



-- 
Matt Sicker <bo...@gmail.com>



-- 
Matt Sicker <bo...@gmail.com>

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Gary Gregory <ga...@gmail.com>.
The problem with the API as it is now is that I have no idea if the API did
what I asked it to do. It does initialize log4j all right but not in a way
I expect.

I see that we could:

1) make the current API throw an IllegalArgumentException that means "file
not found", this keeps the API signature the same.
2) make the current API return null (but should it still initialize log4j
with the 'next' config file it finds?). Not great as this would likely
break some apps.
3) add a new API that throws an exception that means 'config file not found'
4) add a new API that returns null

The nice thing about throwing an exception is that you can give a detailed
error message. Returning null tells you something is wrong, not what, still
a mystery.

So I prefer 3).

Regardless, we need some better Javadocs on the existing APIs... the
behavior is just too surprising IMO.

Thoughts?

Gary



On Tue, Apr 11, 2017 at 10:01 PM, Ralph Goers <ra...@dslextreme.com>
wrote:

> That’s a good point. It is a programmatic interface so it should return an
> error. But generally we want logging to do something reasonable other than
> fail, so it should either use whatever configuration it finds or use the
> default.
>
> Ralph
>
> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com> wrote:
>
> I thought Gary needed a way to detect that the specified location didn't
> work. But perhaps a warning message is sufficient.
>
> Sent from my iPhone
>
> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com> wrote:
>
> I'd prefer an error message but then have it continue with the current
> behavior.
>
> Sent from my iPhone
>
> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com> wrote:
>
> I can see both sides of the argument.
>
> Rather than changing the semantics of the existing method, what about
> adding a method `Configurator.initializeStrict(String, String)` which
> fails if the specified file doesn't exist? Not sure what the best way to
> fail is: return null or throw exception...
>
> Sent from my iPhone
>
> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
>
> Hi All:
>
> Using 2.8.2, I call org.apache.logging.log4j.core.config.Configurator.initialize(String,
> String) with a non-exiting file location.
>
> The method does not return null because it found another log4j2.xml file
> on my classpath. So I get a LoggerContext but not what I expect...
>
> That does not sound right to me, it should return null, and then I can
> look in the status logger to see what went wrong (if I happen to have it
> set to DEBUG in the log4j2.xml file it did find.)
>
> Thoughts?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>
>
> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
> JUnit in Action, Second Edition
> <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>
>
> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
> Spring Batch in Action
> <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
> <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
> 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
<https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
JUnit in Action, Second Edition
<https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>

<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
Spring Batch in Action
<https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>
<http:////ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Ralph Goers <ra...@dslextreme.com>.
That’s a good point. It is a programmatic interface so it should return an error. But generally we want logging to do something reasonable other than fail, so it should either use whatever configuration it finds or use the default.

Ralph

> On Apr 11, 2017, at 8:42 PM, Remko Popma <re...@gmail.com> wrote:
> 
> I thought Gary needed a way to detect that the specified location didn't work. But perhaps a warning message is sufficient. 
> 
> Sent from my iPhone
> 
> On Apr 12, 2017, at 10:05, Ralph Goers <ralph.goers@dslextreme.com <ma...@dslextreme.com>> wrote:
> 
>> I'd prefer an error message but then have it continue with the current behavior.
>> 
>> Sent from my iPhone
>> 
>> On Apr 11, 2017, at 5:47 PM, Remko Popma <remko.popma@gmail.com <ma...@gmail.com>> wrote:
>> 
>>> I can see both sides of the argument. 
>>> 
>>> Rather than changing the semantics of the existing method, what about adding a method `Configurator.initializeStrict(String, String)` which fails if the specified file doesn't exist? Not sure what the best way to fail is: return null or throw exception...
>>> 
>>> Sent from my iPhone
>>> 
>>> On Apr 12, 2017, at 9:13, Gary Gregory <garydgregory@gmail.com <ma...@gmail.com>> wrote:
>>> 
>>>> Hi All:
>>>> 
>>>> Using 2.8.2, I call org.apache.logging.log4j.core.config.Configurator.initialize(String, String) with a non-exiting file location.
>>>> 
>>>> The method does not return null because it found another log4j2.xml file on my classpath. So I get a LoggerContext but not what I expect...
>>>> 
>>>> That does not sound right to me, it should return null, and then I can look in the status logger to see what went wrong (if I happen to have it set to DEBUG in the log4j2.xml file it did find.)
>>>> 
>>>> Thoughts?
>>>> 
>>>> Gary
>>>> 
>>>> -- 
>>>> E-Mail: garydgregory@gmail.com <ma...@gmail.com> | ggregory@apache.org  <ma...@apache.org>
>>>> Java Persistence with Hibernate, Second Edition <https://www.amazon.com/gp/product/1617290459/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1617290459&linkCode=as2&tag=garygregory-20&linkId=cadb800f39946ec62ea2b1af9fe6a2b8>  <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1617290459>
>>>> JUnit in Action, Second Edition <https://www.amazon.com/gp/product/1935182021/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182021&linkCode=as2&tag=garygregory-20&linkId=31ecd1f6b6d1eaf8886ac902a24de418%22>  <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182021>
>>>> Spring Batch in Action <https://www.amazon.com/gp/product/1935182951/ref=as_li_tl?ie=UTF8&camp=1789&creative=9325&creativeASIN=1935182951&linkCode=%7B%7BlinkCode%7D%7D&tag=garygregory-20&linkId=%7B%7Blink_id%7D%7D%22%3ESpring+Batch+in+Action>  <http://ir-na.amazon-adsystem.com/e/ir?t=garygregory-20&l=am2&o=1&a=1935182951>
>>>> 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>

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Remko Popma <re...@gmail.com>.
I thought Gary needed a way to detect that the specified location didn't work. But perhaps a warning message is sufficient. 

Sent from my iPhone

> On Apr 12, 2017, at 10:05, Ralph Goers <ra...@dslextreme.com> wrote:
> 
> I'd prefer an error message but then have it continue with the current behavior.
> 
> Sent from my iPhone
> 
>> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com> wrote:
>> 
>> I can see both sides of the argument. 
>> 
>> Rather than changing the semantics of the existing method, what about adding a method `Configurator.initializeStrict(String, String)` which fails if the specified file doesn't exist? Not sure what the best way to fail is: return null or throw exception...
>> 
>> Sent from my iPhone
>> 
>>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
>>> 
>>> Hi All:
>>> 
>>> Using 2.8.2, I call org.apache.logging.log4j.core.config.Configurator.initialize(String, String) with a non-exiting file location.
>>> 
>>> The method does not return null because it found another log4j2.xml file on my classpath. So I get a LoggerContext but not what I expect...
>>> 
>>> That does not sound right to me, it should return null, and then I can look in the status logger to see what went wrong (if I happen to have it set to DEBUG in the log4j2.xml file it did find.)
>>> 
>>> Thoughts?
>>> 
>>> Gary
>>> 
>>> -- 
>>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>>> Java Persistence with Hibernate, Second Edition 
>>> JUnit in Action, Second Edition 
>>> Spring Batch in Action 
>>> Blog: http://garygregory.wordpress.com 
>>> Home: http://garygregory.com/
>>> Tweet! http://twitter.com/GaryGregory

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Ralph Goers <ra...@dslextreme.com>.
I'd prefer an error message but then have it continue with the current behavior.

Sent from my iPhone

> On Apr 11, 2017, at 5:47 PM, Remko Popma <re...@gmail.com> wrote:
> 
> I can see both sides of the argument. 
> 
> Rather than changing the semantics of the existing method, what about adding a method `Configurator.initializeStrict(String, String)` which fails if the specified file doesn't exist? Not sure what the best way to fail is: return null or throw exception...
> 
> Sent from my iPhone
> 
>> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
>> 
>> Hi All:
>> 
>> Using 2.8.2, I call org.apache.logging.log4j.core.config.Configurator.initialize(String, String) with a non-exiting file location.
>> 
>> The method does not return null because it found another log4j2.xml file on my classpath. So I get a LoggerContext but not what I expect...
>> 
>> That does not sound right to me, it should return null, and then I can look in the status logger to see what went wrong (if I happen to have it set to DEBUG in the log4j2.xml file it did find.)
>> 
>> Thoughts?
>> 
>> Gary
>> 
>> -- 
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
>> Java Persistence with Hibernate, Second Edition 
>> JUnit in Action, Second Edition 
>> Spring Batch in Action 
>> Blog: http://garygregory.wordpress.com 
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory

Re: org.apache.logging.log4j.core.config.Configurator.initialize(String, String)

Posted by Remko Popma <re...@gmail.com>.
I can see both sides of the argument. 

Rather than changing the semantics of the existing method, what about adding a method `Configurator.initializeStrict(String, String)` which fails if the specified file doesn't exist? Not sure what the best way to fail is: return null or throw exception...

Sent from my iPhone

> On Apr 12, 2017, at 9:13, Gary Gregory <ga...@gmail.com> wrote:
> 
> Hi All:
> 
> Using 2.8.2, I call org.apache.logging.log4j.core.config.Configurator.initialize(String, String) with a non-exiting file location.
> 
> The method does not return null because it found another log4j2.xml file on my classpath. So I get a LoggerContext but not what I expect...
> 
> That does not sound right to me, it should return null, and then I can look in the status logger to see what went wrong (if I happen to have it set to DEBUG in the log4j2.xml file it did find.)
> 
> Thoughts?
> 
> Gary
> 
> -- 
> E-Mail: garydgregory@gmail.com | ggregory@apache.org 
> Java Persistence with Hibernate, Second Edition 
> JUnit in Action, Second Edition 
> Spring Batch in Action 
> Blog: http://garygregory.wordpress.com 
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory