[ 
https://issues.apache.org/jira/browse/LOG4J2-1686?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15664120#comment-15664120
 ] 

Raman Gupta commented on LOG4J2-1686:
-------------------------------------

There are two aspects of this we are now discussing: a) do we need a more 
general mechanism for conditional configuration, and b) do we need a 
LoggerSelector for loggers (btw, I only edited for clarity and conciseness, not 
to add confusion, sorry about that).

Regarding (a), I won't argue more for it. I still think it would be useful, but 
if we can get 90+% of the functionality with equivalent script selectors, I'm 
fine with that (though I still think the docs need something to document all 
the available selectors and other script capabilities together in one place 
i.e. "here are the things you can do with scripts", list them, and link to the 
individual sections that have more details.

Regarding (b), I think with AppenderSelectors, PatternSelectors, that would be 
the main missing piece of the conditional puzzle. Properties work fine, but 
don't allow me to control my loggers as a group with one property. For example, 
let say I want this:

logger a : dev DEBUG, prod INFO
logger b : dev INFO, prod INFO
root : dev INFO, prod WARN

In order to do this with properties, I have to create separate properties 
"a.level", "b.level", and "root.level". In addition, if a new version of the 
app adds

logger c : dev WARN, prod WARN

I now have to add property "c.level", which adds operational complexity to new 
releases.

However, if I can define these loggers as a group within my configuration file, 
gated with one property, using the ScriptAppenderSelector as a model, I could 
do something like this with one environment property:

{code:xml}
<Loggers>
  <ScriptLoggerSelector>
    <ScriptRef ref="someScriptThatReturnsEnvironment">
    <LoggersMatch key="dev">
      <Logger name="a" ...>...</Logger>
      <Logger name="b" ...>...</Logger>
      <Root>...</Root>
    <LoggersMatch>
    <LoggersMatch key="prod">
      <Logger name="a" ...>...</Logger>
      <Logger name="b" ...>...</Logger>
      <Root>...</Root>
    <LoggersMatch>
  </ScriptLoggerSelector>
  <Logger name="sameInBoth">...</Logger>
</Loggers

{code}

Thoughts on whether this would be useful?

> Support conditional configuration
> ---------------------------------
>
>                 Key: LOG4J2-1686
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1686
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Configurators
>    Affects Versions: 2.7
>            Reporter: Raman Gupta
>            Priority: Blocker
>
> It would be great to support conditional configuration like logback:
> http://logback.qos.ch/manual/configuration.html#conditional
> This allows for more advanced configuration than is currently possible with 
> property substitution.
> Example use case: to implement 
> https://issues.apache.org/jira/browse/LOG4J2-1685 without log4j library 
> support.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

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

Reply via email to