• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log files.

 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what I was pointing at. Saying Hi and Good Bye Sebastian seems rather obsolete
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I yield to that.
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got the answer , how to check the log files? -
from the link provided.

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i got the answer , how to check the log files? -from the link provided.

Great.
 
priya rishi
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sebastian Janisch and Christophe Verré for a good discussion.

Do you have any links for Logging in IBM Websphere?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic