Log4j2 logger not working for jenkins plugin

145 views
Skip to first unread message

varun...@gmail.com

unread,
Oct 21, 2020, 10:04:18 AM10/21/20
to Jenkins Developers
Hi,

I am trying to use Log4j2 for looging in jenkins plugin , as it includes some jar file,
which uses log4j2 for logging.
when I independently run jar, logging is working fine.
But when I include jar in jenkins Plugin, it is not logging any log.
What may be issue, i have also kept log4j2 properties file in resources folder, still not able
to log. can anyOne please help me here?

Thanks,
Varun

Matt Sicker

unread,
Oct 21, 2020, 10:22:23 AM10/21/20
to jenkin...@googlegroups.com
Are you using the audit-log plugin, too? That specifies a log4j2
config which probably overrides anything you're using.
> --
> You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/97b5066e-c2c3-48a4-b316-12152bf390cen%40googlegroups.com.



--
Matt Sicker
Senior Software Engineer, CloudBees

varun...@gmail.com

unread,
Oct 21, 2020, 10:48:31 AM10/21/20
to Jenkins Developers
Hi Matt,

Thanks for reply.
I am running mvn hpi:run for running jenkins locally. so it includes only jenkins standard plugin. so no audit-log plugin tool , i am using.
It creates log file on local machine but no log is written.
 but It successfully logs on jenkins system log.
I have also included an appender by providing TaskListener.getLogger() printStream as we can add output stream as appender.
to log on jenkins console but it does not work

Thanks,
Varun

Matt Sicker

unread,
Oct 21, 2020, 11:44:49 AM10/21/20
to jenkin...@googlegroups.com
Do you also have log4j-core in your plugin? What other dependencies do you have?
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/e67c56db-a8d8-4163-8970-dea7bf1bc59en%40googlegroups.com.

varun...@gmail.com

unread,
Oct 21, 2020, 12:12:11 PM10/21/20
to Jenkins Developers
Hi,

Below are details of maven dependency  which i have included
    <dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>


Thanks,
Varun

varun...@gmail.com

unread,
Oct 21, 2020, 12:19:09 PM10/21/20
to Jenkins Developers
Hi Matt,
all dependencies are as below:

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>job-dsl</artifactId>
<version>1.41</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>structs</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-net</groupId>
<artifactId>commons-net</artifactId>
<version>3.6</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.1</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
<version>RELEASE</version>
<scope>compile</scope>

</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.6.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.3</version>
</dependency>


</dependencies>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>https://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
</project>

Tim Jacomb

unread,
Oct 21, 2020, 12:39:38 PM10/21/20
to jenkin...@googlegroups.com
Can you post a link to the code? Or at least a new plugin generated off of archetypes where it doesn’t work for you?

Thanks
Tim

Matt Sicker

unread,
Oct 21, 2020, 1:11:48 PM10/21/20
to jenkin...@googlegroups.com
Chances are there's some slf4j dependency interfering. Jenkins uses a
bridge for that into the java.util.logging API from what I've seen.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CAH-3BidJZh6NrUJYqYuvGd3fa9Tn0c1qt8xAw1AGabSgz4wo5w%40mail.gmail.com.

varun...@gmail.com

unread,
Oct 21, 2020, 1:20:31 PM10/21/20
to Jenkins Developers
Hi,

@matt should I remove sl4j and only use log4j2 and try again?

Thanks,
Varun

varun...@gmail.com

unread,
Oct 21, 2020, 1:38:05 PM10/21/20
to Jenkins Developers
Hi Matt,

Thanks , after removing slf4j, logging starts. 

Thanks,
Varun

Reply all
Reply to author
Forward
0 new messages