springboot日志打印 logback-spring.xml

    科技2024-05-19  65

    logback-spring.xml

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %highlight(%-5level) %cyan(%logger{5}:%line) - %msg%n</pattern> </encoder> </appender> <!-- 默认 --> <appender name="DEFAULT_ROLLING" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>/var/dentistry/portal/logs/default.log</file> <!-- <file>E://default.log</file>--> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern>/var/dentistry/portal/logs/default-%d{yyyy-MM-dd}.%i.txt</fileNamePattern> <maxFileSize>20MB</maxFileSize> <maxHistory>60</maxHistory> <totalSizeCap>20GB</totalSizeCap> </rollingPolicy> <encoder> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern> </encoder> </appender> <springProfile name="dev"> <logger name="com.jwt.demo" level="DEBUG" additivity="false"> <appender-ref ref="DEFAULT_ROLLING"/> <appender-ref ref="STDOUT"/> </logger> <root level="INFO"> <appender-ref ref="DEFAULT_ROLLING"/> <appender-ref ref="STDOUT"/> </root> </springProfile> <springProfile name="prod"> <logger name="com.jwt.demo" level="INFO" additivity="false"> <appender-ref ref="DEFAULT_ROLLING"/> </logger> <root level="INFO"> <appender-ref ref="DEFAULT_ROLLING"/> </root> </springProfile> </configuration>

    pom.xml

    <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <spring.profiles.active>dev</spring.profiles.active> </properties> </profile> <profile> <id>prod</id> <properties> <spring.profiles.active>prod</spring.profiles.active> </properties> </profile> </profiles>

    application.yml

    spring: profiles: active: @spring.profiles.active@
    Processed: 0.038, SQL: 9