lif条件判断

更新时间:2023-06-15 21:09:53 阅读: 评论:0

本地开发需要打印控制台⽇志,⽽测试以及⽣产环境则不需要,此时可在l中通过配置⽂件值进⾏条件判断。
1.先上代码
bis珍惜资源 保护环境
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true"scanPeriod="30 conds">
<springProperty scope="context"name="env"source="v"/>
<appender name="FILE"class="ch.olling.RollingFileAppender">
...
...
</appender>
<appender name="STDOUT"class="ch.ConsoleAppender">
...
...
</appender>
<root level="INFO">
<appender-ref ref="FILE"/>
<if condition='property("env").contains("local")'>
<then>
<!-- this only enable in local -->
<appender-ref ref="STDOUT"/>
</then>
my love歌词</if>
</root>
application.properties
<dependency>
<groupId&dehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>3.0.6</version>
</dependency>
2.⽂档
Developers often need to juggle between veral logback configuration files targeting different environments such as development, testing and production. The configuration files have substantial parts in common differing only in a few places. To avoid duplication, logback supports conditional processing of configuration files with the help of , and elements so that a single configuration file can adequately target veral environments. Note that conditional processing requires the .
The general format for conditional statements is shown below.
<!-- if-then form -->
<if condition="some conditional expression">
<then>
...
</then>
</if>
<!-- if-then-el form -->
<if condition="some conditional expression">
<then>
...
</then>
herlf
<el>
...
</el>
</if>
The condition is a Java expression in which only context properties or system properties are accessible. For a key pasd as argument, the property() or its shorter equivalent p() methods return the String value of the property. For example, to access the value of a property with key “k”, you wou
makelove什么意思ld write property(“k”) or equivalently p(“k”). If the property with key “k” is undefined, the property method will return the empty string and not null. This avoids the need to check for null values.
The isDefined() method can be ud to check whether a property is defined. For example, to check whether the property “k” is defined you would write isDefined(“k”) Similarly, if you need to check whether a property is null, the isNull() method is provided. Example: isNull(“k”).
<configuration debug="true">
<if condition='property("HOSTNAME").contains("torino")'>
<then>
<appender name="CON"class="ch.ConsoleAppender">
<encoder>
<pattern>%d %-5level %logger{35} - %msg %n</pattern>
</encoder>
</appender>
<root>
<appender-ref ref="CON"/>
jk罗琳名言
</root>
</then>
lost是什么意思
</if>
<appender name="FILE"class="ch.FileAppender">
<file>${randomOutputDir}/conditional.log</file>
<encoder>
<pattern>%d %-5level %logger{35} - %msg %n</pattern>
moon festival
</encoder>
arturas</appender>
<root level="ERROR">成人学位英语考试成绩查询
<appender-ref ref="FILE"/>
</root>
</configuration>
Conditional processing is supported anywhere within the element. Nested if-then-el statements are also supported.
However, XML syntax is awfully cumbersome and is ill suited as the foundation of a general purpo programming language. Conquently, too many conditionals will quickly render your configuration files incomprehensible to subquent readers, including yourlf.

本文发布于:2023-06-15 21:09:53,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/146291.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:需要   控制台   打印   开发   英语考试   条件   资源
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图