logback方式,比较方便无脑。
<configuration> <!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d %p (%file:%line\)- %m%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <appender name="baselog" class="ch.qos.logback.core.rolling.RollingFileAppender"> <File>${log.dir}/logs/base.log</File> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${log.dir}/logs/base.log.%d.%i</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <!-- or whenever the file size reaches 64 MB --> <maxFileSize>64 MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> </rollingPolicy> <encoder> <pattern> %d %p (%logger:%line\)- %m%n </pattern> <charset>UTF-8</charset> <!-- 此处设置字符集 --> </encoder> </appender> <root level="debug"> <!-- 开发环境用 --> <appender-ref ref="STDOUT" /> <!-- 生产环境用 --> <!-- <appender-ref ref="baselog"/> --> </root> </configuration>