Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Receiving error when I try to push my parsed Squid message to Zookeeper

avatar
Contributor

I am working on adding a Squid telemetry to an Ambari-managed cluster on AWS. I've parsed and transformed the Squid message, but I am getting the following error message when I attempt to push it to Zookeeper:

[root@ip-10-0-0-90 ~]# /usr/metron/0.2.0BETA/bin/zk_load_configs.sh -i /usr/metron/0.2.0BETA/config/zookeeper -m PUSH -z ec2-xx-xx-xxx-xxx.us-west-2.compute.amazonaws.com:2181

log4j:WARN No appenders could be found for logger (org.apache.curator.framework.imps.CuratorFrameworkImpl).

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 checked the referenced Apache FAQ and found the following answer:

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.
Not quite sure how to resolve this. Any help would be appreciated. Thanks!
1 ACCEPTED SOLUTION

avatar
Expert Contributor

The above answer gives a lot of good detail, but for what you're trying to do, the WARN messages are actually okay. Though, I'll be happy when they're gone.

If you run /usr/metron/0.2.0BETA/bin/zk_load_configs.sh -i /usr/metron/0.2.0BETA/config/zookeeper -m DUMP -z hostname:2181 you should see the changes you PUSHed.

View solution in original post

2 REPLIES 2

avatar
Super Guru

@Rita McKissick

Logging output is written to a target by using an appender. If no appenders are attached to a category nor to any of its ancestors, you will get the following message when trying to log:

log4j:No appenders could be found for category (some.category.name).
log4j:Please initialize the log4j system properly.

Log4j does not have a default logging target. It is the user's responsibility to ensure that all categories can inherit an appender. This can be easily achieved by attaching an appender to the root category.

You can find info on how to configure the root logger (log4j.rootLogger) in the log4j documentation, basically adding something as simple as this at the beginning of the file:

log4j.rootLogger=debug, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=...

This should clear those WARN messages you get on startup (make sure you don't already have an appender named stdout; also be careful of what level you give the root logger, debugwill be very verbose and every library in your app will start writing stuff to the console).

In a nutshell, you're missing the log4j.properties or log4j.xml in your classpath.

You can also bypass this by using

BasicConfigurator.configure();

But beware this will ONLY log to System.out and is not recommended. You should really use one of the files above and write to a log file.

A very simple example of log4j.properties would also be

#Log to Console as STDOUT
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%-5p%c %3x-%m%n
#Log to file FILE
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=logfile.log
log4j.appender.file.DatePattern='.'yyyy-MM-dd
log4j.appender.file.append=true
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}%-5p%c %3x-%m%n

#RootLogger
log4j.rootLogger=INFO, stdout, file

avatar
Expert Contributor

The above answer gives a lot of good detail, but for what you're trying to do, the WARN messages are actually okay. Though, I'll be happy when they're gone.

If you run /usr/metron/0.2.0BETA/bin/zk_load_configs.sh -i /usr/metron/0.2.0BETA/config/zookeeper -m DUMP -z hostname:2181 you should see the changes you PUSHed.