-2

I am using Spring, Logback and maven. I would like to put all my settings to properties which will be outside jar that I build with maven. So I moved all setting from Logback.xml. Now it looks like:

<configuration>

    <property resource="application.properties" />

    <timestamp key="byDate" datePattern="yyyyMMdd"/>

    <!-- Send messages to System.out - CONSOLE -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
        </encoder>
        <withJansi>true</withJansi>
    </appender>

    <!-- Send messages to a file -->
    <appender name="FILE" class="ch.qos.logback.core.FileAppender">
        <file>${logging.path}/${spring.application.name}-${byDate}.log</file>
        <append>true</append>
        <!-- encoders are assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{5} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="${logging.level}">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="FILE" />
    </root>

</configuration>

My application.properties file is:

#Spring settings
spring.application.name=MyApp
server.port=8087

# Logging settings
logging.level=INFO
logging.path=/Users/...some path.../logs/

I put this to bean:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="file:application.properties"/>
    </bean>

And excluded application.properties from maven build with plugin:

<plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <copy todir="target" overwrite="true">
                                    <fileset dir="src/main/resources/">
                                        <include name="*.properties"/>
                                    </fileset>
                                </copy>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

But it isn't work for me. Log file name loose datePattern and nothing I changed in property file is not changing. What is wrong? Please.

UPDATE: There is no errors. Everything works fine. And I can change all settings with run in IDE. So I believe that I do something wrong with maven build.

user3742622
  • 1,037
  • 3
  • 22
  • 40
  • In my case, there is no errors. Everything works fine. And I can change all settings with run in IDE. So I believe that I do something wrong with maven build. – user3742622 Jun 27 '15 at 20:34
  • 1
    "_Everything works fine._" So what's your question? – Nic Jun 27 '15 at 20:43
  • "Everything works fine." - in IDE, only in IDE. I have my problems after I build jar with Maven. – user3742622 Jun 27 '15 at 21:00

1 Answers1

1

In your maven antrun plugin, you are doing a copy of application.properties, not a move, so there is alway a copy of application.properties in your jar! Try using maven standard jar plugin configuration to exclude your property file:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <version>2.6</version>
    <configuration>
      <excludes>
        <exclude>path/to/application.properties</exclude>
      </excludes>
    </configuration>
  </plugin>

And make sure that the excluded file is in your app classpath when executing

  • Thanks for your help! All this is difficult for newbie. I've just tried. The result is: logging.path is reading from my file, but I lost date in the log file's name (now it just spring.log) and logging.level doesn't work too. – user3742622 Jun 28 '15 at 09:49