[slf4j-user] logging a stack trace along with a parameterized string
Maarten Bosteels
mbosteels.dns at gmail.com
Thu Dec 20 09:24:17 CET 2007
On Dec 20, 2007 9:18 AM, Lowell Kirsh <lowellk at gmail.com> wrote:
> What if there was a new debug method - something like debug(Throwable,
> String, Object[])? Would that confuse java's method resolution?
I guess not. But it would confuse me :-)
Maarten
>
>
> On Dec 20, 2007 12:14 AM, Maarten Bosteels <mbosteels.dns at gmail.com> wrote:
> > If you're on java 1.5 you can write
> >
> > LOG.debug(String.format("Got a %s with value %s",
> > e.getClass().getName(), e.getValue()), e);
> >
> > Maarten
> >
> >
> > On Dec 19, 2007 10:36 PM, Lowell Kirsh <lowellk at gmail.com> wrote:
> > > Thanks for the info. No big deal about having to concatenate those strings
> > > like that - it's what I was used to until recently ;-)
> > >
> > >
> > >
> > > On Dec 19, 2007 12:30 PM, Ceki Gulcu < listid at qos.ch> wrote:
> > > >
> > > > Hi Lowell,
> > > >
> > > > This is a well-known shortcoming of the SLF4J API. However, since
> > > exceptions are
> > > > by definition rare, you can write
> > > >
> > > > LOG.debug("Got a "+e.getClass().getName()+" with value "+ e.getValue(),
> > > e);
> > > >
> > > > with an *infrequent* loss in performance. Of course, this form is also
> > > less
> > > > pleasant to write, but again you write less of these.
> > > >
> > > > HTH,
> > > >
> > > >
> > > >
> > > >
> > > > Lowell Kirsh wrote:
> > > > > Looking at the API, I can't figure out how to log an exception's stack
> > > > > trace along with a parameterized string. What I want is something like:
> > > > >
> > > > > ...
> > > > > catch (FooException e) {
> > > > > LOG.debug("Got a {} with value {}", e.getClass().getName(),
> > > > > e.getValue (), e);
> > > > > }
> > > > >
> > > > > But it seems from the API that I can either pass a Throwable to the log
> > > > > method, or some arguments to be interpolated into the String. Is there
> > > > > an idiom for doing both?
> > > > >
> > > > > Thanks,
> > > > > Lowell
> > > >
> > > >
> > > > --
> > > > Ceki Gülcü
> > > > Logback: The reliable, generic, fast and flexible logging framework for
> > > Java.
> > > > http://logback.qos.ch
> > > > _______________________________________________
> > > > user mailing list
> > > > user at slf4j.org
> > > > http://www.slf4j.org/mailman/listinfo/user
> > > >
> > >
> > >
> > > _______________________________________________
> > > user mailing list
> > > user at slf4j.org
> > > http://www.slf4j.org/mailman/listinfo/user
> > >
> > _______________________________________________
> > user mailing list
> > user at slf4j.org
> > http://www.slf4j.org/mailman/listinfo/user
> _______________________________________________
> user mailing list
> user at slf4j.org
> http://www.slf4j.org/mailman/listinfo/user
>
More information about the slf4j-user
mailing list