logback conditional

logback conditional参考文档http://logback.qos.ch/manual/configuration.html#conditionalConditionalprocessingissupportedanywherewithinthe<configuration>elementmaven<dependency> <groupId>org.codehaus.janino</groupId> <artifactId>j…

大家好,欢迎来到IT知识分享网。

参考文档

http://logback.qos.ch/manual/configuration.html#conditional

Conditional processing is supported anywhere within the <configuration> element

 

maven

<dependency>
	<groupId>org.codehaus.janino</groupId>
	<artifactId>janino</artifactId>
	<version>${janino.version}</version>
</dependency>

 

if-then

<!-- if-then form -->
<if condition="some conditional expression">
<then>
  ...
</then>
</if>

if-then-else

<!-- if-then-else form -->
<if condition="some conditional expression">
<then>
  ...
</then>
<else>
  ...
</else>    
</if>

 

<if condition='property("HOSTNAME").contains("torino")'>
<then>
  <appender name="CON" class="ch.qos.logback.core.ConsoleAppender">
	<encoder>
	  <pattern>%d %-5level %logger{35} - %msg %n</pattern>
	</encoder>
  </appender>
  <root>
	<appender-ref ref="CON" />
  </root>
</then>
</if>

 嵌套

<if condition='p("log.dir.type").equals("custom")'>
	<then>
		<property scope="context" name="log.root.dir" value="${log.dir.custom}"/>
	</then>
	<else>
		<if condition='p("log.dir.type").equals("install")'>
			<then>
				<property scope="context" name="log.root.dir" value="${LOG_DIR}/logs"/>
			</then>
			<else>
				<if condition='p("os.name").contains("Windows")'>
					<then>
						<property scope="context" name="log.root.dir" value="c:/logs/"/>
					</then>
					<else>
						<property scope="context" name="log.root.dir" value="/tmp/logs"/>
					</else>
				</if>
			</else>
		</if>
	</else>
</if>

property()  或 p() 

the property() or its shorter equivalent p() 

 

isDefined()

判断key是否定义

The isDefined() method can be used to check whether a property is defined.

For example, to check whether the property “k” is defined you would write isDefined("k")

<if condition='isDefined("logging.mydir")'>
	<then>
		<property scope="context" name="LOG_FILE_DIR" value="${logging.mydir}"/>
	</then>
	<else>
		<property scope="context" name="LOG_FILE_DIR" value="c:/logs/otherdir"/>
	</else>

</if>

 

 

isNull

 if you need to check whether a property is null, the isNull() method is provided.

Example: isNull("k").

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/23236.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信