使用logging.config配置 logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="LOG_DIR" value="logs"/>
<property name="pattern" value="%d{yyyyMMdd:HH:mm:ss.SSS}[%c] [userId=%X{dolphinUserId}][pageId=%X{dolphinPageId}][sqlId=%X{dolphinSysWidgetCallId}][%thread] %-5level %msg%n "/>
<property name="sqlPattern" value="%d{yyyyMMdd:HH:mm:ss.SSS}[%c] [userId=%X{dolphinUserId}][pageId=%X{dolphinPageId}][sqlId=%X{dolphinSysWidgetCallId}][databaseId=%X{dolphinDataBaseId}] [%thread] %-5level %msg%n "/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<target>System.out</target>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${pattern}</pattern>
</encoder>
</appender>
<appender name="LOG_INFO" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/system_info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/system_info_%d{yyyy-MM-dd}.log.%i.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>50</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="LOG_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/system_debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/system_debug_%d{yyyy-MM-dd}.log.%i.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>50</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="SQL_LOG_DEBUG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/sql_debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/sql_debug_%d{yyyy-MM-dd}.log.%i.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>50</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${sqlPattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="LOG_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/system_error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/system_error_%d{yyyy-MM-dd}.log.%i.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>50</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${pattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<appender name="SLOW_LOG_ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_DIR}/slow_sql.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_DIR}/slow_sql_%d{yyyy-MM-dd}.log.%i.gz</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<maxFileSize>20MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
<maxHistory>50</maxHistory>
</rollingPolicy>
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
<pattern>${sqlPattern}</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<logger name="druid.sql.Statement" level="debug" additivity="false">
<appender-ref ref="SQL_LOG_DEBUG"></appender-ref>
<appender-ref ref="LOG_ERROR"></appender-ref>
</logger>
<logger name="com.dolphin.config.datasource.SlowSqlLogFilter" level="error" additivity="false">
<appender-ref ref="SLOW_LOG_ERROR"></appender-ref>
</logger>
<root level="info">
<appender-ref ref="LOG_INFO"/>
<appender-ref ref="LOG_ERROR"/>
</root>
</configuration>
Liunx脚本配置日志 config/logback.xml创建config文件夹,把logback.xml放到config中 config位于demo.jar的同级目录
启动start.sh
echo ""
echo "[信息] 运行Web工程。"
echo ""
APP_BASE_PATH=$(cd `dirname $0`; pwd)
SPRING_BOOT_OPTS="--server.tomcat.basedir=$APP_BASE_PATH/temp"
SPRING_BOOT_OPTS="$SPRING_BOOT_OPTS --logging.config=$APP_BASE_PATH/config/logback.xml"
SPRING_BOOT_OPTS="$SPRING_BOOT_OPTS --server.port=8080"
SPRING_BOOT_OPTS="$SPRING_BOOT_OPTS --dolphin.system.basedata.max.query.count=10000"
JAVA_OPTS="$MAVEN_OPTS -Xms128m -Xmx512m -Ddolphin.conf=file:$APP_BASE_PATH/../ -Ddolphin.log.path=$APP_BASE_PATH"
JAVA_OPTS="$JAVA_OPTS -Dehcache.conf=file:$APP_BASE_PATH/config"
JAVA_OPTS="$JAVA_OPTS -Ddolphin.base.path=$APP_BASE_PATH"
if [ -z "$JAVA_HOME" ]; then
RUN_JAVA=java
else
RUN_JAVA="$JAVA_HOME"/bin/java
fi
exec nohup $RUN_JAVA $JAVA_OPTS -jar $APP_BASE_PATH/demo.jar $SPRING_BOOT_OPTS > nohup.out &
停止stop.sh
APP_BASE_PATH=$(cd `dirname $0`; pwd)
echo $APP_BASE_PATH
ps -ef | grep $APP_BASE_PATH | grep java |grep -v grep | awk '{print $2}' | xargs kill -9
重启restart.sh
APP_BASE_PATH=$(cd `dirname $0`; pwd)
echo $APP_BASE_PATH
ps -ef | grep $APP_BASE_PATH | grep java |grep -v grep | awk '{print $2}' | xargs kill -9
sh ./start.sh
|