Hi Folks

I hope someone is able to help me.  I  have written a Java application  that 
uses log4j2. I am using the Idea IDE. When I run the application in Idea the 
logging works fine. I have three appenders, one to the console and two to 
files. However, when I package the application into a runnable jar with all its 
dependencies, and then run it from the command line, log4j2 still creates the 
two files but there is no logging - not to the files or the console.

This is my log4j2.properties file:

property.basePath = /home/janne/IdeaProjects/F2_/DATA/outputs/
rootLogger.level = trace
rootLogger.appenderRefs = STDOUT, LOGFILE, TRACEFILE
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.logfile.ref = LOGFILE
rootLogger.appenderRef.tracefile.ref = TRACEFILE

appender.console.name = STDOUT
appender.console.type = Console
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
appender.console.filter.threshold.type = ThresholdFilter
appender.console.filter.threshold.level = info

appender.file1.type = File
appender.file1.name = LOGFILE
appender.file1.fileName = ${basePath}/firm.log
appender.file1.layout.type = PatternLayout
appender.file1.layout.pattern = %msg%n
appender.file1.filter.threshold.type = ThresholdFilter
appender.file1.filter.threshold.level = debug

appender.file2.type = File
appender.file2.name = TRACEFILE
appender.file2.fileName = ${basePath}/TRACE.log
appender.file2.layout.type = PatternLayout
appender.file2.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
appender.file2.filter.threshold.type = ThresholdFilter
appender.file2.filter.threshold.level = trace


I usually create the jar with Maven, but I also tried using Idea to create it 
as an artefact. It makes no difference.

This is my pom file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0";
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
    <modelVersion>4.0.0</modelVersion>

    <groupId>uk.ac.ncl.nclwater.firm2.firm2</groupId>
    <artifactId>firm2</artifactId>
    <packaging>jar</packaging>
    <version>0.001</version>
    <build>
        <finalName>${project.name}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>uk.ac.ncl.nclwater.firm2</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- bind to the packaging phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>

            </plugin>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>uk.ac.ncl.nclwater.firm2</mainClass>
                        </manifest>
                    </archive>
                    <finalName>FIRM2</finalName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
        </plugins>
    </build>


    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>

        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.9</version>
        </dependency>
        <dependency>
            <groupId>com.miglayout</groupId>
            <artifactId>miglayout-swing</artifactId>
            <version>5.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.graphstream/gs-algo -->
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-algo</artifactId>
            <version>2.0</version>
        </dependency>
        <!-- 
https://mvnrepository.com/artifact/org.danilopianini/graphstream-gs-algo -->
        <dependency>
            <groupId>org.danilopianini</groupId>
            <artifactId>graphstream-gs-algo</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.danilopianini</groupId>
            <artifactId>graphstream-gs-core</artifactId>
            <version>2.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.danilopianini</groupId>
            <artifactId>graphstream-gs-ui-swing</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.16.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc -->
        <dependency>
            <groupId>org.xerial</groupId>
            <artifactId>sqlite-jdbc</artifactId>
            <version>3.46.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>2.24.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.24.0</version>
        </dependency>
    </dependencies>

</project>




Reply via email to