logback的使用(1)

1、写logback.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<appender name="usercenter"
		class="ch.qos.logback.core.rolling.RollingFileAppender">
		<!--See http://logback.qos.ch/manual/appenders.html#RollingFileAppender -->
		<!--and http://logback.qos.ch/manual/appenders.html#TimeBasedRollingPolicy -->
		<!--for further documentation -->
		<File>/var/log/usercenter/usercenter.log</File>
		<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
			<!-- rollover daily -->
			<fileNamePattern>/var/log/usercenter/usercenter-%d{yyyy-MM}.%i.log
			</fileNamePattern>
			<timeBasedFileNamingAndTriggeringPolicy
				class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
				<!-- or whenever the file size reaches 100MB -->
				<maxFileSize>50MB</maxFileSize>
			</timeBasedFileNamingAndTriggeringPolicy>
		</rollingPolicy>
		<encoder>
			<pattern>[%date] [%level] [%thread] [%C.%M:%L] %msg%n</pattern>
		</encoder>
	</appender>

	<logger name="test" level="DEBUG">
		<appender-ref ref="usercenter" />
	</logger>
</configuration>

将文件放在src目录下

2、在项目中使用

Logger log = LoggerFactory.getLogger("test");
log.debug("helloword");


你可能感兴趣的:(thread,Date,File,Class,documentation,encoding)