chaolou / google-glog

Automatically exported from code.google.com/p/google-glog
Other
0 stars 0 forks source link

Special "debug mode" logging macros have always effect, even if NDEBUG macro is defined #96

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. define macro NDEBUG 
2. use Special "debug mode" logging macros in an application 
3. launch compiled application

What is the expected output? What do you see instead?
 The expected output is that logging in debug mode should not appear. Instead it does.

What version of the product are you using? On what operating system? 
Google-gflags 1.6 on Debian unstable (linux kernel 3.0.0-1-amd64)
"
Please provide any additional information below.
 g++ compiler version 4.6 

Original issue reported on code.google.com by alberto....@gmail.com on 30 Aug 2011 at 9:16

GoogleCodeExporter commented 8 years ago
It was my mistake. I defined macro NDEBUG in the wrong header; the source file 
where "debug mode" logging macros were used did not include that header.
The fix was just to define macro NDEBUG in the correct place ;-)

Original comment by alberto....@gmail.com on 6 Sep 2011 at 5:14

GoogleCodeExporter commented 8 years ago
I think I ran into a similar problem as you did, #define NDEBUG doesn't seem to 
have an effect any logging output (DLOG didn't disappear) and was about to open 
an issue on this. Is it supposed to use this way?

#include <iostream>
#include <glog/logging.h>
using namespace std;

#define NDEBUG 1

int main(int argc, char* argv[]) {
    google::InitGoogleLogging(argv[0]);
    DLOG(INFO) << "Hello World" << endl; 
}

Original comment by fwa...@gmail.com on 11 Jun 2012 at 6:36

GoogleCodeExporter commented 8 years ago
The problem is that the macro NDEBUG should be defined before including glog 
header.
I tried your code, and it works with this fix. (it works as assert function 
http://www.cplusplus.com/reference/clibrary/cassert/assert/)

Just to notice that it is not necessary to set the constant value of NDEBUG 
(i.e., 1).

Below I report the code corrected.

#define NDEBUG

#include <iostream>
#include <glog/logging.h>
using namespace std;

int main(int argc, char* argv[]) {
    google::InitGoogleLogging(argv[0]);
    DLOG(INFO) << "Hello World" << endl; 
}

Original comment by alberto....@gmail.com on 11 Jun 2012 at 9:24

GoogleCodeExporter commented 8 years ago
Yes, this is the correct behavior. Appreciate the comments. I wish the 
documents can be more clear on this.

Original comment by fwa...@gmail.com on 12 Jun 2012 at 4:05