亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

使用Logback設(shè)置property參數(shù)方式

 更新時(shí)間:2023年03月10日 09:31:19   作者:yh_1524  
這篇文章主要介紹了使用Logback設(shè)置property參數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Logback設(shè)置property參數(shù)

更多參數(shù)設(shè)置查看官方文檔

1.方式一:直接配置參數(shù)值

<configuration>

? <property name="USER_HOME" value="/home/sebastien" />

? <appender name="FILE" class="ch.qos.logback.core.FileAppender">
? ? <file>${USER_HOME}/myApp.log</file>
? ? <encoder>
? ? ? <pattern>%msg%n</pattern>
? ? </encoder>
? </appender>

? <root level="debug">
? ? <appender-ref ref="FILE" />
? </root>
</configuration>

2.方式二:通過file屬性引入?yún)?shù)文件

<configuration>

? <!-- 引入項(xiàng)目?jī)?nèi)的文件指定文件所在的包路徑 -->
? <property file="src/main/java/chapters/configuration/variables1.properties" />
? <!-- 引入項(xiàng)目外的文件指定文件所在的絕對(duì)路徑 -->
? <property file="/home/logback/variables.properties" />

? <appender name="FILE" class="ch.qos.logback.core.FileAppender">
? ? ?<file>${USER_HOME}/myApp.log</file>
? ? ?<encoder>
? ? ? ?<pattern>%msg%n</pattern>
? ? ?</encoder>
? ?</appender>
? ?<root level="debug">
? ? ?<appender-ref ref="FILE" />
? ?</root>
</configuration>

3.方式三:通過resource屬性引入?yún)?shù)文件

<configuration>
? <!-- 使用classpath的方式引入文件,只需寫明文件名即可 -->
? <property resource="resource1.properties" />

? <appender name="FILE" class="ch.qos.logback.core.FileAppender">
? ? ?<file>${USER_HOME}/myApp.log</file>
? ? ?<encoder>
? ? ? ?<pattern>%msg%n</pattern>
? ? ?</encoder>
? ?</appender>

? ?<root level="debug">
? ? ?<appender-ref ref="FILE" />
? ?</root>
</configuration>

4.引入文件處理類PropertyAction

文件所在路徑:ch.qos.logback.core.joran.action

在begin方法中讀取引入的properies文件,如果引入的文件中的參數(shù)值需要進(jìn)行額外的加工處理,可重寫覆蓋此類,在begin或loadAndSetProperties方法中添加相關(guān)邏輯

/**
 * Logback: the reliable, generic, fast and flexible logging framework.
 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
 *
 * This program and the accompanying materials are dual-licensed under
 * either the terms of the Eclipse Public License v1.0 as published by
 * the Eclipse Foundation
 *
 *   or (per the licensee's choosing)
 *
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation.
 */
package ch.qos.logback.core.joran.action;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;

import org.xml.sax.Attributes;

import ch.qos.logback.core.joran.action.ActionUtil.Scope;
import ch.qos.logback.core.joran.spi.InterpretationContext;
import ch.qos.logback.core.pattern.util.RegularEscapeUtil;
import ch.qos.logback.core.util.Loader;
import ch.qos.logback.core.util.OptionHelper;

/**
 * This class serves as a base for other actions, which similar to the ANT
 * &lt;property&gt; task which add/set properties of a given object.
 * 
 * This action sets new substitution properties in the logging context by name,
 * value pair, or adds all the properties passed in "file" or "resource"
 * attribute.
 * 
 * @author Ceki G&uuml;lc&uuml;
 */
public class PropertyAction extends Action {

    static final String RESOURCE_ATTRIBUTE = "resource";

    static String INVALID_ATTRIBUTES = "In <property> element, either the \"file\" attribute alone, or "
                    + "the \"resource\" element alone, or both the \"name\" and \"value\" attributes must be set.";

    /**
     * Set a new property for the execution context by name, value pair, or adds
     * all the properties found in the given file.
     * 
     */
    public void begin(InterpretationContext ec, String localName, Attributes attributes) {

        if ("substitutionProperty".equals(localName)) {
            addWarn("[substitutionProperty] element has been deprecated. Please use the [property] element instead.");
        }

        String name = attributes.getValue(NAME_ATTRIBUTE);
        String value = attributes.getValue(VALUE_ATTRIBUTE);
        String scopeStr = attributes.getValue(SCOPE_ATTRIBUTE);

        Scope scope = ActionUtil.stringToScope(scopeStr);

        if (checkFileAttributeSanity(attributes)) {
            String file = attributes.getValue(FILE_ATTRIBUTE);
            file = ec.subst(file);
            try {
                FileInputStream istream = new FileInputStream(file);
                loadAndSetProperties(ec, istream, scope);
            } catch (FileNotFoundException e) {
                addError("Could not find properties file [" + file + "].");
            } catch (IOException e1) {
                addError("Could not read properties file [" + file + "].", e1);
            }
        } else if (checkResourceAttributeSanity(attributes)) {
            String resource = attributes.getValue(RESOURCE_ATTRIBUTE);
            resource = ec.subst(resource);
            URL resourceURL = Loader.getResourceBySelfClassLoader(resource);
            if (resourceURL == null) {
                addError("Could not find resource [" + resource + "].");
            } else {
                try {
                    InputStream istream = resourceURL.openStream();
                    loadAndSetProperties(ec, istream, scope);
                } catch (IOException e) {
                    addError("Could not read resource file [" + resource + "].", e);
                }
            }
        } else if (checkValueNameAttributesSanity(attributes)) {
            value = RegularEscapeUtil.basicEscape(value);
            // now remove both leading and trailing spaces
            value = value.trim();
            value = ec.subst(value);
            ActionUtil.setProperty(ec, name, value, scope);

        } else {
            addError(INVALID_ATTRIBUTES);
        }
    }

    void loadAndSetProperties(InterpretationContext ec, InputStream istream, Scope scope) throws IOException {
        Properties props = new Properties();
        props.load(istream);
        istream.close();
        ActionUtil.setProperties(ec, props, scope);
    }

    boolean checkFileAttributeSanity(Attributes attributes) {
        String file = attributes.getValue(FILE_ATTRIBUTE);
        String name = attributes.getValue(NAME_ATTRIBUTE);
        String value = attributes.getValue(VALUE_ATTRIBUTE);
        String resource = attributes.getValue(RESOURCE_ATTRIBUTE);

        return !(OptionHelper.isEmpty(file)) && (OptionHelper.isEmpty(name) && OptionHelper.isEmpty(value) && OptionHelper.isEmpty(resource));
    }

    boolean checkResourceAttributeSanity(Attributes attributes) {
        String file = attributes.getValue(FILE_ATTRIBUTE);
        String name = attributes.getValue(NAME_ATTRIBUTE);
        String value = attributes.getValue(VALUE_ATTRIBUTE);
        String resource = attributes.getValue(RESOURCE_ATTRIBUTE);

        return !(OptionHelper.isEmpty(resource)) && (OptionHelper.isEmpty(name) && OptionHelper.isEmpty(value) && OptionHelper.isEmpty(file));
    }

    boolean checkValueNameAttributesSanity(Attributes attributes) {
        String file = attributes.getValue(FILE_ATTRIBUTE);
        String name = attributes.getValue(NAME_ATTRIBUTE);
        String value = attributes.getValue(VALUE_ATTRIBUTE);
        String resource = attributes.getValue(RESOURCE_ATTRIBUTE);

        return (!(OptionHelper.isEmpty(name) || OptionHelper.isEmpty(value)) && (OptionHelper.isEmpty(file) && OptionHelper.isEmpty(resource)));
    }

    public void end(InterpretationContext ec, String name) {
    }

    public void finish(InterpretationContext ec) {
    }
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java線程安全和鎖Synchronized知識(shí)點(diǎn)詳解

    Java線程安全和鎖Synchronized知識(shí)點(diǎn)詳解

    在本篇文章里小編給大家分享的是關(guān)于Java線程安全和鎖Synchronized相關(guān)知識(shí)點(diǎn),有需要的朋友們可以參考下。
    2019-08-08
  • java 獲取中文拼音首字母及全拼的實(shí)踐

    java 獲取中文拼音首字母及全拼的實(shí)踐

    本文主要介紹了java 獲取中文拼音首字母及全拼的實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-08-08
  • js判斷是否是移動(dòng)設(shè)備登陸網(wǎng)頁的簡(jiǎn)單方法

    js判斷是否是移動(dòng)設(shè)備登陸網(wǎng)頁的簡(jiǎn)單方法

    這篇文章主要介紹了js判斷是否是移動(dòng)設(shè)備登陸網(wǎng)頁的簡(jiǎn)單方法,需要的朋友可以參考下
    2014-02-02
  • springboot @ConditionalOnMissingBean注解的作用詳解

    springboot @ConditionalOnMissingBean注解的作用詳解

    這篇文章主要介紹了springboot @ConditionalOnMissingBean注解的作用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Java中string和int的互相轉(zhuǎn)換問題

    Java中string和int的互相轉(zhuǎn)換問題

    本文通過實(shí)例代碼給大家詳細(xì)介紹了Java中string和int的互相轉(zhuǎn)換問題,感興趣的朋友一起看看吧
    2017-10-10
  • SpringBoot集成七牛云OSS的示例詳解

    SpringBoot集成七牛云OSS的示例詳解

    OSS的英文全稱是Object?Storage?Service,翻譯成中文就是對(duì)象存儲(chǔ)服務(wù),官方一點(diǎn)解釋就是對(duì)象存儲(chǔ)是一種使用HTTP?API存儲(chǔ)和檢索非結(jié)構(gòu)化數(shù)據(jù)和元數(shù)據(jù)對(duì)象的工具,本文給大家詳細(xì)介紹了SpringBoot集成七牛云OSS的示例,需要的朋友可以參考下
    2023-11-11
  • JAVA格式化時(shí)間日期的簡(jiǎn)單實(shí)例

    JAVA格式化時(shí)間日期的簡(jiǎn)單實(shí)例

    這篇文章主要介紹了JAVA格式化時(shí)間日期的簡(jiǎn)單實(shí)例,有需要的朋友可以參考一下
    2013-11-11
  • Java根據(jù)實(shí)體生成SQL數(shù)據(jù)庫表的示例代碼

    Java根據(jù)實(shí)體生成SQL數(shù)據(jù)庫表的示例代碼

    這篇文章主要來和大家分享一個(gè)Java實(shí)現(xiàn)根據(jù)實(shí)體生成SQL數(shù)據(jù)庫表的代碼,文中的實(shí)現(xiàn)代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-07-07
  • SpringBoot3和mybatis-plus整合出現(xiàn)的問題解決辦法

    SpringBoot3和mybatis-plus整合出現(xiàn)的問題解決辦法

    SpringBoot和MybatisPlus的整合可以讓我們更加方便地進(jìn)行數(shù)據(jù)庫操作,這篇文章主要給大家介紹了關(guān)于SpringBoot3和mybatisplus整合出現(xiàn)的一些問題的相關(guān)資料,需要的朋友可以參考下
    2024-01-01
  • java類成員中的訪問級(jí)別淺析

    java類成員中的訪問級(jí)別淺析

    在本篇文章里小編給大家整理的是一篇關(guān)于java類成員中的訪問級(jí)別淺析內(nèi)容,有興趣的朋友們跟著學(xué)習(xí)下。
    2021-01-01

最新評(píng)論