On Mon, Jun 22, 2015 at 12:44 PM, Charles Allen <
[email protected]> wrote:
> org.apache.logging.log4j.core.impl.Log4jContextFactory#createShutdownCallbackRegistry
> creates the instance of interest, but the resulting instance is not
> get-able without using reflection?
>
That's true, createShutdownCallbackRegistry is called from
Log4jContextFactory constructions and not accessible from outside the class.
You'd like a
public ShutdownCallbackRegistry getShutdownCallbackRegistry() {
return shutdownCallbackRegistry;
}
added to this class?
Gary
> On Mon, Jun 22, 2015 at 12:36 PM Charles Allen <
> [email protected]> wrote:
>
>> No, it is still not showing up. For the record, this is using 2.2
>> Which seems odd because if I break on Log4jContextFactory.java:88 then
>> the shutdownCallbackRegistry is the correct custom instance if the
>> properties are set programmatically or at command line, but it simply does
>> not print out the debug message
>>
>>
>> On Mon, Jun 22, 2015 at 12:11 PM Gary Gregory <[email protected]>
>> wrote:
>>
>>> If you do not see the message "Using ShutdownCallbackRegistry
>>> YOUR_CLASS_INSTANCE" then that is not good.
>>>
>>> Can you try setting the system properties from the command line instead
>>> of programmatically? I wonder if Log4j is initialized _before_ your
>>> setProperty calls.
>>>
>>> Gary
>>>
>>> On Mon, Jun 22, 2015 at 11:37 AM, Charles Allen <
>>> [email protected]> wrote:
>>>
>>>> No, oddly enough.
>>>>
>>>> The following options are being set:
>>>>
>>>> properties.setProperty("log4j.shutdownCallbackRegistry",
>>>> "io.druid.common.config.Log4jShutdown");
>>>> properties.setProperty("log4j.shutdownHookEnabled", "true");
>>>>
>>>>
>>>> I know it is getting called though and I have the following at the
>>>> start and end of my log when my main program:
>>>>
>>>>
>>>> 2015-06-22 18:32:38,543 INFO Registered Log4j as the
>>>> java.util.logging.LogManager.
>>>> 2015-06-22 18:32:38,698 DEBUG Registering MBean
>>>> org.apache.logging.log4j2:type=1793467229
>>>> 2015-06-22 18:32:38,705 DEBUG Registering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=StatusLogger
>>>> 2015-06-22 18:32:38,707 DEBUG Registering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=ContextSelector
>>>> 2015-06-22 18:32:38,710 DEBUG Registering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=Loggers,name=
>>>> 2015-06-22 18:32:38,713 DEBUG Registering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=Appenders,name=Console
>>>> 2015-06-22 18:32:38,714 DEBUG Reconfiguration complete for
>>>> context[name=1793467229] at null
>>>> (org.apache.logging.log4j.core.LoggerContext@6bfecf32) with optional
>>>> ClassLoader: null
>>>> 2015-06-22 18:32:38,714 DEBUG Shutdown hook enabled. Registering a new
>>>> one.
>>>> 2015-06-22 18:32:38,716 DEBUG LoggerContext[name=1793467229,
>>>> org.apache.logging.log4j.core.LoggerContext@6bfecf32] started OK.
>>>> 2015-06-22 18:32:40,327 DEBUG Using default SystemClock for timestamps
>>>>
>>>> ......
>>>>
>>>> 2015-06-22T18:33:28,999 INFO [Thread-52]
>>>> io.druid.initialization.Log4jShutterDownerModule - Shutting down log4j
>>>> callbacks
>>>> 2015-06-22 18:33:29,000 DEBUG Stopping LoggerContext[name=1793467229,
>>>> org.apache.logging.log4j.core.LoggerContext@6bfecf32]
>>>> 2015-06-22 18:33:29,000 DEBUG Stopping LoggerContext[name=1793467229,
>>>> org.apache.logging.log4j.core.LoggerContext@6bfecf32]...
>>>> 2015-06-22 18:33:29,000 DEBUG Unregistering MBean
>>>> org.apache.logging.log4j2:type=1793467229
>>>> 2015-06-22 18:33:29,001 DEBUG Unregistering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=StatusLogger
>>>> 2015-06-22 18:33:29,001 DEBUG Unregistering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=ContextSelector
>>>> 2015-06-22 18:33:29,001 DEBUG Unregistering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=Loggers,name=
>>>> 2015-06-22 18:33:29,002 DEBUG Unregistering MBean
>>>> org.apache.logging.log4j2:type=1793467229,component=Appenders,name=Console
>>>> 2015-06-22 18:33:29,003 DEBUG Stopped
>>>> XmlConfiguration[location=/Users/charlesallen/src/druid/common/target/classes/log4j2.xml]
>>>> OK
>>>> 2015-06-22 18:33:29,004 DEBUG Stopped LoggerContext[name=1793467229,
>>>> org.apache.logging.log4j.core.LoggerContext@6bfecf32]...
>>>> 2015-06-22 18:33:29,004 DEBUG Stopping LoggerContext[name=Default,
>>>> org.apache.logging.log4j.core.LoggerContext@dbef480]
>>>> 2015-06-22 18:33:29,004 DEBUG Stopping LoggerContext[name=Default,
>>>> org.apache.logging.log4j.core.LoggerContext@dbef480]...
>>>> 2015-06-22 18:33:29,005 DEBUG Stopped
>>>> XmlConfiguration[location=/Users/charlesallen/src/druid/common/target/classes/log4j2.xml]
>>>> OK
>>>> 2015-06-22 18:33:29,005 DEBUG Stopped LoggerContext[name=Default,
>>>> org.apache.logging.log4j.core.LoggerContext@dbef480]...
>>>>
>>>>
>>>>
>>>>
>>>> On Sat, Jun 20, 2015 at 9:04 AM Gary Gregory <[email protected]>
>>>> wrote:
>>>>
>>>>> If you turn on the Log4j status logger (<Configuration status="DEBUG">),
>>>>> do you see the debug log message
>>>>> from
>>>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.Log4jContextFactory(ContextSelector,
>>>>> ShutdownCallbackRegistry):
>>>>>
>>>>> Using ShutdownCallbackRegistry YOUR_CLASS_INSTANCE
>>>>>
>>>>> Or do you see an exception logged
>>>>> from
>>>>> org.apache.logging.log4j.core.impl.Log4jContextFactory.createShutdownCallbackRegistry()?
>>>>>
>>>>> Gary
>>>>>
>>>>> On Wed, Jun 17, 2015 at 9:13 AM, Charles Allen <
>>>>> [email protected]> wrote:
>>>>>
>>>>>> I'm currently writing a lifecycle bridge between Druid.io's logging
>>>>>> and log4j2's logging to make sure logs during normal shutdown hooks are
>>>>>> persisted correctly. I cannot rely on JVM shutdown hook firing order but
>>>>>> have a "functional" ShutdownCallbackRegistry.
>>>>>>
>>>>>> Is there a preferred way to get the instanced
>>>>>> ShutdownCallbackRegistry at org.apache.logging.log4j.core.
>>>>>> impl.Log4jContextFactory#shutdownCallbackRegistry ?
>>>>>>
>>>>>> I have set a class via the log4j.shutdownCallbackRegistry property,
>>>>>> but cannot seem to actually get the instance used. This leaves me to
>>>>>> either
>>>>>> use reflection https://github.com/druid-io/druid/pull/1387 or
>>>>>> static methods https://github.com/DjDCH/Log4j-StaticShutdown
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> E-Mail: [email protected] | [email protected]
>>>>> 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: [email protected] | [email protected]
>>> 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: [email protected] | [email protected]
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