aspose file tools*
The moose likes Other Open Source Projects and the fly likes Help Please -log4j:WARN No appenders could be found for logger Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Help Please -log4j:WARN No appenders could be found for logger" Watch "Help Please -log4j:WARN No appenders could be found for logger" New topic
Author

Help Please -log4j:WARN No appenders could be found for logger

sree visu
Ranch Hand

Joined: Jul 05, 2007
Posts: 133

I am a newbie to log4j .Could you please say me on how to write the log4j.properties file.
Since i have not written this file i get a warning that log4j is not initialised properly .

I referred to previous posts in this topic but i couldn't understand
Could you please explain about how to configure the log4j.properties file.
The exact message is given below.

log4j:WARN No appenders could be found for logger (org.apache.struts.util.PropertyMessageResources).
log4j:WARN Please initialize the log4j system properly.


Here is what i did.I configured a initialization servlet as given below and configured it to load on startup.
I would like to write my logs in a file named error.log inside a WEB-INF directory.I have written it in my initialization servlet.

I Wish to get all my logs into the file mentioned below.That is (/WEB-INF/logs/error.log) when i open the file i only have the messages relating to org.apache.commmons.beanutils

here is the sample that i obtained





Also could you please say me how to use it in the java files that i write.I tried the following


but this did not give a log in that particular log file




Thank you for your time


Regards<br />Sree Visu<br />SCJP 5.0, SCWCD 5.0, SCJD(Preparing B&S 2.2.2)
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Usually this occurs when you do not have log4j.properties in your CLASSPATH.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
sree visu
Ranch Hand

Joined: Jul 05, 2007
Posts: 133
Yes,I am a newbie to log4j and hence it would be of great help to me if you could illustrate on how to configure it.I tried it on hard but i always get a warning message stating that Log4j was not initialised properly although the first message vanished.Further i could not write the logs in the file mentioned in my previous post.

Please help me
Thank you so much for patient reading
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

OK, whereabouts is your log4j.properties file kept in your WAR (or expanded WAR)? It should be in the CLASSPATH for the WAR so under WEB-INF/classes might be a good start....
sree visu
Ranch Hand

Joined: Jul 05, 2007
Posts: 133
Yes it was under web-inf/classes.But i am in doubt about what to configure to configure.I did the following


I got the following error messages.

What must be done now.

Thanks for your help
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Should it not be log4j.appender.stdout.target instead of log4j.appender.stdout.Target?
sree visu
Ranch Hand

Joined: Jul 05, 2007
Posts: 133
Yes i did the modifications.But still i get the same error.

Here is my log4j.properties


and my error messages



Sorry for requerying again.Please help me.
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Sorry try File instead of target
sree visu
Ranch Hand

Joined: Jul 05, 2007
Posts: 133
Thanks Martijn Verburg the warning and error messages vanished.But i still have one more problem.Instead of getting the logs inside my WEB-INF directory inside my server(Inside the project folder/build/web/WEB-INF/logs) ,I have got a new folder called WEB-INF created at my E:\ (E:\WEB-INF\logs) drive where my netbeans project resides.Could you please tell me what the problem is.

Thanks a lot
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Try a relative path instead of an absolute one (e.g. Get rid of the first '/')
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

A relative path is going to be interpreted as relative to the application server's current working directory. This isn't likely to be anything in any of the web applications running in the server.

If you want the logs to be put in a specific directory, provide the full path to that directory. Also putting the logs inside your web application isn't necessarily a good strategy, as they may disappear when you install a new version of the application in many servers.
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi,

i have the same problem..
here is my property file




and the error message
log4j:WARN No such property [target] in org.apache.log4j.FileAppender.
log4j:WARN File option not set for appender [stdout].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR No output stream or file set for the appender named [stdout].



and this is my class





what am i doing wrong....

i think i m doing wrong here in this line..... Logger logger =Logger.getLogger("loggg");
if not.. what is wrong
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

ceazer bunny wrote:
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.FileAppender
log4j.appender.stdout.Target=C:\Program Files\Java\jdk1.5.0_11\bin\log\error.log
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=debug, stdout


This is a little confusing to start with. I'd call your appender fileappender as opposed to stdout as stdout is traditionally to the console.

ceazer bunny wrote:
and the error message
log4j:WARN No such property [target] in org.apache.log4j.FileAppender.
log4j:WARN File option not set for appender [stdout].
log4j:WARN Are you using FileAppender instead of ConsoleAppender?
log4j:ERROR No output stream or file set for the appender named [stdout].


* As it says, you're using a property called target which is not valid, look at your capitilisation and/or what file appender actually expects as a property (hint, File not Target?)

Hope that helps!
*
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi martijn,

you certainly helped me...
now it is compiling without errors.... but i'm not getting the log in the desired file.... to be precise i did not get the log in any way. but the program is running fine without errors...

i have clarifications on these lines..

Logger logger =Logger.getLogger("log"); // in the class file.... i have log directory in the java\bin folder
log4j.appender.stdout.File=C:\Program Files\Java\jdk1.5.0_11\bin\log\error.log /// i donot have this error.log file in the path..i was thinking logger will create a file called error.log...

is it right???

what else should i do...



this is the class




this is the property file



thanks in advance

Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Try Logger logger = Logger.getLogger(SimpleLogging.class);
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi martijn,

i tried it but it is not creating any new file in the log folder.
can you just tell me where will be my log file and what will be the name of the log file for the code i have provided.

Thanks in advance
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

"ceazer bunny " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.


SCJP, SCWCD.
|Asking Good Questions|
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi amit,
i'm in office.
entry to that session is resstricted..
i guess it is regarding coding the codes..
i have done it
bharani rao
Ranch Hand

Joined: Apr 06, 2009
Posts: 164
hi martijn,

i didn't get the output..

help me please
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

ceazer bunny wrote:hi amit,
i'm in office.
entry to that session is resstricted..
i guess it is regarding coding the codes..
i have done it


It will be regarding your display name, see Naming Policy
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

ceazer bunny wrote:hi martijn,

i tried it but it is not creating any new file in the log folder.
can you just tell me where will be my log file and what will be the name of the log file for the code i have provided.

Thanks in advance


I would expect to see the log file at:

C:\Program Files\Java\jdk1.5.0_11\bin\log\error.log

However, sometimes java apps don't really like spaces in directory names, so try changing your log path to c:\error.log and see if one appears there
Josh Wild
Greenhorn

Joined: May 27, 2008
Posts: 7
When log4j starts it displays messages like

".....setting property file to 'xxxx'"
"Adding appender 'stdout' to appender 'root'" etc

To see these messages, your log4j configuration must have been started in "debug" mode. I can see from your config file that you are already doing that.

You must look out for the destination where 'File' attribute is being set. Also figure out if you are accidentally setting the root appender programatically (after log4j has started) because setting the root appender again will mean your previous settings will have no effect.


Josh Wild
Greenhorn

Joined: May 27, 2008
Posts: 7
....setting the root appender again will mean your previous settings will have no effect.


That means if you set the root appender again in code, you will not get traces logged to desired log file anyway unless you manually add a new FileAppender instance to root.
Leonardo Jose Gomes da Silva
Greenhorn

Joined: Dec 26, 2011
Posts: 7

You can do your log4j config that:



[]'s


Don't matter if your code are running, it need to be organized and well done!

Leonardo J. G. Silva
Analyst/Developer
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help Please -log4j:WARN No appenders could be found for logger