how to set classpath to logger - java

i work with log4j and now that i want to use it i get this:
log4j:WARN No appenders could be found for logger (xmlModul.XmlLoader).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
but the website didnt help me and i asked this some time ago but i simply cant figure out how and where to set the class path.
but now that the deadline draws near i'm frightened that i cant finish it.
I really need a step-by-step solution.
thank you for your help.
Edit:
i know that the file has to be in the directory but no matter where i put it it wont find the log4j.properties file

Related

android studio 2.0 showing log4j Warning when launch in terminal

I was kind curious about the warning when I start android studio 2.0 and always got this message in my terminal:
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
I have visited the suggested site and from what I understand the configuration files log4j.properties and log4j.xml are missing so I tried to find the file in the root directory and I could not found them this is the screenshot :
My Questions are :
How to resolve this issue so I will not see the warning message again?
Could somebody explain what is log4j for in android studio?
any help and useful information would be appreciated thanks.
it's no critical error. Log4j is a logging framework to log output. If you don't have a configuration file, nothing is logged. You can add them manually if you want.

Setting configuration file with Log4j using slf4j-log4j12

I know there is several answers for how to set the file. Non have worked with me.
I'm trying to unifying several conf files for that I need to set the conf of log4j provided in slf4j-log4j12 into the configuration file provided as parameter of the program. Till now I tried by setting as parameter of the jvm like:
java '-Dlog4j.configuration=conf.cfg' -jar my.jar
I'm getting back:
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
log4j:ERROR Could not parse file [].
Setting programatically by:
System.setProperty("log4j.configuration",(new File( Configurator.getDefaultConfig().getString(Const.LoggingDefaultLoggingFile))).toURL().toString());
and
System.setProperty("log4j.configurationFile",(new File( Configurator.getDefaultConfig().getString(Const.LoggingDefaultLoggingFile))).toURL().toString());
Same result.
I tried using DOMConfigurator but is for xml I'm using properties so no success.
I was searching how to reload the log4j but the give complex solution for making subscription for monitoring change and constant loading of changes.
I just want programatically change the configuration file once.
Till now, I was able to set the file just if I put it directly into the jar. But this by using a separated file with the default name.
Is there a way of loading the file directly int the Log4j (no shity system properties)? o there is a simple way of doing this better?
log4j looking for log4j.properties under WEB-INF\classes
PropertyConfigurator class,
example of usage:
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
// ...
public static final Logger log=Logger.getLogger(App.class);
// ...
PropertyConfigurator.configure("log4j.properties");

hadoop container stdout is always empty

Why is stdout file of a job container in hadoop is always of size 0.
On java
import org.apache.log4j.Logger;
static final Logger MAPLOGGER= Logger.getLogger(MyMap.class.getName());
MAPLOGGER.warn("key is :"+key);
after running jar, 3 files are generated
stderr, stdout,syslog
stderr contains
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.impl.MetricsSystemImpl).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
where exactly MAPLOGGER.warn("key is :"+key); writes the log?.
It doesn't write it anywhere right now, because you have not set up log4j.
From the link in the WARN message:
"Why do I see a warning about "No appenders found for logger" and "Please configure log4j properly"?
This occurs when the default configuration files log4j.properties and log4j.xml can not be found and the application performs no explicit configuration. log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system. Knowing the appropriate location to place log4j.properties or log4j.xml requires understanding the search strategy of the class loader in use. log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments."
So you need to set up the log4j engine, and give it to Java overall, or explicitly declare their location in the application.

How to handle log4j no appenders error

Whenever I debug my code in Netbeans this appears:
log4j:WARN No appenders could be found for logger (org.apache.pdfbox.pdfparser.PDFObjectStreamParser).
log4j:WARN Please initialize the log4j system properly.
Why is this? Is this important?
Why is this?
The reason why you see this message is that your log4j configuration file(i.e. log4j.xml or log4j.properties) is NOT found in the classpath. Placing the log4j configuration file in the applications classpath should solve the issue.
is this important?
Depends on requirement, if you want messages logged to a file with defined levels, then yes you need to fix this warning. Otherwise you may ignore.
For setting Log4j in runtime, do this:
java -Dlog4j.configuration=file:///D:/crawler4j-3.5/log4j.properties -jar newCrawlerV0.1.jar

Is there a way not to print the log4j warn messages?

I get the following:
log4j:WARN No appenders could be found for logger (org.test.Books).
log4j:WARN Please initialize the log4j system properly.
I do not want to print these messages, regardless to whether if my log4j configuration is correct or not.
To turn off the warnings try:
Logger.getRootLogger().setLevel(Level.OFF);
And as said in the comment it might be better using the log4j.xml here is a nice link on its format and a few examples too: http://wiki.apache.org/logging-log4j/Log4jXmlFormat
Reference:
How to turn off log4j warnings?

Categories