ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.87k stars 514 forks source link

Logback.xml cannot obtain spring.application.name in bootstrap.properties #359

Open yangtao5826 opened 1 year ago

yangtao5826 commented 1 year ago

jasypt version:3.0.5 springboot version:3.0.0 bootstrap.yml:

spring:
  application:
    name: config-client

application.yml:

server:
    port: 8081
logging:
    file:
        path: c:\temp\logs

logback.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

    <springProperty scope="context" name="springAppName" source="spring.application.name"/>
    <springProperty scope="context" name="springAppPort" source="server.port"/>
    <springProperty scope="context" name="springLogPath" source="logging.file.path"/>

    <property name="LOG_PATTERN"
              value="%d{ss.SSS} %highlight(%-5level) %blue(%-30logger{30}:%-4line) %thread %msg%n"/>

    <property name="LOG_FILE" value="${springLogPath:-log}/${springAppName}_${springAppPort}.log"/>

    <appender name="fileAppender"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <pattern>${LOG_PATTERN}</pattern>
            <charset>utf8</charset>
        </encoder>
        <file>${LOG_FILE}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.gz</fileNamePattern>
            <maxHistory>7</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>100MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="fileAppender"/>
    </root>

</configuration>

run project,i get the log file: springAppName_IS_UNDEFINED_8081.log

xiaogang-github commented 1 year ago

Have you solved the problem? How to solve, can you provide some ideas

hhh123-sec commented 1 year ago

I also encountered the same problem, but I don't know how to solve it

Jenfong commented 2 weeks ago

it's seem the same issue jasypt:3.0.5 spring boot:2.5.15

logging: config: classpath:logback-${spring.profiles.active}.xml `mvn jasypt:encrypt -Dspring.profiles.active=prod -Djasypt.encryptor.password="test2024" -Djasypt.plugin.path="file:src/main/resources/application-prod.yml

demo\src\main\resources>dir
2024/08/22  17:50             4,668 application-dev.yml
2024/08/22  17:50             4,136 application-prod.yml
2024/08/22  17:50             4,135 application-stage.yml
2024/08/22  17:55             3,060 application.yml
2024/08/22  17:06             3,673 logback-dev.xml
2024/07/24  15:20             3,668 logback-prod.xml
2024/08/22  17:06             3,675 logback-stage.xml

error: class path resource [logback-prod.xml] cannot be resolved to URL because it does not exist

linqihe commented 1 week ago

When I use Spring Boot 2.7.12 and Jasy PT 2.0.0, I also encounter the problem of outputting springAppName_IS_UNDEFINED in the log. When debugging in the local development environment, except EncryptablePropertySourceConferter, the other logs are gray, but when starting the service in the server with java -jar, the original gray logs are not output.