阅读量:0
1、在src/main/resources下添加logback-spring.xml(springboot会自动识别改配置文件),配置如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <fileNamePattern>${LOG_DIR}/logs/%d{yyyy-MM}/current-%d{yyyy-MM-dd}-%i.log</fileNamePattern> <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP"> <maxFileSize>10MB</maxFileSize> </timeBasedFileNamingAndTriggeringPolicy> <maxHistory>30</maxHistory> </rollingPolicy> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> </appender> <root level="info"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> <appender name="STDOUT_TO_FILE" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern> </encoder> <target>SYSTEM_OUT</target> </appender> <logger name="java.lang.System.out" level="INFO" additivity="false"> <appender-ref ref="STDOUT_TO_FILE" /> </logger> </configuration>
大致的意思是会滚动根据当前时间生成文件夹及日志文件,其中日志包含SYSTEM_OUT的输出。
打成jar包后,在bat或者sh启动文件中的命令:主要声明DLOG_DIR以上xml的配置
bat:
java -DLOG_DIR=D:/project/easMq -jar D:/project/easMq/RabbitMQToEasService.jar --server.port=8085 &
sh
#!/bin/bash nohup java -DLOG_DIR=/soft/cosmicMqToEasServer -jar /soft/cosmicMqToEasServer/RabbitMQToEasService.jar --server.port=8085 & echo "RabbitMQToEasService started."