Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile
Asked Answered
A

6

8

I want my application to output logs to a the logfile in a user's home directory. Therefore I have configured the log4j2.xml file as below:

<Configuration>
<Properties>
    <Property name="logfolder">/${sys:user.home}/xx/log/ff</Property>
</Properties>
<Appenders>
    <RollingFile name="user_file" append="true" fileName="${logfolder}/logxyz.csv" filePattern="${logfolder}/old/$${date:yyyy-MM}/service-%d{MM-dd-yyyy}-%i.csv.gz">
        <CsvParameterLayout format="Default" nullString="" charset="UTF-8"/> 
        <Policies>

I can see the logs in the specified folder, however, some errors are displayed in the console:

ERROR Could not create plugin of type class org.apache.logging.log4j.core.appender.RollingFileAppender for element RollingFile : java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:\Users\xx/yy/log/abc/def.csv java.nio.file.InvalidPathException: Illegal char <:> at index 2: /C:\Users\xx/yy/log/abc/def.csv
at sun.nio.fs.WindowsPathParser.normalize(WindowsPathParser.java:182)

The error seems to be related to parsing the windows files system, but I've got no idea how to go about this. Will appreciate any directions. I am developing on Windows 10, but the application logging should be cross-platform.

Archegonium answered 10/3, 2018 at 9:42 Comment(0)
W
3

In my case, the user I ran the program had not the permission to create the log directory and write into it. So, I just changed the owner of the working directory and restarted the program without any problem.

sudo chown -R runner-user:runner-user working-directory/*
Waive answered 16/3, 2020 at 8:30 Comment(0)
T
1

I do something similar with an environment variable. user.home should be a fully qualified path without any prefix needed. Example: user.home == C:\Users\dumbo

Try removing the first slash from your log folder.

From: <Property name="logfolder">/${sys:user.home}/xx/log/ff</Property>

To: <Property name="logfolder">${sys:user.home}/xx/log/ff</Property>

Tanah answered 14/2, 2019 at 21:54 Comment(0)
O
1

add full path to the directory according to operating system

if linux:

/opt/tomcat/apache-tomcat-9.0.27/webapps/My_Logs

if Windows: (Not Need generally append automatically )

   C:\Program Files\Apache Software Foundation\Tomcat 9.0\My_Logs
Overword answered 7/11, 2019 at 17:33 Comment(0)
A
0

In my case it was related with administrator permissions , so I just executed the Integration Studio as Administrator and the run was success

Alkane answered 8/6, 2022 at 14:40 Comment(0)
C
0

This error typically occurs when the running program either:

  • A) does not have the permission to create the log directory and write into it or
  • B) the log directory set for the program is invalid.

I'd recommend first verifying where the log directory is pointing to (is it something explicit like a C: or D: drive or trying to point to a remote location?). Once you've validated the log directory, then validate that the program has permissions to write to said directory.

Try validating your log4j2.xml file or log4js config and ensuring the path is write accessible.

Happy coding!

Chun answered 13/7, 2023 at 19:56 Comment(0)
E
0

In my case I got this error when my maven dependency pulled log4j3 beta:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>[2.15.0,)</version>
    <scope>compile</scope>
</dependency>

Checking with

mvn dependency:tree

Showed it was using log4j3 beta.

I changed the dependency to:

<dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.20.0</version>
    <scope>compile</scope>
</dependency>

and it worked again.

Eddins answered 3/1 at 17:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.