
On Fri, Dec 26, 2008 at 9:48 AM, Jason Wagner <jason@nialscorva.net> wrote:
Hello all,
I know there are two proposed logging libraries out there for Boost, already, but I had a different itch to scratch on a project. I think I saw that Andrey Semashev was going to submit his far more mature version soon, but I thought I'd throw my technique out there for an interest check and hopefully commentary. This is very much a prototype-- there's a lot of work yet to be done but the basic outline and functionality is implemented.
Getting the code ---------------- http://www.nialscorva.net/boost_logging-0_1.tar.bz2
What is the motivation for using boost::mpl in the logging library? I didn't look too deeply into your code, but wouldn't something like this work just as well: struct logging_debug; struct logging_release; template <class> struct logging_traits; template <> logging_traits<logging_debug> { .... }; In other words, let the user provide an explicit specialization to configure the logger; once that's done, they just do: logger<logging_debug> log; My reasoning is that a logging library should be lightweight in terms of source code; when I need logging, I'd rather not get boost::mpl too. A few more comments: In general I don't like using macros or #ifdefs, but one place where I think they are OK is in a logging library interface, partially because they make it much lighter, and partially because automatically logging __FILE__, __LINE__, etc. is desirable IMO. Finally, I think that all the machinery a typical logging lib uses to kill logging expressions when they're not needed is an overkill. I've found that using something as simple as the code below works just fine: namespace logging { static bool const warnings=false; static bool const errors=true; } and then: if( logging::warnings ) log << "Warning"; where log simply implements std::ostream. You could put the if in a macro but frankly, I personally don't mind typing it every time; compared to the rest of the junk I have to type to format a meaningful logging message, the if is not an issue. As a bonus, you don't have to worry about functions referenced by a logging expression being executed when logging is not enabled. -- Emil Dotchevski Reverge Studios, Inc. http://www.revergestudios.com/reblog/index.php?n=ReCode