File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes log files. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "log files." Watch "log files." New topic
Author

log files.

priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
Hello,

I am studying attributes and listeners.
where its mentioned ,
ServletContext can be used for logging , if the web app is really small and simple - HFSJ.
So,
What are Log files? and
Whats the purpose?

any help,
priya.


SCJP 5 , SCWCD 5
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Log Files are used to trace the flow of your application and help debugging.

You could write the info that a certain servlet is executing into a log file, as well as error messages.

I don't really know how that goes together with a ServletContextListener as these events only fire upon server startup and shutdown ...


JDBCSupport - An easy to use, light-weight JDBC framework -
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
I don't really know how that goes together with a ServletContextListener as these events only fire upon server startup and shutdown ...


i think we use ServletContext 's log(String) method for the purpose of logging.
but i am not sure of the ServletContextListener here.

my doubt :

if we want to have ServletContext's log() , where should we provide the implementation.
like in which part of web app., as the instance of ServletContext is available to all parts of the web app(servlets and jsps).



Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

i think we use ServletContext 's log(String) method for the purpose of logging.
but i am not sure of the ServletContextListener here.

The ServletContextListener receives a ServletContextEvent as a parameter of its methods. You can retrieve the ServletContext from ServletContextEvent, and use the log method to log anything you want.

You can check how Tomcat is using the logging facilities here.


[My Blog]
All roads lead to JavaRanch
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
The ServletContextListener receives a ServletContextEvent as a parameter of its methods. You can retrieve the ServletContext from ServletContextEvent, and use the log method to log anything you want.


Well fine but who wants to log only upon startup and shutdown ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Why "only" ? If you use the ServletContextListener, it's true that this will be used at startup and shutdown. You might want to say "hello Sebastian" or "goodbye Sebastian" at that time
But you can also use the ServletContext elsewhere during the application lifetime, via HttpServlet#getServletContext, or directly via GenericServlet#log.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
That's what I was pointing at. Saying Hi and Good Bye Sebastian seems rather obsolete
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Saying Hi and Good Bye Sebastian seems rather obsolete

You may have to do more than that. On startup, you may want to access some files, or access a database... You may have to log what you're doing at that time. You may have to report any error occuring at that time. I don't think it's obsolete to have a logging facility there.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I yield to that.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
On startup, you may want to access some files, or access a database... You may have to log what you're doing at that time. You may have to report any error occuring at that time.


here you are creating a log of what you are doing.
if i want to check the log how can i do that?
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
i got the answer , how to check the log files? -
from the link provided.

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

i got the answer , how to check the log files? -from the link provided.

Great.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
Thanks Sebastian Janisch and Christophe Verré for a good discussion.

Do you have any links for Logging in IBM Websphere?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I don't know if this article helps, because it doesn't talk about ServletContext#log. But the result should be the same, so check it out.
priya rishi
Ranch Hand

Joined: Oct 26, 2008
Posts: 119
Thanks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log files.