[java基础]logback日志按照日志级别输出

logback日志按照日志级别输出:

<configuration>
	<property name="APP_NAME" value="parkApi" />
	<property name="LOG_HOME" value="log" />
	<contextName>${APP_NAME}contextName>
	
	<appender name="stdout"
		class="ch.qos.logback.core.ConsoleAppender">
		<encoder charset="UTF-8">
			<pattern>%d{yyyy-MM-dd HH:mm:ss} %5p %c:%L %m%npattern>
		encoder>
	appender>
	
	<appender name="FILE"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		
		<file>${LOG_HOME}/${APP_NAME}.logfile>
		<rollingPolicy
			class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			
			<fileNamePattern>${LOG_HOME}/logbacks/${APP_NAME}-%d{yyyy-MM-dd}-%i.log
			fileNamePattern>
			<MaxHistory>180MaxHistory>
			
			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>1KBmaxFileSize>
			timeBasedFileNamingAndTriggeringPolicy>
		rollingPolicy>
		
		<layout class="ch.qos.logback.classic.PatternLayout">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [
				%logger{50} : %line ] - %msg%npattern>
		layout>
	appender>

	
	
	
	<root level="DEBUG">
		<appender-ref ref="stdout" />
		<appender-ref ref="FILE" />
	root>

	

	
	<appender name="errorAppender"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		
		<file>${LOG_HOME}/${APP_NAME}-error.logfile>
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			
			-->
			<level>ERRORlevel>
			<onMatch>ACCEPTonMatch>
			<onMismatch>DENYonMismatch>
		filter>
		<rollingPolicy
			class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			
			<fileNamePattern>${LOG_HOME}/logbacks/${APP_NAME}-error-%d{yyyy-MM-dd}-%i.log
			fileNamePattern>
			<MaxHistory>180MaxHistory>
			
			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>1KBmaxFileSize>
			timeBasedFileNamingAndTriggeringPolicy>
		rollingPolicy>
		
		<layout class="ch.qos.logback.classic.PatternLayout">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [
				%logger{50} : %line ] - %msg%npattern>
		layout>
	appender>
	<appender name="infoAppender"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		
		<file>${LOG_HOME}/${APP_NAME}-info.logfile>
		
		<filter class="ch.qos.logback.classic.filter.LevelFilter">
			
			<level>INFOlevel>
			<onMatch>ACCEPTonMatch>
			<onMismatch>DENYonMismatch>
		filter>
		<rollingPolicy
			class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			
			<fileNamePattern>${LOG_HOME}/${APP_NAME}-info-%d{yyyy-MM-dd}-%i.log
			fileNamePattern>
			<MaxHistory>180MaxHistory>
			
			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<maxFileSize>1KBmaxFileSize>
			timeBasedFileNamingAndTriggeringPolicy>
		rollingPolicy>
		
		<layout class="ch.qos.logback.classic.PatternLayout">
			<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [ %thread ] - [ %-5level ] [
				%logger{50} : %line ] - %msg%npattern>
		layout>
	appender>

	
	
	
	<logger name="com.wr.park_toolkit" additivity="false">
		<appender-ref ref="infoAppender" />
		<appender-ref ref="errorAppender" />
	logger>

	
configuration>

你可能感兴趣的:(Java,#,Java基础,java,log4j2,logback,logging,log4j)