目录
my解决方式:
1.?logback-spring.xml 指定环境
2. application.yml激活指定配置环境
3. logback-sping.xml文件
4. 启动服务
网上的操作方式是:我没有进行尝试,感兴趣的可以试试
nohup java -Dserver.port=8848 -Dlogging.level.root=INFO -Xmx256M -Xms256M -jar pig-register.jar --logging.config=classpath:logback-spring.xml >> /dev/null 2>&1 &
my解决方式:
1.?logback-spring.xml 指定环境
在logback-spring.xml 中的 springProfile 指定相应的配置文件就可以了 ,如果是测试项目,将配置信息都写到application.yml 里面,可以创建一个空的 applicaiton-local.yml 文件
2. application.yml激活指定配置环境
3. logback-sping.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<property name="LOG_HOME" value="./logs"/>
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
</Pattern>
</layout>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<appender name="fileInfoLog"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
</filter>
<File>${LOG_HOME}/macDay_info.log</File>
<encoder>
<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/macDay_info.%d.log</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="fileErrorLog"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<File>${LOG_HOME}/macDay_error.log</File>
<encoder>
<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_HOME}/macDay_error.%d.log</fileNamePattern>
</rollingPolicy>
</appender>
<springProfile name="local">
<root level="info">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileInfoLog"/>
<appender-ref ref="fileErrorLog"/>
</root>
</springProfile>
<springProfile name="dev">
<root level="info">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileInfoLog"/>
<appender-ref ref="fileErrorLog"/>
</root>
</springProfile>
<springProfile name="sim">
<root level="info">
<appender-ref ref="consoleAppender"/>
<appender-ref ref="fileInfoLog"/>
<appender-ref ref="fileErrorLog"/>
</root>
</springProfile>
</configuration>
4. 启动服务
控制台会正常的进行日志的打印?
|