GeeCON Prague 2014*
The moose likes Servlets and the fly likes Logging Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Logging" Watch "Logging" New topic
Author

Logging

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
how do i create a seperate log file for my application ???
[ January 19, 2007: Message edited by: Bear Bibeault ]

Jigar Naik


Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Configure any logger and start using it.


Rahul Bhattacharjee
LinkedIn - Blog
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Can you be more specific how about you are logging things currently?


My Blog: Down Home Country Coding with Scott Selikoff
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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...
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Nov 29, 2005
Posts: 2308
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

Joined: Dec 12, 2006
Posts: 757
It's not working...

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

it's urgent... please...help....
Ayub ali khan
Ranch Hand

Joined: Oct 20, 2005
Posts: 380
    
    2
Hi Jigar,

Try out this link:

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

All the best !!

Regards
Ayub


SCEA part I,TOGAF Foundation
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
Is my log4j.properties file correct ???

David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

all except the line starting "message format", I think this should be commented
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
Where should log4j.peroperties file fall ??? how will it get read ???
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
what may be the other reason causes my log file not being created ???
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

in a web application? WEB-INF\classes is a good location
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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 ???
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Log4j looks on your classpath.
It will find it there.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

Cool the jets and get some food. Getting pissed is wasted emotion.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Dec 12, 2006
Posts: 757
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

Joined: Dec 12, 2006
Posts: 757
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
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Dec 12, 2006
Posts: 757
yes,
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757



in .java file




Error while starting jboss server:

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 757
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
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
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

Joined: Dec 12, 2006
Posts: 757
Logging problem solved...

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



thanks all for spending time and helping me...
 
GeeCON Prague 2014
 
subject: Logging