log4j2 not logging when packaged in a jar

Jannetta Steyn <[email protected]> Sat, 5 Oct 2024 21:06:49 +0000
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <92055964623346dfad3e1451d90464a1LO2P302MB03439E3723CA5314A6544C03C2732@LO2P302MB0343.GBRP302.PROD.OUTLOOK.COM>
--_000_92055964623346dfad3e1451d90464a1LO2P302MB03439E3723CA53_
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi Folks

I hope someone is able to help me.  I  have written a Java application  tha=
t 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 c=
reates the two files but there is no logging - not to the files or the cons=
ole.

This is my log4j2.properties file:

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

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

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

appender.file2.type =3D File
appender.file2.name =3D TRACEFILE
appender.file2.fileName =3D ${basePath}/TRACE.log
appender.file2.layout.type =3D PatternLayout
appender.file2.layout.pattern =3D %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1} - %m%n
appender.file2.filter.threshold.type =3D ThresholdFilter
appender.file2.filter.threshold.level =3D 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=3D"1.0" encoding=3D"UTF-8"?>
<project xmlns=3D"http://maven.apache.org/POM/4.0.0"
         xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation=3D"http://maven.apache.org/POM/4.0.0 http://mav=
en.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/graphstre=
am-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>





--_000_92055964623346dfad3e1451d90464a1LO2P302MB03439E3723CA53_--