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 "Remko Popma (JIRA)" <ji...@apache.org> on 2014/07/13 11:27:05 UTC

[jira] [Updated] (LOG4J2-321) Provide configuration alternative to system properties

     [ https://issues.apache.org/jira/browse/LOG4J2-321?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Remko Popma updated LOG4J2-321:
-------------------------------

    Fix Version/s:     (was: 2.0-rc1)
                   2.1

It is not possible to define a ContextSelector in configuration because the lifecycle needs the ContextSelector to be created before the configuration file is read. So, to use AsyncLoggers without system properties, we need a way to enable AsyncLoggers that uses the normal ContextSelector.

Currently LoggerContext defines a protected factory method {{newInstance(...)}} to createLogger instances. AsyncLoggerContext overrides this method to create AsyncLogger instances.

Instead of this factory method, LoggerContext should delegate this to a separate factory object. This factory object can be derived from the configuration. (Still need to work out the details...)

A sample config could look like this (all loggers async):
{code}
<configuration level="warn" jmxEnabled="true">
  <appenders>
    ..
  </appenders>
  <!-- valid values for the async attribute are ALL, MIXED or NONE -->
  <loggers async="ALL"
           asyncRingBufferSize="4096"
           asyncWaitStrategy="Block"
           asyncExceptionHandler="my.custom.Handler">
    <root level="trace">
      ... (appender-refs here)
    </root>
  </loggers>
</configuration>
{code}

Sample config 2 (mixed async/sync loggers):
{code}
<configuration level="warn" jmxEnabled="true">
  <appenders>
    ..
  </appenders>
  <loggers async="MIXED"
           asyncRingBufferSize="128"
           asyncWaitStrategy="Block"
           asyncExceptionHandler="my.custom.Handler">
    <Logger level="debug" name="my.sync.logger">
      ... (appender-refs here)
    </Logger>
    <AsyncLogger level="debug" name="my.async.logger">
      ...
    </AsyncLogger>
    <AsyncRoot level="trace">
      ...
    </AsyncRoot>
  </loggers>
</configuration>
{code}

For the {{jmxEnabled}} attribute, an {{isJmxEnabled()}} method would need to be added to the Configuration interface.
The enabled value may change when reconfigured, so the MBean registration logic needs to be changed to first unregister the old MBeans, and then to check if JMX is enabled in configuration before registering the new MBeans.

TBD:
What to do if the system property value conflicts with the configuration value?
For example:
{{-DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector}} is set, but the configuration says {{<loggers async="NONE">}},
or {{-Dlog4j2.disable.jmx=true}} is set, but the configuration says {{<configuration jmxEnabled="true">}}.

> Provide configuration alternative to system properties
> ------------------------------------------------------
>
>                 Key: LOG4J2-321
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-321
>             Project: Log4j 2
>          Issue Type: Bug
>    Affects Versions: 2.0-beta8
>            Reporter: Remko Popma
>            Assignee: Remko Popma
>             Fix For: 2.1
>
>
> Some components behaviour cannot be configured in the configuration file but only with System properties. There is a strong preference to ensure all behaviour can be configured in the configuration file.
> Properties that can be used to configure AsyncLoggers when all loggers are Async:
> * Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
> * AsyncLogger.ExceptionHandler
> * AsyncLogger.RingBufferSize
> * AsyncLogger.WaitStrategy
> * log4j.Clock - currently only used for timestamping RingBufferLogEvents. 
> Question: Should all LogEvents use this clock?
> The following system properties can be used to configure mixed Async Loggers:
> * AsyncLoggerConfig.ExceptionHandler	
> * AsyncLoggerConfig.RingBufferSize
> * AsyncLoggerConfig.WaitStrategy
> For JMX there is only the one "disable" property, in the mailing list it was suggested to make this into an element rather than an attribute to future-proof it.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org