How do I override a Maven Plugin's log4j Configuration? - log4j

I'm using the Cargo Maven plugin to deploy a WAR to a remote server, and I'm having problems. I'll probably create a second question for that problem, but this one is about overriding a Maven plugin's log4j configuration. Cargo uses JBoss' client libraries to ship stuff to JBoss servers (which I'm trying to do.) The JBoss library uses log4j. Cargo doesn't set up any sort of mapping layer that I know of.
So, essentially, log messages are occurring in the dependent library of a Maven plugin. I tried setting -Dlog4j.debug and got this information:
log4j: Trying to find [log4j.xml] using ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]] class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]].
log4j: Using URL [jar:file:/C:/Users/username/.m2/repository/org/jboss/jbossts/jbossjts/4.13.1.Final/jbossjts-4.13.1.Final.jar!/log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL jar:file:/C:/Users/username/.m2/repository/org/jboss/jbossts/jbossjts/4.13.1.Final/jbossjts-4.13.1.Final.jar!/log4j.properties
log4j: Could not find root logger information. Is this OK?
log4j: Parsing for [com.arjuna] with value=[INFO, default, stdout].
log4j: Level token is [INFO].
log4j: Category com.arjuna set to INFO
log4j: Parsing appender named "default".
log4j: Parsing layout options for "default".
log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c - %m%n].
log4j: End of parsing for "default".
log4j: Setting property [maxBackupIndex] to [2].
log4j: Setting property [file] to [transaction.log].
log4j: Setting property [maxFileSize] to [500KB].
log4j: setFile called: transaction.log, true
log4j: setFile ended
log4j: Parsed "default" options.
log4j: Parsing appender named "stdout".
log4j: Parsing layout options for "stdout".
log4j: Setting property [conversionPattern] to [%d [%t] %-5p %c - %m%n].
log4j: End of parsing for "stdout".
log4j: Setting property [threshold] to [WARN].
log4j: Parsed "stdout" options.
log4j: Handling log4j.additivity.com.arjuna=[null]
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.
Then I tried setting -Dlog4j.configuration=mylog4j.properties but got this:
log4j: Trying to find [mylog4j.properties] using context classloader ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]].
log4j: Trying to find [mylog4j.properties] using ClassRealm[plugin>org.codehaus.cargo:cargo-maven2-plugin:1.0.5, parent: ClassRealm[maven.api, parent: null]] class loader.
log4j: Trying to find [mylog4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [mylog4j.properties].
log4j:WARN No appenders could be found for logger (org.jnp.interfaces.TimedSocketFactory).
log4j:WARN Please initialize the log4j system properly.
It would appear that the log4j configuration file needs to be in the Maven plugin's classpath, but I don't know how to include random files there, only dependencies. I really want to set this information so that I can get debug information from the JBoss libraries in order to troubleshoot my problem.

With log4j.configuration you will set a resource string. Have a look at the log4j default initialization process and the examples.
If you use a syntax like this
-Dlog4j.configuration=mylog4j.properties
the file is expected in the classpath. But you can also use a syntax like this
-Dlog4j.configuration=file:/<path>/mylog4j.properties
to specify a fully qualified file location.

Related

Lucee log4j and org.owasp.esapi.devteam error

I am trying to log several variables in lucee 5.2.9 (jdk 1.8) via cfdump var= "#variable#" output="console", but unfortunately I get the following error stack in log file. Lucee has been installed via commandbox (start command) as embedded server.
[ERROR] runwar.context: log4j:WARN No appenders could be found for logger (org.apache.http.impl.conn.PoolingHttpClientConnectionManager).
[ERROR] runwar.context: log4j:WARN Please initialize the log4j system properly.
[ERROR] runwar.context: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[ERROR] runwar.context: System property [org.owasp.esapi.opsteam] is not set
[ERROR] runwar.context: System property [org.owasp.esapi.devteam] is not set
Any idea what could I do?

log4j-1.2-api bridge ClassNotFoundException:org.apache.log4j.RollingFileAppender

I try to migrate my application from log4j to log4j2. According to official manual I have org.apache.logging.log4j:log4j-1.2-api:2.17.1, org.apache.logging.log4j:log4j-api:2.17.1 and org.apache.logging.log4j:log4j-core:2.17.1 in my maven dependencies. I use log4j.properties file so I enabled compatibility mode (-Dlog4j1.compatibility=true). RollingFileAppender is configured in my log4j.properties file:
log4j.appender.A2=org.apache.log4j.RollingFileAppender
I get following error:
2022-02-16 21:04:20,396 main ERROR Unable to create Appender org.apache.log4j.RollingFileAppender due to ClassNotFoundException:org.apache.log4j.RollingFileAppender
According to official manual, RollingFileAppender is a supported component. I had log4j:log4j:1.2.17 dependency before migration to log4j2 and it contains org.apache.log4j.RollingFileAppender class. Unfortunately none of the log4j-1.2-api,log4j-api and log4j-core libraries contain this class. I do not understand why RollingFileAppender is not present in log4j bridge if manual says that RollingFileAppender is supported component. I have found similar question but without a satisfactory answer. How to migrate RollingFileAppender?
UPDATE
Here is my log4j.properties file:
log4j.rootCategory=INFO, A1, A2
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A2=org.apache.log4j.RollingFileAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d%m%M %n
log4j.appender.A2.file=C:/projects/test/Log.log
#log4j.appender.A2.layout=org.apache.log4j.PatternLayout
#log4j.appender.A2.layout.ConversionPattern=[%d{dd.MM HH.mm.ss.SSS} %-5p %-20c{1}] : %m%n
#log4j.appender.A2.MaxFileSize=10000KB
#log4j.appender.A2.MaxBackupIndex=3
I added -Dlog4j2.debug=true. There are tons of logs. I chose interesting logs:
TRACE StatusLogger Trying to find [log4j.properties] using context class loader jdk.internal.loader.ClassLoaders$AppClassLoader#2437c6dc.
DEBUG StatusLogger Not in a ServletContext environment, thus not loading WebLookup plugin.
DEBUG StatusLogger PluginManager 'Log4j Builder' found 18 plugins
DEBUG StatusLogger Parsing for [root] with value=[INFO, A1, A2].
DEBUG StatusLogger Level token is [INFO].
DEBUG StatusLogger Logger root level set to INFO
DEBUG StatusLogger Parsing appender named "A1".
DEBUG StatusLogger PluginManager 'Converter' found 47 plugins
DEBUG StatusLogger Starting OutputStreamManager SYSTEM_OUT.false.false
DEBUG StatusLogger Adding appender named [A1] to loggerConfig [].
DEBUG StatusLogger Parsing appender named "A2".
WARN StatusLogger Unable to create File Appender, no file name provided
ERROR StatusLogger Unable to create Appender org.apache.log4j.RollingFileAppender due to ClassNotFoundException:org.apache.log4j.RollingFileAppender
DEBUG StatusLogger Appender named [A2] not found.
DEBUG StatusLogger Finished configuring.
The reason configuration fails is explained by the following message:
WARN StatusLogger Unable to create File Appender, no file name provided
This is caused by a compatibility problem between the Log4j 1.x bridge and the original Log4j 1.x: property names must start with a capital letter (cf. LOG4J2-3316). This will be solved in the next release.
Until then, you can use:
log4j.appender.A2.File=C:/projects/test/Log.log
(with a capital F).

How to config log4j on yarn?

Background: The yarn is installed by cloudera manager. I use yarn to run my xxx.jar.
I use yarn to run my xxx.jar. As we know, syslog file will contain the log4j related logs. stdout file will contain some output like System.out.println(...). Blow is the some out put in stdout file:
===============================================================
LogType:stdout
LogLastModifiedTime:Sun Oct 11 21:19:27 +0800 2020
LogLength:109238
LogContents:
log4j: Trying to find [container-log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader#5c647e05.
log4j: Using URL [jar:file:/usr/lib/hadoop-yarn/hadoop-yarn-server-nodemanager-3.0.0-cdh6.3.2.jar!/container-log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL jar:file:/usr/lib/hadoop-yarn/hadoop-yarn-server-nodemanager-3.0.0-cdh6.3.2.jar!/container-log4j.properties
log4j: Hierarchy threshold set to [ALL].
log4j: Parsing for [root] with value=[INFO,CLA, EventCounter].
log4j: Level token is [INFO].
log4j: Category root set to INFO
log4j: Parsing appender named "CLA".
log4j: Parsing layout options for "CLA".
log4j: Setting property [conversionPattern] to [%d{ISO8601} %p [%t] %c: %m%n].
log4j: End of parsing for "CLA".
log4j: Setting property [containerLogFile] to [syslog].
log4j: Setting property [totalLogFileSize] to [1048576].
log4j: Setting property [containerLogDir] to [/yarn/container-logs/application_1602420941906_0002/container_1602420941906_0002_01_000001].
log4j: setFile called: /yarn/container-logs/application_1602420941906_0002/container_1602420941906_0002_01_000001/syslog, true
log4j: setFile ended
log4j: Parsed "CLA" options.
log4j: Parsing appender named "EventCounter".
log4j: Parsed "EventCounter" options.
log4j: Parsing for [org.apache.hadoop.mapreduce.task.reduce] with value=[INFO,CLA].
log4j: Level token is [INFO].
log4j: Category org.apache.hadoop.mapreduce.task.reduce set to INFO
log4j: Parsing appender named "CLA".
log4j: Appender "CLA" was already parsed.
log4j: Handling log4j.additivity.org.apache.hadoop.mapreduce.task.reduce=[false]
log4j: Setting additivity for "org.apache.hadoop.mapreduce.task.reduce" to false
log4j: Parsing for [org.apache.hadoop.mapred.Merger] with value=[INFO,CLA].
log4j: Level token is [INFO].
log4j: Category org.apache.hadoop.mapred.Merger set to INFO
log4j: Parsing appender named "CLA".
log4j: Appender "CLA" was already parsed.
log4j: Handling log4j.additivity.org.apache.hadoop.mapred.Merger=[false]
log4j: Setting additivity for "org.apache.hadoop.mapred.Merger" to false
log4j: Finished configuring.
Launcher AM configuration loaded
From the log, we can see the log4j properties is from jar:file:/usr/lib/hadoop-yarn/hadoop-yarn-server-nodemanager-3.0.0-cdh6.3.2.jar!/container-log4j.properties. I alse download the hadoop-yarn-server-nodemanager-3.0.0-cdh6.3.2.jar. the content of container-log4j.properties is:
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. See accompanying LICENSE file.
#
# Define some default values that can be overridden by system properties
hadoop.root.logger=DEBUG,CLA
yarn.app.mapreduce.shuffle.logger=${hadoop.root.logger}
# Define the root logger to the system property "hadoop.root.logger".
log4j.rootLogger=${hadoop.root.logger}, EventCounter
# Logging Threshold
log4j.threshold=ALL
#
# ContainerLog Appender
#
#Default values
yarn.app.container.log.dir=null
yarn.app.container.log.filesize=100
log4j.appender.CLA=org.apache.hadoop.yarn.ContainerLogAppender
log4j.appender.CLA.containerLogDir=${yarn.app.container.log.dir}
log4j.appender.CLA.containerLogFile=${hadoop.root.logfile}
log4j.appender.CLA.totalLogFileSize=${yarn.app.container.log.filesize}
log4j.appender.CLA.layout=org.apache.log4j.PatternLayout
log4j.appender.CLA.layout.ConversionPattern=%d{ISO8601} %p [%t] %c: %m%n
log4j.appender.CRLA=org.apache.hadoop.yarn.ContainerRollingLogAppender
log4j.appender.CRLA.containerLogDir=${yarn.app.container.log.dir}
log4j.appender.CRLA.containerLogFile=${hadoop.root.logfile}
log4j.appender.CRLA.maximumFileSize=${yarn.app.container.log.filesize}
log4j.appender.CRLA.maxBackupIndex=${yarn.app.container.log.backups}
log4j.appender.CRLA.layout=org.apache.log4j.PatternLayout
log4j.appender.CRLA.layout.ConversionPattern=%d{ISO8601} %p [%t] %c: %m%n
log4j.appender.shuffleCLA=org.apache.hadoop.yarn.ContainerLogAppender
log4j.appender.shuffleCLA.containerLogDir=${yarn.app.container.log.dir}
log4j.appender.shuffleCLA.containerLogFile=${yarn.app.mapreduce.shuffle.logfile}
log4j.appender.shuffleCLA.totalLogFileSize=${yarn.app.mapreduce.shuffle.log.filesize}
log4j.appender.shuffleCLA.layout=org.apache.log4j.PatternLayout
log4j.appender.shuffleCLA.layout.ConversionPattern=%d{ISO8601} %p [%t] %c: %m%n
log4j.appender.shuffleCRLA=org.apache.hadoop.yarn.ContainerRollingLogAppender
log4j.appender.shuffleCRLA.containerLogDir=${yarn.app.container.log.dir}
log4j.appender.shuffleCRLA.containerLogFile=${yarn.app.mapreduce.shuffle.logfile}
log4j.appender.shuffleCRLA.maximumFileSize=${yarn.app.mapreduce.shuffle.log.filesize}
log4j.appender.shuffleCRLA.maxBackupIndex=${yarn.app.mapreduce.shuffle.log.backups}
log4j.appender.shuffleCRLA.layout=org.apache.log4j.PatternLayout
log4j.appender.shuffleCRLA.layout.ConversionPattern=%d{ISO8601} %p [%t] %c: %m%n
################################################################################
# Shuffle Logger
#
log4j.logger.org.apache.hadoop.mapreduce.task.reduce=${yarn.app.mapreduce.shuffle.logger}
log4j.additivity.org.apache.hadoop.mapreduce.task.reduce=false
# Merger is used for both map-side and reduce-side spill merging. On the map
# side yarn.app.mapreduce.shuffle.logger == hadoop.root.logger
#
log4j.logger.org.apache.hadoop.mapred.Merger=${yarn.app.mapreduce.shuffle.logger}
log4j.additivity.org.apache.hadoop.mapred.Merger=false
#
# Event Counter Appender
# Sends counts of logging messages at different severity levels to Hadoop Metrics.
#
log4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCounter
So, i think the log4j related log will be saved in syslog file. But after run my xxx.jar in yarn, there is nothing in syslog, my xxx.jar also contains some code like: System.out.println("my demo");. And i can find the output "my demo" in stdout after run my xxx.jar.
So my question is why the log4j related output cann't been printed out? Is there any other configuration needed?
Got exactly same issue. (I use EMR-5.33, Oozie 5.2.0)
The logs are written to syslog if you set 0 to this property log4j.appender.CLA.totalLogFileSize
It gets the value from yarn.app.container.log.filesize config.
log4j.appender.CLA.totalLogFileSize=${yarn.app.container.log.filesize}
There is an Oozie ticket for that: https://issues.apache.org/jira/browse/OOZIE-3600

TIBCO MDM 9 : log4j:WARN No appenders could be found for logger (RulebaseCustomFunction)

Getting below error while I am trying to print MqLog to elink.log via RulebaseCustomFunction (MDM 9)\
ERROR [stderr] (TIBCO EMS Session Dispatcher (895)) log4j:WARN No appenders could be found for logger (RulebaseCustomFunction).
ERROR [stderr] (TIBCO EMS Session Dispatcher (895)) log4j:WARN Please initialize the log4j system properly.
How to Configure in order to avoid above error?
Can somebody help me, please?
Default log4j configuration provided out-of-box does not have appender defined for RulebaseCustomFunction. However, you can always add new appender to ConfigValues.xml
Try adding below in "Logging" category-
<ConfValue description="The debugging logging level CustomRulebaseFunction" name="Logging Level for CustomRulebaseFunction" propname="log4j.logger.RulebaseCustomFunction" sinceVersion="8.0" visibility="All" isHotDeployable="true" isHidden="false">
<ConfString default="DEBUG,elink,error" value="DEBUG,elink,error"/>
</ConfValue>

Runnig Ex-crawler

Hi i am runnig the jar of this open source Ex-Crawler
But i always receive this error :
og4j:WARN No appenders could be found for logger (eu.medsea.mimeutil.TextMimeDetector).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info
The application you're running uses log4j to produce log files. And log4j needs a configuration file, usually named log4j.properties, to be available in the application's class path, in order to start properly.
This is sample of default configuration you might start with:
log4j.rootLogger=WARN, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.conversionPattern=%5p [%t] (%F:%L) - %m%n

Resources