Logging API

F

fritz-bayer

Hello,

I have been using the logging API to log HTTP requests. I have an
object, which resembles a HTTP request and has methods to extract the
typical fields of a HTTP request.

Now, I have noticed that you can only pass log messages as a String and
not as an object. Also I saw that Formatters format "around" this
String. I think that is quite a limitation for my purpose.

What's if I have different Log Formats, which I would like to apply.
For example, there are different levels of verbosity. The apache log
format "combined" sends more output then "common". Maybe I also want to
define my own custom ones.

Then I would like to have a Formatter for each output Format. Do do
that, however, Formatters would have to be able to work on those HTTP
objects, which contain the fields.

That does not seem to be possible under the current logging API or am I
missing someting here? I really don't understand, why the message is
not being stored as an Object but a String - that only limits the use
of the Formatter.
Can somebody elaborate on this. Maybe it should be brought up with Sun?
 
T

Tilman Bohn

In message <[email protected]>,
Hello,

I have been using the logging API to log HTTP requests. I have an
object, which resembles a HTTP request and has methods to extract the
typical fields of a HTTP request.

Now, I have noticed that you can only pass log messages as a String and
not as an object.

Because they are strings, String is the most natural representation
for them.
Also I saw that Formatters format "around" this
String. I think that is quite a limitation for my purpose.

You can always decorate your Logger. You only need a thin wrapper that
unpacks the object you would like to pass and builds an appropriate
String for the Logger.

[...]
missing someting here? I really don't understand, why the message is
not being stored as an Object but a String - that only limits the use
of the Formatter.

And what generic mechanism would you propose to extract the log message
from the Object you want to pass? You can only depend on methods declared
in Object! So the only likely candidate would be toString(), but then
there would really be no point to the whole thing, as you can just as
well let the caller get the relevant String that way. If you want to be
more flexible, you will have to depend on more specific behavior of the
type of object you pass, in which case a decorator is the way to go.
Can somebody elaborate on this. Maybe it should be brought up with Sun?

Hardly.
 

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

No members online now.

Forum statistics

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