• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Logging

 
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i create a seperate log file for my application ???
[ January 19, 2007: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Configure any logger and start using it.
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you be more specific how about you are logging things currently?
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to create a different log file for my aplication named Tools.war

well first let me explain what i did till now...

first i created log4j.properties in my project Tools's WEB-INF folder

log4j.properties File

code:
--------------------------------------------------------------------------------

#debug log4jlog4j.debug=truelog4j.rootLogger=debug, ROOT #Log things to a File, keep the files size to 500KB#and keep 2 backup fileslog4j.appender.ROOT=org.apache.log4j.RollingFileAppenderlog4j.appender.ROOT.File=d://temp//tools.loglog4j.appender.ROOT.MaxBackupIndex=2log4j.appender.ROOT.MaxFileSize=500KBlog4j.appender.ROOT.layout=org.apache.log4j.PatternLayoutlog4j.appender.ROOT.layout.ConversionPattern=%p %d %c %x- %m%nlog4j.appender.ROOT.threshold=DEBUGlog4j.appender.ROOT.Append=falselog4j.appender.ROOT.ImmediateFlush=true

--------------------------------------------------------------------------------



coppied log4j.jar file into the WEB-INF/lib directory and imported log4j.jar into my project Tools.

than i configured log4j.properties in packaging so that it will fall into the WEB-INF/classes directory when i deploy it where my other classes will also fall.

well other classes will fall in the appropriate packages like my servlet connect.class will fall in
WEB-INF/classes/com/tg/feedback/connect.class
where as log4j.properties will fall in the
WEB-INF/classes/log4j.properties

allright...

than this code is in my servlet Connect.java


code:
--------------------------------------------------------------------------------

public class Connect extends HttpServlet { private static final Logger l = Logger.getLogger("ROOT");

--------------------------------------------------------------------------------



and this is in my doPost method of Connect.java servlet


code:
--------------------------------------------------------------------------------

l.info("Hello World"); try{f.store_data_post(o);m.parse_xml(req.getParameter("dept_name").toLowerCase());m.send_mail(o.getMail(),"Feedback - " + o.getTopic(),o.getComment());}catch(Exception e){l.debug("JIGAR NAIK");e.printStackTrace();f.errFlagPost = true;}

--------------------------------------------------------------------------------



but my tools.log is not getting created... Error is also occuring in send_mail method and store_data method...
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jigar, could you edit your post (pencil icon) so your properties file and code is readable. It's REALLY hard to read, not to mention determine what is commented out and what isn't.

1. Really uncommon to create a logger in your class with Logger l = Logger.getLogger("ROOT");. All loggers inherit from ROOT, so not necessary and not very flexible to call any logger ROOT.

2. If you have log4j.debug=true in your properties file, then what debug output are you getting in the console log? Is it finding your properties file? Having any problems creating the output file?

3. Do double forward slashes work in a path?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code seems to be correct , but the loggin system has not been initialized.Use PropertyConfigurator to configure the loggin system with the log4j.properties that you have already created.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not working...

is there any other solution for creating seperate applciaton log ???

it's urgent... please...help....
 
Ranch Hand
Posts: 399
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jigar,

Try out this link:

http://www.vipan.com/htdocs/log4jhelp.html

All the best !!

Regards
Ayub
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is my log4j.properties file correct ???

 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
all except the line starting "message format", I think this should be commented
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where should log4j.peroperties file fall ??? how will it get read ???
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what may be the other reason causes my log file not being created ???
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in a web application? WEB-INF\classes is a good location
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya.. my log4j.properties file is falling in the WEB-INF/classes directory...

and how will j-boss get to know from where to read that file ???
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Log4j looks on your classpath.
It will find it there.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now i'm not using log4j.properties file.

I have added one appender and defined it catagory in the file ...JBoss/../conf/log4j.xml

this is the code which i added in log4j.xml at jboss server.



but when now when i start jboss server i get following error.

ERROR :



Anybody any idea ??? suggesion ???

I'm behind log4j since last 17 hours continuously without having dinner...

I'm pissed... huhuhu Helphhhhhh....
[ January 22, 2007: Message edited by: Jigar Naik ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool the jets and get some food. Getting pissed is wasted emotion.
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you put your appender with the other appenders in log4j.xml, and your logger or category with the other loggers/categories in log4j.xml. Looks like the error message shows the order the elements need to be in.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ya everything is allright...




The name of my project is ContactDetails which is having folder src which contains package com.cd and inside that servlet and java classses...

what should be the category name ???does it has to match with something ???

and there is no specification for my application like how will it get to know that generate log file only for ContactDetaail Project...???
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have given my package name in category name com.cd

its still giving the same error at the end of file

 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
logger/category Match:

Category is the old name for Logger. So, The category or logger in your configuration file should match part or all of the name of your Logger in your java code

Logger l = Logger.getLogger(MyClass.class);

If package is com.foo then the Logger name is com.foo.MyClass
To match in the configuration file you could use com.foo or com.foo.MyClass

<category name="com.foo"
<category name="com.foo.MyClass"

or

<logger name="com.foo"
<logger name="com.foo.MyClass"
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Configuration error :

log4j:ERROR The content of element type "log4j:configuration" must match "(renderer*,appender*,(category|logger)*,root?,categoryFactory?)".



Are all the appenders listed before all of the category elements and both of those are before the root element?

<appender/>
<appender/>
<appender/>
<appender/>
<appender/>

<category/>
<category/>
<category/>
<category/>
<category/>

<root>

If that;s not the problem, then check that the rest of the elements are in the order indicated in the error message.
[ January 22, 2007: Message edited by: Carol Enderlin ]
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes,
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



in .java file




Error while starting jboss server:

 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CDetails.java is in

ContactDetails <-- Project name
src <-- name of the source folder
com.tg.contact <-- package name
CDetail.java <-- servlet name
which contains following code

[ January 22, 2007: Message edited by: Jigar Naik ]
 
Carol Enderlin
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry to say I've about run out of ideas.

After googling on your error again I saw one reference that said they were getting your error, but logging was actually working. If you don't see your file where you expect it, make sure it is getting jboss.server.home.dir value or it will be putting it elsewhere.

<param name="File" value="${jboss.server.home.dir}/log/contact.log"/>

Beyond that it may be some kind of JBoss-specific issue.
 
Jigar Naik
Ranch Hand
Posts: 763
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Logging problem solved...

using >>> http://logging.apache.org/log4j/docs/manual.html



thanks all for spending time and helping me...
 
reply
    Bookmark Topic Watch Topic
  • New Topic