Debug logging

6,099 views
Skip to first unread message

Alexander Demin

unread,
Jul 19, 2009, 12:05:14 PM7/19/09
to Google C++ Testing Framework
Hi,

Some of our developers regularly ask about the possibility to log
something in the tests. They would like to do something like this:

...
EXPECT_EQ(...);
LOG() << "a custom debugging output";
...

or

LOG(2) << "a custom debugging output on level 2";

where 2 is logging level.

In the normal run of tests the LOG() macro does nothing but if needed
a developer can use '--gtest_verbose' (or --gtest_verbose=2) flag to
have that additional debug information printed to the console.

I encourage people not to do this because a test should not be in
"unfinished" state when that debug output could be useful.
Unfortunately in reality it happens sometimes when, for example, a
test is stable enough and it does what it should do but the higher
level logic is not examined properly (if, for instance, some code
talks to an external library and not all response code are fully
tested). So that LOG() output would be useful when somebody has to
come back to this test and review it again.

Just interesting how do other people manage this situation?

In terms of GTest itself the patch for this kind of feature would not
be too difficult but it is worth to know to reason of doing that in
general.

Alexander

Zhanyong Wan (λx.x x)

unread,
Jul 19, 2009, 7:31:10 PM7/19/09
to Alexander Demin, Google C++ Testing Framework

Logging is not specific to testing. You should be able to find an
open-source logging library to use with gtest. One logging library is
Google glog: http://code.google.com/p/google-glog/

Documentation: http://google-glog.googlecode.com/svn/trunk/doc/glog.html

I haven't tried to use it myself, but you may be able to make it work
with gtest. Thanks,
--
Zhanyong

Alexander Demin

unread,
Jul 20, 2009, 5:47:44 AM7/20/09
to Zhanyong Wan (λx.x x), Google C++ Testing Framework
I have been using GLog already for sometime. This library is very functional but it's not quite easy to be used on Windows. The latest version has the major improvements in terms of portability especially for Windows but some bits needed to be fixed.

Anyway I got it, thanks.

Alexander

2009/7/20 Zhanyong Wan (λx.x x) <w...@google.com>
Reply all
Reply to author
Forward
0 new messages