About logback use problems encountered and problem solving records

Configuration in logback.xml file

<?xml version="1.0" encoding="UTF-8" ?>
<!-- When the log component starts, print debugging information, and monitor the change of this file, the cycle is 300 seconds-->
<configuration scan="true" scanPeriod="300 seconds" debug="false">
	<!--Performance optimization for jul-->
	<contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
		<resetJUL> true </resetJUL>
	</contextListener>
	<!-- Configuration file, including the configuration of all variables in this file-->
	<property name="LOG_PATH" value="${user.dir}/logs" />
	<property name="APP_NAME" value="server" />
	<!-- contextName is mainly to distinguish when multiple applications are deployed under a web container to enable jmx, there will be no confusion -->
	<contextName>${APP_NAME}</contextName>
	<!-- ***************************************************************** -->
	<!-- Configure the output to the console, and enable output to the console only during development and testing. The following statement takes effect in the window environment. Students who use mac or ubuntu, please construct it yourself -->
	<!-- ***************************************************************** -->
	<if condition='property("os.name").toUpperCase().contains("WINDOWS") || property("os.name").toUpperCase().contains("MAC")'>
		<then>
			<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
				<encoder>
					<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{0}:%L- %msg%n</pattern>
				</encoder>
			</appender>
			<root>
				<appender-ref ref="STDOUT" />
			</root>
		</then>
	</if>
	<!-- ***************************************************************** -->
	<!-- info level log appender -->
	<!-- ***************************************************************** -->
	<appender name="APP-INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${LOG_PATH}/${APP_NAME}-info-30dt.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${LOG_PATH}/${APP_NAME}-info-30dt.log.%d{yyyy-MM-dd}.%i
			</fileNamePattern>
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>1024MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder>
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{0}:%L- %msg%n</pattern>
		</encoder>
	</appender>
	<!-- ***************************************************************** -->
	<!-- error level log appender -->
	<!-- ***************************************************************** -->
	<appender name="APP-ERR" class="ch.qos.logback.core.rolling.RollingFileAppender">
		<file>${LOG_PATH}/${APP_NAME}-error-30dt.log</file>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<fileNamePattern>${LOG_PATH}/${APP_NAME}-error-30dt.%d{yyyy-MM-dd}.%i
			</fileNamePattern>
			<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>1024MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
			<level>ERROR</level>
		</filter>
		<encoder>
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{0}:%L- %msg%n</pattern>
		</encoder>
	</appender>

	<!-- root log logger -->
	<root level="DEBUG">
		<appender-ref ref="APP-ERR" />
		<appender-ref ref="APP-INFO" />
		<appender-ref ref="STDOUT" />
	</root>

</configuration>

 

encountered problems (1)

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/shuang/maven_repository/ch/qos/logback/logback-classic/1.0.13/logback-classic-1.0.13.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/shuang/maven_repository/org/slf4j/slf4j-log4j12/1.7.12/slf4j-log4j12-1.7.12.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
log4j:WARN No appenders could be found for logger (com.alibaba.druid.pool.DruidDataSource).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

 The above problem is because the same jar package exists, check whether there are duplicate jar packages related to slf4j and log4j, etc.

 

encountered a problem (2)

14:49:53,026 |-ERROR in ch.qos.logback.core.joran.conditional.IfAction - Could not find Janino library on the class path. Skipping conditional processing.
14:49:53,026 |-ERROR in ch.qos.logback.core.joran.conditional.IfAction - See also http://logback.qos.ch/codes.html#ifJanino
14:49:53,125 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - Could not find an appender named [STDOUT]. Did you define it below instead of above in the configuration file?
14:49:53,125 |-ERROR in ch.qos.logback.core.joran.action.AppenderRefAction - See http://logback.qos.ch/codes.html#appender_order for more details.

 The problem above is that the following jar package is missing

   <!-- The org.codehaus.janino:commons-compiler:2.6.1 dependency -->
    <!-- will be automatically pulled in by Maven's transitivity rules -->
    <dependency>
        <groupId>org.codehaus.janino</groupId>
        <artifactId>janino</artifactId>
        <version>2.6.1</version>
    </dependency>

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326444921&siteId=291194637