Logging API  
Author Message
fritz-bayer





PostPosted: 2005-1-6 18:00:00 Top

java-programmer, Logging API 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?

 
fritz-bayer





PostPosted: 2005-1-6 18:05:00 Top

java-programmer >> Logging API 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?

 
Tilman Bohn





PostPosted: 2005-2-20 2:39:00 Top

java-programmer >> Logging API In message <email***@***.com>,
email***@***.com wrote on 6 Jan 2005 02:00:10 -0800:

> 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.

--
Cheers, Tilman

`Boy, life takes a long time to live...' -- Steven Wright