Search code examples
javajarresourceslogbacklaunch4j

lost Logback configuration in launch4j


I ran into a strange problem to me, and I ask your help. Judging by the fact that my search has not given definite results, I just forgot something obvious, but I can not understand what it was.

So, there is a program on Java. Logback configuration (logback.xml in "resources" path):

<configuration>    
    <property resource=".\app\LOG.properties" /> 
    <appender name="STDOUT-BLACK"  
       ...
    </appender>
    <appender name="STDOUT-RED" class="ch.qos.logback.core.ConsoleAppender">
       ...      
    </appender>

    <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">   
        <file>${destination}</file>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <level>INFO</level>
        </filter>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${destination}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">                
            <maxFileSize>2MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>7</maxHistory>
            <totalSizeCap>10MB</totalSizeCap>           
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>        
        <encoder>
            <Pattern>%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n</Pattern>
        </encoder>
  </appender>

  <logger name="org.hibernate.type" level="TRACE" />
  <logger name="org.hibernate.SQL" level="DEBUG" />

  <root level="DEBUG">
    <appender-ref ref="STDOUT-BLACK" />
    <appender-ref ref="STDOUT-RED" />
    <appender-ref ref="FILE" />
  </root>
</configuration>

the additional configuration file is (resources\app\LOG.properties):

fileName=LOGFile.log
#destination=${DEV_HOME:-.\\logs}\\${fileName}
destination=C:\\Temp\\${fileName}

And it works fine in NetBeans.

BUT whean I make an Exe for Windows from this (using Gradle shadow and launch4j plugins) properties file seems to be ignorred. Each time I start my exe I have a file (in the same folder, as exe file) "destination_IS_UNDEFINED", where all my logs are stored correct. If I "hardcode" the file name in "logback.xml" all works as expected, but why he can't read "properties"? They are in Jar, from which Launch4j creates an exe, and I got there also some other properties Files, which program read correct.

<property resource=".\app\LOG.properties" /> 

The error is somewhere here... I tried different "/" as separator, but it haven't helped anyhow. What am I doung wrong?

And actually I have one more question: which is the right way to store properties otside Jar file? I mean it would be nice to have a folder, where all my properties are (just as it is in IDE), and user may change them without recompile the project (so the "*.exe" Program must "read" it from this folder instead of Jar). I'm sure it's made 1000 times by everione. Is there any sample or explanation about it anywhere (maybe I'm just looking for the wrong, because I know English is not enough, so I can not find what I need).

Thanks a lot!

EDITED: So, the first "Problem" is solved, and it was really silly - there was just an extra point. Does anyone have any advice about the second question?


Solution

  • I would like to check the following line in the XML

    <property resource=".\app\LOG.properties" />
    

    Are you sure about the location of app folder?