4

I am trying to use janino conditional statements in logback configuration and it is working fine with "if" and "else". But I want to ask if there is it possible to write "else if" in it?

My case -

<if condition='p("log.environment").equals("prod")'>
    <then>
        <include file="${LOG_CONFIG_DIR}/logback-prod.xml" />
    </then>
</if>

<if condition='p("log.environment").equals("uat")'>
    <then>
        <include file="${LOG_CONFIG_DIR}/logback-uat.xml" />
    </then>
</if>

<if condition='p("log.environment").equals("dev")'>
    <then>
        <include file="${LOG_CONFIG_DIR}/logback-dev.xml" />
    </then>
</if>
Betlista
  • 10,327
  • 13
  • 69
  • 110
Popeye
  • 1,548
  • 3
  • 25
  • 39

2 Answers2

3

Try to do like this.

<if condition=''>
  <then>..</then>
  <else>
    <if condition=''>
      <then>..</then>
      <else>..</else>
    </if>
  </else>
</if>
Betlista
  • 10,327
  • 13
  • 69
  • 110
Jungyeol
  • 71
  • 3
2

You can use if-then-else in multi-level

<if condition='p("log.environment").equals("prod")'>
    <then>
        <include file="${LOG_CONFIG_DIR}/logback-prod.xml" />
    </then>
    <if condition='p("log.environment").equals("uat")'>
       <then>
            <include file="${LOG_CONFIG_DIR}/logback-uat.xml" />
       </then>
       <else>
           <include file="${LOG_CONFIG_DIR}/logback-dev.xml" />
       </else>
    </if>
</if>
Betlista
  • 10,327
  • 13
  • 69
  • 110
Karthik Prasad
  • 9,662
  • 10
  • 64
  • 112