GLOG_logtostderr=1 ./your_application
</pre>
+<!-- TODO(hamaji): Fill the version number
+<p>By glog version 0.x.x, you can use GLOG_* environment variables
+even if you have gflags. If both an environment variable and a flag
+are specified, the value specified by a flag wins. E.g., if GLOG_v=0
+and --v=1, the verbosity will be 1, not 0.
+-->
+
<p>The following flags are most commonly used:
<dl>
<p>There are some other flags defined in logging.cc. Please grep the
source code for "DEFINE_" to see a complete list of all flags.
+<p>You can also modify flag values in your program by modifying global
+variables <code>FLAGS_*</code> . Most settings start working
+immediately after you update <code>FLAGS_*</code> . The exceptions are
+the flags related to destination files. For example, you might want to
+set <code>FLAGS_log_dir</code> before
+calling <code>google::InitGoogleLogging</code> . Here is an example:
+
+<pre>
+ LOG(INFO) << "file";
+ // Most flags work immediately after updating values.
+ FLAGS_logtostderr = 1;
+ LOG(INFO) << "stderr";
+ FLAGS_logtostderr = 0;
+ // This won't change the log destination. If you want to set this
+ // value, you should do this before google::InitGoogleLogging .
+ FLAGS_log_dir = "/some/log/directory";
+ LOG(INFO) << "the same file";
+</pre>
+
<h2><A NAME=conditional>Conditional / Occasional Logging</A></h2>
<p>Sometimes, you may only want to log a message under certain
for informational messages.
<pre>
- LOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie";
+ LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
</pre>
<p>The above line outputs a log messages on the 1st, 11th,
21st, ... times it is executed. Note that the special
-<code>COUNTER</code> value is used to identify which repetition is
+<code>google::COUNTER</code> value is used to identify which repetition is
happening.
<p>You can combine conditional and occasional logging with the
following macro.
<pre>
- LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << COUNTER
+ LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
<< "th big cookie";
</pre>
the output to the first n occurrences:
<pre>
- LOG_FIRST_N(INFO, 20) << "Got the " << COUNTER << "th cookie";
+ LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
</pre>
<p>Outputs log messages for the first 20 times it is executed. Again,
-the <code>COUNTER</code> identifier indicates which repetition is
+the <code>google::COUNTER</code> identifier indicates which repetition is
happening.
<h2><A NAME=debug>Debug Mode Support</A></h2>
DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
- DLOG_EVERY_N(INFO, 10) << "Got the " << COUNTER << "th cookie";
+ DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
</pre>
<h2><A NAME=check>CHECK Macros</A></h2>
"program with --v=1 or more";
VLOG_EVERY_N(1, 10)
<< "I'm printed every 10th occurrence, and when you run the program "
- "with --v=1 or more. Present occurence is " << COUNTER;
+ "with --v=1 or more. Present occurence is " << google::COUNTER;
VLOG_IF_EVERY_N(1, (size > 1024), 10)
<< "I'm printed on every 10th occurence of case when size is more "
" than 1024, when you run the program with --v=1 or more. ";
- "Present occurence is " << COUNTER;
+ "Present occurence is " << google::COUNTER;
</pre>
<h2> <A name="signal">Failure Signal Handler</A> </h2>
all log messages associated with <code>VLOG</code>s as well as
<code>INFO</code> log statements.
+<h3><A NAME=windows>Notes for Windows users</A></h3>
+
+<p>Google glog defines a severity level <code>ERROR</code>, which is
+also defined in <code>windows.h</code> . You can make glog not define
+<code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
+and <code>FATAL</code> by defining
+<code>GLOG_NO_ABBREVIATED_SEVERITIES</code> before
+including <code>glog/logging.h</code> . Even with this macro, you can
+still use the iostream like logging facilities:
+
+<pre>
+ #define GLOG_NO_ABBREVIATED_SEVERITIES
+ #include <windows.h>
+ #include <glog/logging.h>
+
+ // ...
+
+ LOG(ERROR) << "This should work";
+ LOG_IF(ERROR, x > y) << "This should be also OK";
+</pre>
+
+<p>
+However, you cannot
+use <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
+and <code>FATAL</code> anymore for functions defined
+in <code>glog/logging.h</code> .
+
+<pre>
+ #define GLOG_NO_ABBREVIATED_SEVERITIES
+ #include <windows.h>
+ #include <glog/logging.h>
+
+ // ...
+
+ // This won't work.
+ // google::FlushLogFiles(google::ERROR);
+
+ // Use this instead.
+ google::FlushLogFiles(google::GLOG_ERROR);
+</pre>
+
+<p>
+If you don't need <code>ERROR</code> defined
+by <code>windows.h</code>, there are a couple of more workarounds
+which sometimes don't work:
+
+<ul>
+ <li>#define <code>WIN32_LEAN_AND_MEAN</code> or <code>NOGDI</code>
+ <strong>before</strong> you #include <code>windows.h</code> .
+ <li>#undef <code>ERROR</code> <strong>after</strong> you #include
+ <code>windows.h</code> .
+</ul>
+
+<p>See <a href="http://code.google.com/p/google-glog/issues/detail?id=33">
+this issue</a> for more detail.
+
<hr>
<address>
Shinichiro Hamaji<br>