• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Usually this occurs when you do not have log4j.properties in your CLASSPATH.
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should it not be log4j.appender.stdout.target instead of log4j.appender.stdout.Target?
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry try File instead of target
 
sree visu
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try a relative path instead of an absolute one (e.g. Get rid of the first '/')
 
Marshal
Posts: 28296
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try Logger logger = Logger.getLogger(SimpleLogging.class);
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"ceazer bunny " please check your private messages for an important administrative matter. You can check them by clicking the My Private Messages link above.
 
bharani rao
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi martijn,

i didn't get the output..

help me please
 
Martijn Verburg
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

....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.
 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do your log4j config that:



[]'s
 
Beware the other head of science - it bites! Nibble on this message:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic