I'm running Mac OS X 10. I just did brew install zookeeper.
Then I created /usr/local/etc/zookeeper/zoo.cfg based on /usr/local/etc/zookeeper/zoo_sample.cfg.
Then zkServer start works just fine.
But, when trying to connect to Zookeeper from Clojure, which uses the Zookeeper Java client, I get this error:
log4j:WARN No appenders could be found for logger (org.apache.zookeeper.ZooKeeper).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
My log4j.properties file:
log4j.rootCategory=WARN, zklog
log4j.appender.zklog = org.apache.log4j.FileAppender
log4j.appender.zklog.File = /usr/local/var/log/zookeeper/zookeeper.log
log4j.appender.zklog.Append = true
log4j.appender.zklog.layout = org.apache.log4j.PatternLayout
log4j.appender.zklog.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} %c{1} [%p] %m%n
So, my questions are:
What is a reasonable log4j configuration for my situation?
What could homebrew do, out of the box, to prevent this warning from happening?
To be clear, there are two log4j.properties files involved. One is created by Homebrew and gets written to /usr/local/etc/zookeeper/log4j.properties. This file is not the cause of the error message above.
The other log4j.properties file is particular to your (my) application. So, to answer part 1 of the question, create a log4j.properties file on the classpath of the Clojure app, such as in the src directory.
log4j.rootLogger=WARN, A1
log4j.logger.user=DEBUG
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p %c: %m%n
log4j.logger.org.apache.zookeeper=WARN
I built this by starting with https://github.com/clojure/tools.logging and adding the last line.
To answer part 2, Homebrew does not and should not have anything to do with how a Clojure application sets up its logging.
Related
I have used log4j to rotate catalina.out .After the first log rotation tomcat started logging to newly created file by log4j not to catalina.out in linux environment.Every thing works fine in windows environment.
Here's my log4j.properties
log4j.rootLogger=ALL, file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.File=${catalina.home}/logs/catalina.out
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[Java] %d{yyyy-MM-dd HH:mm:ss} - %5p - %c{1} : Line No. %L - %m%n
log4j.appender.file.DatePattern='.'yyyy-MM-dd-HH
log4j.appender.FILE.Append=true
Please suggest.
The catalina.out file is actually created by output redirection from the shell when you launch Tomcat using bin/catalina.sh and friends. If you try to rotate that file using log4j, you will clobber that file with your log4j logs. tomcat is still logging to the old catalina.out, which no longer exists.
You should point log4j at a different log file and not rotate catalina.out at all. If you absolutely must rotate catalina.out, use another technique.
If your catalina.out is filling up with System.out.println garbage from applications, read about the swallowOutput option in Tomcat. That will capture System.out and System.err and redirect it to a file instead of dumping it to standard output.
I have a shell script test.sh with following contents :
echo " Running test.sh ..." | log
test_cp=./test/jar/*:./test/lib/*
test_main=com.test.TestApp
java -cp $test_cp $test_main | log
The relative paths used in the above file are correct as far as I understand. In this case, log4j jar is located at ./test/lib/ and the jar containing TestApp (test-app.jar) is located at ./test/jar/.
Now, the current scenario is that log4j.properties is packaged inside test-app.jar and all Java classes are using the log4j logger to create logs. The contents of log4j.properties are as follows :
log4j.rootLogger=ALL, CONSOLE, FILE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d %-5p [%t] %c %M - %n%m%n
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=test-app.log
log4j.appender.FILE.Append=false
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d %-5p [%t] %c %M - %n%m%n
We want to externalize the log4j.properties and move it outside the test-app.jar. For this, I have placed log4j.properties at ./test/properties/ and modified the shell script accordingly as follows :
echo " Running test.sh ..." | log
test_cp=./test/properties/*:./test/jar/*:./test/lib/*
test_main=com.test.TestApp
java -cp $test_cp $test_main | log
But I am getting the following error and no log file is generated, nor any logs get pronted on console.
log4j:WARN No appenders could be found for logger (com.noknok.util.PropertiesLoader).
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 also read somewhere on the Internet that this could be a Java classloader issue, so I have tried changing the sequence of different locations in classpath, placing log4j.properties in the directories that are already included in the classpath, etc.
But I am still getting the same error.
Thanks a lot for the help! Please get back if you need any other info.
Make sure log4j picks the correct log4j.properties file by using -Dlog4.debug
You can specify the config file by -Dlog4j.configuration=/path/to/file
I have created a very simple application, where I am trying to use the Log4J, but my application is not logging any log.
Can anyone please tell me how can I debug the same as my log4j started or not?
I have kept the file in classes folder of WEB-INF/classes
Thanks
following is my log4j.properties
log4j.rootLogger=debug, stdout, ABC
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
log4j.appender.ABC=org.apache.log4j.RollingFileAppender
log4j.appender.ABC.File=D://abc//dams_workflow_application.log
log4j.appender.ABC.MaxFileSize=3000KB
# Keep one backup file
log4j.appender.ABC.MaxBackupIndex=10
log4j.appender.ABC.layout=org.apache.log4j.PatternLayout
log4j.appender.ABC.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
following is the sample line for using log 4j..
Logger log = Logger.getLogger("ABC");
log.info("my message");
If you're writing a web application, you can view the Log4J Default Initialization Under Tomcat. Even it states Tomcat, the same applies in other Containers/Web application servers.
Console will print this if log4j is not started :
log4j:WARN No log4j configuration information found.
log4j:WARN Changed non-configured level from DEBUG to ERROR.
log4j:WARN The log4j system is not properly configured!
You could have a look at Log4j - Looking for a good 'Getting started' tutorial or blog
to get started.
Regards,
Stéphane
Make sure the log4j jar is in the lib directory for your webapp or in the lib directory in tomcat.
Log4j doesn't seem to work properly for me unless i put the log4j properties file in the default package in the webapp's source directory within the project.
All of my log4j properties files typically look similar to the following
# Define a logger called "processLog" using the FileAppender implementation of the
# Log interface
log4j.appender.processLog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.processLog.File.DateFormat='.'yyyy-ww
# Define the output location
log4j.appender.processLog.File=C:/logs/myapp.log
# Define what the output is going to look like for your log
log4j.appender.processLog.layout=org.apache.log4j.PatternLayout
log4j.appender.processLog.layout.ConversionPattern=%d{yyyy-MM-dd hh:mm a} %5p %c{1}: Line#%L - %m%n
# log4j.rootLogger specifies the default logging level and output location.
# The first parameter is the level (debug > info > warn > error > fatal).
log4j.rootLogger=INFO, processLog
That's how I do it anyway. There may be a better way but this one always works for me.
I am using the Java Service Wrapper to create a Windows Service from a Java Program.
Everything works fine, except the wrapper does not log to a file (I'm using log4j). The logging works properly when the project does not run as a service.
This is not a Log4J problem, because I can log to console with success (this gets redirected to the wrapper's log file), but is not what I'm attempting to achieve.
Here's my wrapper's config file:
encoding=UTF-8
#include ../conf/wrapper-license.conf
wrapper.lang.folder=../lang
# Java Configuration.
wrapper.java.command=java
wrapper.java.command.loglevel=INFO
wrapper.logfile.rollmode=NONE
wrapper.java.mainclass=servicewrapper.MainServiceWrapper
wrapper.java.classpath.1=../lib/*.jar
wrapper.java.classpath.2=../lib/classes/*.jar
wrapper.java.library.path.1=../lib
wrapper.java.additional.auto_bits=TRUE
wrapper.app.parameter.1=servicewrapper.MainServiceWrapper
# Logging Configuration
wrapper.console.format=PM
wrapper.logfile=../logs/wrapper.log
# Service Configuration
wrapper.name=myproject
wrapper.check.deadlock=TRUE
wrapper.check.deadlock.interval=10
wrapper.check.deadlock.action=RESTART
wrapper.check.deadlock.output=FULL
wrapper.console.title=myproject
wrapper.ntservice.dependency.1=
wrapper.ntservice.starttype=AUTO_START
wrapper.ntservice.interactive=false
Also here's my Log4J config file:
log4j.rootCategory=INFO, R
log4j.logger.com.dappit.Dapper.parser=ERROR
log4j.logger.org.w3c.tidy=FATAL
log4j.logger.org.hibernate=ERROR
log4j.logger.org.hibernate.type=ERROR
log4j.logger.com.mchange.v2.c3p0=ERROR
log4j.logger.myproject=DEBUG
#------------------------------------------------------------------------------
#
# The following properties configure the console (stdout) appender.
# See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.S = org.apache.log4j.ConsoleAppender
log4j.appender.S.layout = org.apache.log4j.PatternLayout
log4j.appender.S.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] %p %c{1} %m%n
#------------------------------------------------------------------------------
#
# The following properties configure the Daily Rolling File appender.
# See http://logging.apache.org/log4j/docs/api/index.html for details.
#
#------------------------------------------------------------------------------
log4j.appender.R = org.apache.log4j.RollingFileAppender
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.File = myproject.log.txt
log4j.appender.R.Append = true
log4j.appender.R.layout = org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern = %d{yyyy-MM-dd HH:mm:ss} [%t] %p %c{1} %m%n
I was not clear on the problem. To confirm. When you run as a service, log4j output that is directed to the console correctly gets written to the Wrapper's log file? ../logs/wrapper.log Correct?
So the problem is that your log4j output that is supposed to go to myproject.log.txt is not showing up. Is that the problem you are having?
If so then it actually is a log4j side issue as that would be entirely within the JVM.
From your configuration you are trying to write to .¥myproject.log.txt which would be in the same directory as the Wrapper binary. If it was an access problem to the file then I would expect some kind of log4j error in the console, which would then be visible in the wrapper.log file.
To put the log4j file in with the Wrapper's log file you would want to do:
log4j.appender.R.File = ../logs/myproject.log.txt
Please confirm which file you are not able to write to. Also what version of the Wrapper and Windows are you running?
Cheers,
Leif
A possible cause is that you forgot to set -Dlog4j.configuration={path to file} in your wrapper configuration. For example:
wrapper.java.additional.1=-Dlog4j.configuration=/home/logs.log
How do I log from within my web application deployed on Tomcat 6? Where should I expect the logging output to go (internal tomcat log files, or will another logfile be generated)? I see a ton of documentation but am having a hard time finding a direct answer to the above questions. Where should I expect the logging to show up (currently it is log4j is not generating a log file and it is not showing up in my console). I am trying to follow http://www.laliluna.de/articles/log4j-tutorial.html .
### direct log messages to 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{ABSOLUTE} %5p %c{1}:%L - %m%n
### file appender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB
log4j.appender.file.maxBackupIndex=5
log4j.appender.file.File=test.log
log4j.appender.file.threshold=info
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout
In my application I define a log object:
private static org.apache.log4j.Logger log = Logger.getLogger(MyClass.class);
log.error("LOGGING!");
Thanks for the help.
2 things to try:
1: Change test.log to /tmp/test.log so you know exactly where the file is supossed to be.
2: Put your log4j.properties config file in your apache-tomcat-6.0.x/lib directory together with the log4j-1.2.15.jar file. And don't have any log4j files in your webapps/*/WEB-INF/lib
That's the way I am doing it, and its working for me. Here is a usefull snippet from my log4j.properties (Remember to do a mk /tmp/logs if you use this config)
log4j.rootLogger=debug, root
log4j.appender.root=org.apache.log4j.FileAppender
log4j.appender.root.layout = org.apache.log4j.PatternLayout
log4j.appender.root.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.root.file = /tmp/logs/root.log
log4j.appender.root.append = true
log4j.category.mside = DEBUG,msideAppender
log4j.category.javashare = DEBUG,msideAppender
log4j.additivity.mside = false
log4j.additivity.mside.msideAppender = false
log4j.additivity.javashare = false
#Define msideAppender.
log4j.appender.msideAppender = org.apache.log4j.RollingFileAppender
log4j.appender.msideAppender.MaxFileSize=10MB
log4j.appender.msideAppender.MaxBackupIndex=7
log4j.appender.msideAppender.file = /tmp/logs/mside.log
log4j.appender.msideAppender.layout = org.apache.log4j.PatternLayout
log4j.appender.msideAppender.layout.conversionPattern = %d [%t] %-5p %c - %m%n
log4j.appender.msideAppender.append = true
IIRC Tomcat v4/v5 sends standard output to the catalina.out file, so any log4j output using a console appender would go to that file as well. Not sure if this still the case with newer versions of Tomcat, though.
Your log4j configuration will be picked up by log4j if you put it into the classpath of your web application, e.g. in WEB-INF/classes/. Make sure that your log4j.jar is in WEB-INF/lib.
The output of the ConsoleAppender that you defined, which is logging on stdout, will go to ${CATALINA_BASE}/logs/catalina.out, as any Tomcat stdout output.
As to the RollingFileAppender, you should define the correct path. If you want your web application's logs to appear in Tomcat's logs directory, change the file for this appender to:
log4j.appender.file.File=${catalina.base}/logs/test.log
BTW, use the system property -Dlog4j.debug system property. That should tell you where the heck log4j is sending its output.
Also, if your tomcat install is in a *nix system, or if you are running on Windows with cygwin installed, you could use the find command to detect what files get changed right after you send a HTTP request to Tomcat (which you know should produce a logging output)
cd <your tomcat install>
ls -ltr `find . -type f -ls` | tail -10
That should show you the last 10 files that were updated or changed. It won't work if there are files in your app with spaces in their file names, though.
I have tried following way and make sure it works well:
put your own log4j.properties place at a path;
then update your catalina.sh under tomcat, add below similar line:
JAVA_OPTS="-Dlog4j.configuration=file:${yourownlog4jpath}"