new scrapple Lib: API logging
BCS
ao at pathlink.com
Wed Aug 13 21:03:40 PDT 2008
Reply to Christopher,
> BCS wrote:
>
>> (lets try this again in the correct NG :)
>>
>> I have posted a new library to scrapple.
>>
>> http://www.dsource.org/projects/scrapple/browser/trunk/log_api
>>
>> This library allows simple wrapping of function calls with logging of
>> file name/line number of call, function name and argument/return
>> values.
>>
>> The intended use for this lib is for debugging the external API's.
>> For example
>>
>> I wrote it because I was having issues with a mysql wrapper lib and
>> wanted to known what api calls were being made.
>>
>> To use it, replace the calls to be logged with wrapped calls:
>>
>> ulong r = mysql_real_escape_string(connection, ret.ptr, string.ptr,
>> string.length); ulong r =
>> TraceAPI!("mysql_real_escape_string)(__FILE__,__LINE__,connection,
>> ret.ptr, string.ptr, string.length);
>>
> This is really ugly, but it does a good thing.
>
Ah, Yah. that about sums it up.
> Maybe you could incorporate jive.stacktrace (or one of the hacked
> versions that actually works) so you don't have to use __FILE__,
> __LINE__? Though that's probably more than you want to do.
>
I wanted very light dependencies, I actually considered going with printf
rather than writef but I can live with that one
Considering if you are smart about it you doesn't need to type the __FILE__,__LINE__
more than once (http://gskinner.com/RegExr/) I can live with that ugliness.
> Also, have you tried alias parameters rather than strings? It results
> in more sensible error messages.
>
Yup that was my first thought, but it didn't work for some reason and the
string trick did. I was kind of in a Fast, Stupid 'n Works kind of mood.
I don't recall why it wasn't working but I might take a pass at trying at
again (feel free to take a crack at it your self, I can get you SVN access
if you want to commit improvements)
More information about the Digitalmars-d-announce
mailing list