Newbie question on adding trace statements

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Newbie question on adding trace statements

Joseph Wang
This is a newbie question....

I'd like to add some code into Quantlib to dump out intermediate results
for debugging,
and it seems that it would be a good thing to have some mechanism that
you can turn
on trace statements in response to an environment variable.  Something
similar to the
Java Logger facility.

What is the preferred way of doing this in Quantlib?




Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on adding trace statements

Luigi Ballabio
On 12/29/04 09:46:55, Joseph Wang wrote:
> I'd like to add some code into Quantlib to dump out intermediate results  
> for debugging, and it seems that it would be a good thing to have some  
> mechanism that you can turn on trace statements in response to an  
> environment variable.  Something similar to the
> Java Logger facility.
>
> What is the preferred way of doing this in Quantlib?

Joseph,
        there's no such mechanism at the time, but I'd happily insert it. I  
wouldn't go for a full-featured logging facility, though---I'd be happy  
with something as simple as

    QL_TRACE("x = " << x << ", y = " << y);

whose effects would be turned on/off by something like

    Settings::instance().enableTracing();  // or disableTracing()

and whose destination would be set by something like

    Settings::instance().traceTo(std::cerr); // or an ofstream, or whatever

Do you think this would fit the bill?

Later,
        Luigi




Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on adding trace statements

Joseph Wang
There should probably be the concept of different debug levels, so that
you can set things up for minimal trace or dump every single number.  
The interface should probably look like

QL_TRACE(int tracelevel, output);

Settings::instance.setTraceLevel(int);

The trace levels that java Logger uses should be plenty.

Luigi Ballabio wrote:

> On 12/29/04 09:46:55, Joseph Wang wrote:
>
>> I'd like to add some code into Quantlib to dump out intermediate
>> results  for debugging, and it seems that it would be a good thing to
>> have some  mechanism that you can turn on trace statements in
>> response to an  environment variable.  Something similar to the
>> Java Logger facility.
>>
>> What is the preferred way of doing this in Quantlib?
>
>
> Joseph,
>     there's no such mechanism at the time, but I'd happily insert it.
> I  wouldn't go for a full-featured logging facility, though---I'd be
> happy  with something as simple as
>
>    QL_TRACE("x = " << x << ", y = " << y);
>
> whose effects would be turned on/off by something like
>
>    Settings::instance().enableTracing();  // or disableTracing()
>
> and whose destination would be set by something like
>
>    Settings::instance().traceTo(std::cerr); // or an ofstream, or
> whatever
>
> Do you think this would fit the bill?
>
> Later,
>     Luigi
>



Reply | Threaded
Open this post in threaded view
|

Re: Newbie question on adding trace statements

Luigi Ballabio
On 01/04/05 04:56:35, Joseph Wang wrote:
> There should probably be the concept of different debug levels, so that  
> you can set things up for minimal trace or dump every single number.

Yes, that stroke me after sending my reply. There should be a way to  
selectively emit information.

> The interface should probably look like
>
> QL_TRACE(int tracelevel, output);
>
> Settings::instance.setTraceLevel(int);

Another way might be to add a tag:

    QL_TRACE(const std::string& tag, output);

    Settings::instance().enableTracing(tag);

The above could be useful as a particular task could be traced in  
isolation, without tracing from different parts of the library confusing  
the output. Were you thinking of the tracing facility as a development/
debugging aid (in which case I'd favor the second solution) or as a logging  
facility to be made available to end-users (in which case I'd favor the  
first?)  Or could these be two separate facilities?

Later,
        Luigi

P.S. I'll be away for a few days starting tomorrow ("away" as in both "from  
the office" and "from the net".) I might not be very responsive during that  
time :)