Overview
Features
Download
Documentation
Community
Add-Ons & Services

Compile-time type safety in Poco logging

Discussion of ideas for features and new projects based on POCO.

Compile-time type safety in Poco logging

Postby codecandy2k » 11 Jan 2012, 23:10

So one of the things I've discovered about Poco that is not so nice is that the Poco convenience macros for the logging framework make use of the very fickle Poco::format function. Since logging is often used for debugging purposes, the last thing we need is runtime bad cast exceptions being thrown by the logging calls.

I'm not quite sure what the answer is off the top, but maybe something like macros or template functions that use a LogStream instead of using format would be better.
codecandy2k
 
Posts: 40
Joined: 03 Dec 2011, 18:48

Re: Compile-time type safety in Poco logging

Postby codecandy2k » 11 Jan 2012, 23:44

I guess there would need to be macros involved, and something other than LogStream used, so that things like source file and line can be properly added to the messages.

I'm thinking a series of template functions that can be used by themselves to construct messages, and also a set of macros that will call the template functions and pass in __FILE__ and __LINE__.

It will probably be a little more expensive than the current macros, but would be more usable and less chance of the logging itself causing problems. So additions rather than replacements.

I'll put together something along the lines of what I'm thinking about here and submit it.
codecandy2k
 
Posts: 40
Joined: 03 Dec 2011, 18:48

Re: Compile-time type safety in Poco logging

Postby codecandy2k » 12 Jan 2012, 00:07

Another thing that might be useful as I'm thinking of it is some stream modifiers that could add __FILE__ and __LINE__ to a log message.

Then we could do something like:

Code: Select all
logStream.fatal()  << LogStream::SourceFile(__FILE__) << LogStream::SourceLine(__LINE__) << "some log message" << std::endl;

or maybe this would be simpler to implement:

Code: Select all
logStream.fatal().source(__FILE__).line(__LINE__) << "some log message" << std::endl;



Then we could do something like
Code: Select all
#define poco_fatal_f4(s, arg1, arg2, arg3, arg4 ) \
   s.fatal().source(__FILE__).line(__LINE__) << arg1 << arg2 << arg3 << arg4 << std::endl;


poco_fatal_f4( logStream, "Some log message. Value1=", value1, ", value2=", value2 );
codecandy2k
 
Posts: 40
Joined: 03 Dec 2011, 18:48


Return to Wishlist

Who is online

Users browsing this forum: No registered users and 1 guest

cron