当前位置:网站首页>How to specify the output path of pig register Project Log

How to specify the output path of pig register Project Log

2022-06-23 05:55:00 CaptainCats

springboot,logback-spring.xml Don't take effect

Usually springboot project ,
Just in src/main/resources Add below logback-spring.xml that will do ,

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
	<property name="log.path" value="/opt/pig/logs/${project.artifactId}"/>
	<!--  Color log format  -->
	<property name="CONSOLE_LOG_PATTERN" value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/>
	<!--  Color log depends on rendering class  -->
	<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/>
	<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/>
	<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>
					
	<!-- Console log output -->
	<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
		<encoder>
			<pattern>${CONSOLE_LOG_PATTERN}</pattern>
		</encoder>
	</appender>

	<!-- Log file debug output -->
	<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${log.path}/debug.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${log.path}/%d{yyyy-MM, aux}/debug.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
			<maxFileSize>50MB</maxFileSize>
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
		</encoder>
	</appender>

	<!-- Log file error output -->
	<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${log.path}/error.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
			<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
			<maxFileSize>50MB</maxFileSize>
			<maxHistory>30</maxHistory>
		</rollingPolicy>
		<encoder>
			<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
		</encoder>
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
	</appender>

	<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
	<root level="INFO">
		<appender-ref ref="console"/>
		<appender-ref ref="debug"/>
		<appender-ref ref="error"/>
	</root>
</configuration>

Then I started the project , However, it is found that no log files are generated to the configured directory ,

I'm in again application.yml Specified in logback Configuration file for :

logging:
  config: classpath:logback-spring.xml

But it still doesn't take effect , What's going on here ?

My project is an open source project pig Registration Center for pig-register, It quoted nacos-core This jar package ,
I feel it is because of this dependence ( Because I start it locally pig-register At the time of C I have seen nacos Output log file ), I went to see naco-core This project , Found that it had a META-INF/logback/nacos.xml,
Inside nacos Of logback The configuration file ,
Then I found it in LoggingSpringApplicationRunListener This configuration file is used in ,
 Insert picture description here

LoggingSpringApplicationRunListener implements SpringApplicationRunListener

See here , I sort of understand what's going on ,

spring boot It's using LoggingApplicationListener To initialize the log system ,

System.setProperty(CONFIG_PROPERTY, DEFAULT_NACOS_LOGBACK_LOCATION);

This step will be LoggingApplicationListener Medium CONFIG_PROPERTY namely logging.config Set up in order to "META-INF/logback/nacos.xml",

And then look at nacos-core Of /META-INF/spring.factories,
 Insert picture description here
Sure enough, it was designated here SpringApplicationRunListener For the front LoggingSpringApplicationRunListener,
such pig-register quote nacos-core When , Will nacos Of LoggingSpringApplicationRunListener Sign up to spring boot In the container ( When it starts ),
such SpringApplicationRunListener I won't go again resource seek logback.xml、logback-spring.xml Such a default configuration file ,
So the configuration file we added doesn't work .

that , Is there no way to modify the log configuration ?

No, it isn't , We can do this at startup :

nohup java -Dserver.port=8848 -Dlogging.level.root=INFO -Xmx256M -Xms256M -jar pig-register.jar --logging.config=classpath:logback-spring.xml >> /dev/null 2>&1 &

Specify to use our configuration file .

Impropriety , Also please correct me .

Reference article :

Gado SpringBoot And logback-spring.xml Solutions that don't work
cy Tan logback.xml Don't take effect && spring boot The log configuration file could not be read
kangkaiispring boot Log file configuration (logback-spring.xml) Close test available !
CaptainCatsMETA-INF/spring.factories What is the function of documents
CaptainCatsnohup java -jar Background start , Parameters “> /dev/null 2>&1“ The meaning of .

原网站

版权声明
本文为[CaptainCats]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230419071483.html