mac 笔记本开发,日志文件写到/data/logs/下,控制台报出:Failed to create parent directories for [/data/logs/...........
再去手动在命令窗口创建文件夹data,报Read-only file system
resource 目录下的配置文件列表:
在logback-spring.xml添加配置, 只有local写到当前项目下的data目录,其他环境写到系统根目录/data下
完整的logback-spring.xm
- "1.0" encoding="UTF-8"?>
-
- <configuration debug="false">
- <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
- <springProperty scope="context" name="appName" source="spring.application.name"
- defaultValue="onemap-quality-manage-service"/>
- <springProperty scope="context" name="ip" source="spring.cloud.client.ip-address"/>
- <property name="CONSOLE_LOG_PATTERN"
- value="[%d{yyyy-MM-dd HH:mm:ss.SSS}] [${ip} ${appName}] [%(%-5level) %logger{80}:%line]:%msg%n"/>
- <property name="LOG_HOME" value="/data/logs/${appName}/${hostname}/"/>
- <springProfile name="local">
- <property name="LOG_HOME" value="./data/logs/${appName}/${hostname}/"/>
- springProfile>
-
- <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
- <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <pattern>${CONSOLE_LOG_PATTERN}pattern>
- <charset>UTF-8charset>
- encoder>
- appender>
-
-
- <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${LOG_HOME}/${appName}-${ip}-info.logfile>
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-
- <FileNamePattern>${LOG_HOME}/${appName}-${ip}-info-%d{yyyy-MM-dd}.logFileNamePattern>
-
- <MaxHistory>30MaxHistory>
- rollingPolicy>
- <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <pattern>${CONSOLE_LOG_PATTERN}pattern>
- <charset>UTF-8charset>
- encoder>
- appender>
-
-
- <appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${LOG_HOME}/${appName}-${ip}-error.logfile>
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-
- <FileNamePattern>${LOG_HOME}/${appName}-${ip}-error-%d{yyyy-MM-dd}.logFileNamePattern>
-
- <MaxHistory>30MaxHistory>
- rollingPolicy>
- <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
- <pattern>${CONSOLE_LOG_PATTERN}pattern>
- <charset>UTF-8charset>
- encoder>
-
- <filter class="ch.qos.logback.classic.filter.LevelFilter">
- <level>ERRORlevel>
- <onMatch>ACCEPTonMatch>
- <onMismatch>DENYonMismatch>
- filter>
- appender>
-
-
- <logger name="org.springframework" level="INFO"/>
- <logger name="org.apache" level="WARN"/>
-
-
- <root level="INFO">
- <appender-ref ref="STDOUT"/>
- <appender-ref ref="FILE"/>
- <appender-ref ref="ERROR"/>
- root>
- configuration>
日志写到当前项目下的/data/目录