成熟丰满熟妇高潮XXXXX,人妻无码AV中文系列久久兔费 ,国产精品一国产精品,国精品午夜福利视频不卡麻豆

您好,歡迎來到九壹網(wǎng)。
搜索
您的當(dāng)前位置:首頁SpringbootLogback日志使用,SpringbootLogback詳細(xì)配置和日志分割

SpringbootLogback日志使用,SpringbootLogback詳細(xì)配置和日志分割

來源:九壹網(wǎng)
?SpringbootLogback?志使?,SpringbootLogback詳細(xì)配置和

?志分割

Springboot Logback?志使?,Springboot Logback詳細(xì)配置和?志分割Springboot Logback springProperty使?,Springboot Logback區(qū)分環(huán)境

================================?Copyright 蕃薯耀 2020-12-23

?、引?Logback?志的maven依賴:logback-classic

ch.qos.logback logback-classic

?、Springboot Logback 區(qū)分環(huán)境配置:1、application.properties:

spring.profiles.active=dev

server.port=6000

server.servlet.context-path=/logback

2、application-dev.properties:

logging.config=classpath:logback-spring-dev.xml

3、application-test.properties:

logging.config=classpath:logback-spring-test.xml

4、application-prod.properties:

logging.config=classpath:logback-spring-prod.xml

通過logging.config設(shè)置Springboot使?的?志配置?件,這樣每個(gè)環(huán)境都可以使?不能的配置。如果不區(qū)分環(huán)境,可以直接命名為:logback-spring.xml,這樣Springboot會(huì)?動(dòng)加載。

三、Springboot Logback.xml 配置?件詳細(xì)設(shè)置:1、logback-spring-dev.xml

[${springProfilesActive}]${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/info.log

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-info.log

${logDays}

[${springProfilesActive}]${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/warn.log

WARN

ACCEPT DENY

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-warn.log

${logDays}

[${springProfilesActive}]${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/error.log

ERROR

ACCEPT DENY

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-error.log

${logDays}

[${springProfilesActive}]${log_style}

2、logback-spring-test.xml

${LOG_HOME}/${projectName}/${weblogicName}/info.log

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-info.log

${logDays}

[${springProfilesActive}]${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/warn.log

WARN

ACCEPT DENY

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-warn.log

${logDays}

[${springProfilesActive}]${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/error.log

ERROR

ACCEPT DENY

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-error.log

${logDays}

[${springProfilesActive}]${log_style}

3、logback-spring-prod.xml

${LOG_HOME}/${projectName}/${weblogicName}/info.log

${LOG_HOME}/${projectName}/${weblogicName}/%d{yyyy-MM-dd}-info.log

${logDays}

${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/warn.log

WARN

ACCEPT DENY

${LOG_HOME}/${projectName}/${weblogicName}/${history}/%d{yyyy-MM-dd}-warn.log

${logDays}

${log_style}

${LOG_HOME}/${projectName}/${weblogicName}/error.log

ERROR

ACCEPT DENY

${LOG_HOME}/${projectName}/${weblogicName}/%d{yyyy-MM-dd}-error.log

${logDays}

${log_style}

四、logback的使?(LogbackStartupListener.java)在logback的xml配置?件中,有?個(gè)的配置:

類?件:

package com.lqy.log.listener;

import org.springframework.util.StringUtils;

import ch.qos.logback.classic.Level;import ch.qos.logback.classic.Logger;

import ch.qos.logback.classic.LoggerContext;

import ch.qos.logback.classic.spi.LoggerContextListener;import ch.qos.logback.core.Context;

import ch.qos.logback.core.spi.ContextAwareBase;import ch.qos.logback.core.spi.LifeCycle;

public class LogbackStartupListener extends ContextAwareBase implements LoggerContextListener, LifeCycle {

@Override

public void start() {

//log.info(\"LogbackStartupListener start()\");

String userDir = System.getProperty(\"user.dir\"); String osName = System.getProperty(\"os.name\"); String osVersion = System.getProperty(\"os.version\"); String javaVersion = System.getProperty(\"java.version\");

String weblogicName = System.getProperty(\"weblogic.Name\");

System.out.println(\"userDir===\" + userDir); System.out.println(\"osName===\" + osName); System.out.println(\"osVersion===\" + osVersion); System.out.println(\"javaVersion===\" + javaVersion);

System.out.println(\"weblogicName===\" + weblogicName);

if(StringUtils.isEmpty(weblogicName)) { weblogicName = \"notWeblogic\"; }

System.out.println(\"weblogicName2===\" + weblogicName);

Context context = getContext();

context.putProperty(\"weblogicName\ }

@Override

public void stop() {

//log.info(\"LogbackStartupListener stop()\"); }

@Override

public boolean isStarted() { return false; }

@Override

public boolean isResetResistant() { return false; }

@Override

public void onStart(LoggerContext context) { //log.info(\"LogbackStartupListener onStart()\"); }

@Override

public void onReset(LoggerContext context) { //log.info(\"LogbackStartupListener onReset()\"); }

@Override

public void onStop(LoggerContext context) { //log.info(\"LogbackStartupListener onStop()\"); }

@Override

public void onLevelChange(Logger logger, Level level) { //log.info(\"LogbackStartupListener onLevelChange()\"); }}

1、為什么要使?:

通過,可以往logback的context注?變量,如系統(tǒng)環(huán)境變量(os.name),這樣在配置?件就能通過${os.name}直接引?使?變量的值。

如?例中引?了weblogic容器的服務(wù)名稱:weblogic.Name

String weblogicName = System.getProperty(\"weblogic.Name\");context.putProperty(\"weblogicName\

xml引?使?就是:${weblogicName}使?如下:

${LOG_HOME}/${projectName}/${weblogicName}/info.log

五、logback通過springProperty標(biāo)簽使?Springboot配置?件中的變量1、logback引?Springboot配置?件的環(huán)境變量name:?定義別名

source:對應(yīng)Springboot配置?件中的屬性名

使?:

${springProfilesActive}?例:

[${springProfilesActive}]${log_style}

2、logback使?springProperty標(biāo)簽可能存在的問題報(bào)錯(cuò):

no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]詳細(xì)錯(cuò)誤如下:

Logging system failed to initialize using configuration from 'classpath:logback-test.xml'java.lang.IllegalStateException: Logback configuration error detected:

ERROR in ch.qos.logback.core.joran.spi.Interpreter@13:83 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]] at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:169) at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66) at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)

at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)

at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:310) at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:281)

at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239) at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)

at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:80) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:345) at org.springframework.boot.SpringApplication.run(SpringApplication.java:308) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) at com.lqy.log.LogbackApplication.main(LogbackApplication.java:10) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498)

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

[classpath:logback-test.xml][notWeblogic][ERROR] [2020-12-22 10:39:29.409] org.springframework.boot.SpringApplication.reportFailure:837Application run failed

原因:

logback最開始使?的命名是:logback-test.xml,這樣會(huì)導(dǎo)致出錯(cuò)。

SpringBoot 會(huì)在 classpath 下查找是否有l(wèi)ogback的 jar包,存在jar包,然后檢查配置?件,包含 logback-test.groovy、logback-test.xml、logback.groovy 或者 logback.xml,如果都找不到的話,才會(huì)加載項(xiàng)?路徑下的 logback-spring.xml。

如果命名為logback-test.xml,logback會(huì)優(yōu)先SpringBoot加載完,導(dǎo)致加載不到SpringBoot配置?件的變量?報(bào)錯(cuò)。

解決?案:?案?(?選):

簡單的解決?法,就是重命名,改成:logback-spring-test.xml ?案?:

不使?springProperty標(biāo)簽,通過LogbackStartupListener注?相關(guān)的變量,上?已經(jīng)說到。

六、測試logback?志:

import java.util.Date;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;@RequestMapping(\"/\")@RestController

public class LogController {

private static final Logger log = LoggerFactory.getLogger(LogController.class);

@RequestMapping(\"log\") public String log() {

String time = new Date().getTime() + \"\"; log.info(time);

log.info(\"{} + {} is {}\

log.warn(\"{} + {} is not {}\

String weblogicName = System.getProperty(\"weblogic.Name\"); log.error(\"weblogicName==={}\

return \"ok,時(shí)間=\" + time + \",weblogicName=\" + weblogicName; }}

(如果?章對您有幫助,歡迎捐贈(zèng),^_^)================================?Copyright 蕃薯耀 2020-12-23

因篇幅問題不能全部顯示,請點(diǎn)此查看更多更全內(nèi)容

Copyright ? 2019- 91gzw.com 版權(quán)所有 湘ICP備2023023988號-2

違法及侵權(quán)請聯(lián)系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市萬商天勤律師事務(wù)所王興未律師提供法律服務(wù)