servletcontext listener vs servlet with high priority on loading

A

a

Hi,

I have a question about initializing the web app. There are 2 ways to do the
initialization.
1> Create a servlet with high loading priority on web.xml.
2> Use servletcontext listener

Why the second way is better?

I used to use a class with static logger to standardize the format of the
log. I cannot use this class because it has not been loaded when the
servlet context event is sent.
Is there anyway to overcome my problem if I use the servletcontext listener?

Thanks
 
J

jaap

Hi,

I have a question about initializing the web app. There are 2 ways to do
the
initialization.
1> Create a servlet with high loading priority on web.xml.
2> Use servletcontext listener

Why the second way is better?

I used to use a class with static logger to standardize the format of the
log. I cannot use this class because it has not been loaded when the
servlet context event is sent.
Is there anyway to overcome my problem if I use the servletcontext
listener?

Thanks

I prefer the ServletContextListener, it is made for that job. Make it
the first in the list of listeners in web.xml.

Success,
Jaap
 
M

markspace

I cannot use this class because it has not been loaded when the
servlet context event is sent.


I'd have to go check my JEE stuff again but I'd say in general the
context listener is superior. Loading order has to be manually
maintained. Context listeners fire automatically.

I used to use a class with static logger to standardize the format of the
log.

For this particular application, there are already ways to initialize
your logger (both the standard SE one and log4j). Why are you not using
the standard configuration files?
 
M

markspace

I build my own version of Log Util based on the log4j. The purpose is for
convenience. It involves a lot of static method and static variable.


I think you have just discovered that home built frameworks like this
are often not more convenient. Please try the existing configuration files.

I expect objects can be instantiated in ServletContextListener, but not any
static in a class. Is that true? Pls explain.


I don't understand.
 
L

Lew

markspace said:
I think you have just discovered that home built frameworks like this
are often not more convenient. Please try the existing configuration files.

+1

With log4j, the same-named logger (i.e., via the class or class name you pass to the constructor) is the same logger instance. It is better to name alogger by the class that uses it, as documented in the log4j instructions.This helps ops to maintain the program. I don't know whose convenience you're trying to serve, "a", but I will bet dollars to doughnuts it's not the folks whose convenience you ought to serve, namely the production personnel.

Logging isn't for programmers, it's for ops.
I don't understand.

I wonder if "a" means that you cannot instantiate a logger as a static variable, which of course is nonsense. You most definitely can, and sometimes should, instantiate a logger as a static variable.

If "a" refers to objects in general, then it's even more nonsensical. It'sJava. Of course you can instantiate objects as static members.

Perhaps "a" ought to clarify his meaning. "a"?

Also, "a", I heartily recommend you read *and study* the documentation for log4j (or any other framework that you use).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top