

Show HN: Header-only debug module for c++11 - porphyry3
https://github.com/vzaccaria/debug.hxx

======
amelius
Some things that are missing (at least from the docs):

    
    
        - multithreaded logging (show thread ID with each line)
        - nesting (e.g. indent logged lines when entering a scope)
        - logging of values other than strings (mentioned already)
        - storing the results in a separate file (rather than outputting to stderr)
    

Also, the documentation is too terse. And, what is that lambda symbol doing in
the output?

~~~
to3m
This code also constructs a std::string each time you do some logging.

Really, you need to be using a #define to call the logging function, one that
goes a bit like this. You invoke it like printf. (I know some people hate
printf, but I like it. Anyway, that's addressed below.)

    
    
        #define LOG(LOG,...)                                                      \
            do {                                                                  \
                extern LogData LogData_##LOG;                                     \
                if(LogData_##LOG.enabled) PrintToLog(LogData_##LOG, __VA_ARGS__); \
            } while(0)
    

Then you use it, like, ``LOG(MyLog, "Hello: %d\n", n)''. You need another
macro to generate the LogData_XXX variables with the right name and so on.

There are two advantages to doing it like this.

Firstly, the cost is minimal if the logging is disabled. This isn't so much to
avoid the call to PrintToLog - though that doesn't hurt! - as PrintToLog would
surely check the flag itself and early out at little cost. It's more to avoid
having to evaluate the printf args. Say you're printing out 3 things, and each
thing requires a function call - along the lines of ``PrintToLog("%d %d
%d",f0(),f1(),f2())'' \- then calling PrintToLog requires those 3 function
calls to be made before PrintToLog is entered, even when the log is disabled.
No good, especially if they're expensive.

The second - and one reason I've always done this printf-style rather than
iostreams, though maybe iostreams-style would be doable, if you didn't mind
some slightly funny syntax - is that you can strip all the debugging out with
an alternative #define:

    
    
        #define LOG(...) ((void)0)
    

This gets rid of everything, code and string literals. If your product won't
have anywhere to put debug logs when it's running in the wild, or you're short
on code/data space, or you just want to strip out certain types of message
(you might have a VLOG for verbose debugging, for example, that doesn't want
to be in the final product), then you can do that.

This particular package suffers from both problems, I think, as (based on a
quick skim of the code) does the Google one mentioned elsewhere.

------
Ecco
Shouldn't it be called a _logging_ module?

~~~
Galanwe
It doesn't even support logging anything other than strings... I would just
call it "print string lambda" ... Why is this thing on HN?

------
ajtulloch
If you're looking for something more fully featured,
[https://code.google.com/p/google-glog/](https://code.google.com/p/google-
glog/) is a great C++ logging library.

~~~
stingraycharles
The documentation is here, for anyone who is equally confused as I was:

[https://google-glog.googlecode.com/svn/trunk/doc/glog.html](https://google-
glog.googlecode.com/svn/trunk/doc/glog.html)

