glog.html 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>How To Use Google Logging Library (glog)</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <link href="http://www.google.com/favicon.ico" type="image/x-icon"
  7. rel="shortcut icon">
  8. <link href="designstyle.css" type="text/css" rel="stylesheet">
  9. <style type="text/css">
  10. <!--
  11. ol.bluelist li {
  12. color: #3366ff;
  13. font-family: sans-serif;
  14. }
  15. ol.bluelist li p {
  16. color: #000;
  17. font-family: "Times Roman", times, serif;
  18. }
  19. ul.blacklist li {
  20. color: #000;
  21. font-family: "Times Roman", times, serif;
  22. }
  23. //-->
  24. </style>
  25. </head>
  26. <body>
  27. <h1>How To Use Google Logging Library (glog)</h1>
  28. <small>(as of
  29. <script type=text/javascript>
  30. var lm = new Date(document.lastModified);
  31. document.write(lm.toDateString());
  32. </script>)
  33. </small>
  34. <br>
  35. <h2> <A NAME=intro>Introduction</A> </h2>
  36. <p><b>Google glog</b> is a library that implements application-level
  37. logging. This library provides logging APIs based on C++-style
  38. streams and various helper macros.
  39. You can log a message by simply streaming things to LOG(&lt;a
  40. particular <a href="#severity">severity level</a>&gt;), e.g.
  41. <pre>
  42. #include &lt;glog/logging.h&gt;
  43. int main(int argc, char* argv[]) {
  44. // Initialize Google's logging library.
  45. google::InitGoogleLogging(argv[0]);
  46. // ...
  47. LOG(INFO) &lt;&lt; "Found " &lt;&lt; num_cookies &lt;&lt; " cookies";
  48. }
  49. </pre>
  50. <p>Google glog defines a series of macros that simplify many common logging
  51. tasks. You can log messages by severity level, control logging
  52. behavior from the command line, log based on conditionals, abort the
  53. program when expected conditions are not met, introduce your own
  54. verbose logging levels, and more. This document describes the
  55. functionality supported by glog. Please note that this document
  56. doesn't describe all features in this library, but the most useful
  57. ones. If you want to find less common features, please check
  58. header files under <code>src/glog</code> directory.
  59. <h2> <A NAME=severity>Severity Level</A> </h2>
  60. <p>
  61. You can specify one of the following severity levels (in
  62. increasing order of severity): <code>INFO</code>, <code>WARNING</code>,
  63. <code>ERROR</code>, and <code>FATAL</code>.
  64. Logging a <code>FATAL</code> message terminates the program (after the
  65. message is logged).
  66. Note that messages of a given severity are logged not only in the
  67. logfile for that severity, but also in all logfiles of lower severity.
  68. E.g., a message of severity <code>FATAL</code> will be logged to the
  69. logfiles of severity <code>FATAL</code>, <code>ERROR</code>,
  70. <code>WARNING</code>, and <code>INFO</code>.
  71. <p>
  72. The <code>DFATAL</code> severity logs a <code>FATAL</code> error in
  73. debug mode (i.e., there is no <code>NDEBUG</code> macro defined), but
  74. avoids halting the program in production by automatically reducing the
  75. severity to <code>ERROR</code>.
  76. <p>Unless otherwise specified, glog writes to the filename
  77. "/tmp/&lt;program name&gt;.&lt;hostname&gt;.&lt;user name&gt;.log.&lt;severity level&gt;.&lt;date&gt;.&lt;time&gt;.&lt;pid&gt;"
  78. (e.g., "/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474").
  79. By default, glog copies the log messages of severity level
  80. <code>ERROR</code> or <code>FATAL</code> to standard error (stderr)
  81. in addition to log files.
  82. <h2><A NAME=flags>Setting Flags</A></h2>
  83. <p>Several flags influence glog's output behavior.
  84. If the <a href="http://code.google.com/p/google-gflags/">Google
  85. gflags library</a> is installed on your machine, the
  86. <code>configure</code> script (see the INSTALL file in the package for
  87. detail of this script) will automatically detect and use it,
  88. allowing you to pass flags on the command line. For example, if you
  89. want to turn the flag <code>--logtostderr</code> on, you can start
  90. your application with the following command line:
  91. <pre>
  92. ./your_application --logtostderr=1
  93. </pre>
  94. If the Google gflags library isn't installed, you set flags via
  95. environment variables, prefixing the flag name with "GLOG_", e.g.
  96. <pre>
  97. GLOG_logtostderr=1 ./your_application
  98. </pre>
  99. <!-- TODO(hamaji): Fill the version number
  100. <p>By glog version 0.x.x, you can use GLOG_* environment variables
  101. even if you have gflags. If both an environment variable and a flag
  102. are specified, the value specified by a flag wins. E.g., if GLOG_v=0
  103. and --v=1, the verbosity will be 1, not 0.
  104. -->
  105. <p>The following flags are most commonly used:
  106. <dl>
  107. <dt><code>logtostderr</code> (<code>bool</code>, default=<code>false</code>)
  108. <dd>Log messages to stderr instead of logfiles.<br>
  109. Note: you can set binary flags to <code>true</code> by specifying
  110. <code>1</code>, <code>true</code>, or <code>yes</code> (case
  111. insensitive).
  112. Also, you can set binary flags to <code>false</code> by specifying
  113. <code>0</code>, <code>false</code>, or <code>no</code> (again, case
  114. insensitive).
  115. <dt><code>stderrthreshold</code> (<code>int</code>, default=2, which
  116. is <code>ERROR</code>)
  117. <dd>Copy log messages at or above this level to stderr in
  118. addition to logfiles. The numbers of severity levels
  119. <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>, and
  120. <code>FATAL</code> are 0, 1, 2, and 3, respectively.
  121. <dt><code>minloglevel</code> (<code>int</code>, default=0, which
  122. is <code>INFO</code>)
  123. <dd>Log messages at or above this level. Again, the numbers of
  124. severity levels <code>INFO</code>, <code>WARNING</code>,
  125. <code>ERROR</code>, and <code>FATAL</code> are 0, 1, 2, and 3,
  126. respectively.
  127. <dt><code>log_dir</code> (<code>string</code>, default="")
  128. <dd>If specified, logfiles are written into this directory instead
  129. of the default logging directory.
  130. <dt><code>v</code> (<code>int</code>, default=0)
  131. <dd>Show all <code>VLOG(m)</code> messages for <code>m</code> less or
  132. equal the value of this flag. Overridable by --vmodule.
  133. See <a href="#verbose">the section about verbose logging</a> for more
  134. detail.
  135. <dt><code>vmodule</code> (<code>string</code>, default="")
  136. <dd>Per-module verbose level. The argument has to contain a
  137. comma-separated list of &lt;module name&gt;=&lt;log level&gt;.
  138. &lt;module name&gt;
  139. is a glob pattern (e.g., <code>gfs*</code> for all modules whose name
  140. starts with "gfs"), matched against the filename base
  141. (that is, name ignoring .cc/.h./-inl.h).
  142. &lt;log level&gt; overrides any value given by --v.
  143. See also <a href="#verbose">the section about verbose logging</a>.
  144. </dl>
  145. <p>There are some other flags defined in logging.cc. Please grep the
  146. source code for "DEFINE_" to see a complete list of all flags.
  147. <p>You can also modify flag values in your program by modifying global
  148. variables <code>FLAGS_*</code> . Most settings start working
  149. immediately after you update <code>FLAGS_*</code> . The exceptions are
  150. the flags related to destination files. For example, you might want to
  151. set <code>FLAGS_log_dir</code> before
  152. calling <code>google::InitGoogleLogging</code> . Here is an example:
  153. <pre>
  154. LOG(INFO) << "file";
  155. // Most flags work immediately after updating values.
  156. FLAGS_logtostderr = 1;
  157. LOG(INFO) << "stderr";
  158. FLAGS_logtostderr = 0;
  159. // This won't change the log destination. If you want to set this
  160. // value, you should do this before google::InitGoogleLogging .
  161. FLAGS_log_dir = "/some/log/directory";
  162. LOG(INFO) << "the same file";
  163. </pre>
  164. <h2><A NAME=conditional>Conditional / Occasional Logging</A></h2>
  165. <p>Sometimes, you may only want to log a message under certain
  166. conditions. You can use the following macros to perform conditional
  167. logging:
  168. <pre>
  169. LOG_IF(INFO, num_cookies &gt; 10) &lt;&lt; "Got lots of cookies";
  170. </pre>
  171. The "Got lots of cookies" message is logged only when the variable
  172. <code>num_cookies</code> exceeds 10.
  173. If a line of code is executed many times, it may be useful to only log
  174. a message at certain intervals. This kind of logging is most useful
  175. for informational messages.
  176. <pre>
  177. LOG_EVERY_N(INFO, 10) &lt;&lt; "Got the " &lt;&lt; google::COUNTER &lt;&lt; "th cookie";
  178. </pre>
  179. <p>The above line outputs a log messages on the 1st, 11th,
  180. 21st, ... times it is executed. Note that the special
  181. <code>google::COUNTER</code> value is used to identify which repetition is
  182. happening.
  183. <p>You can combine conditional and occasional logging with the
  184. following macro.
  185. <pre>
  186. LOG_IF_EVERY_N(INFO, (size &gt; 1024), 10) &lt;&lt; "Got the " &lt;&lt; google::COUNTER
  187. &lt;&lt; "th big cookie";
  188. </pre>
  189. <p>Instead of outputting a message every nth time, you can also limit
  190. the output to the first n occurrences:
  191. <pre>
  192. LOG_FIRST_N(INFO, 20) &lt;&lt; "Got the " &lt;&lt; google::COUNTER &lt;&lt; "th cookie";
  193. </pre>
  194. <p>Outputs log messages for the first 20 times it is executed. Again,
  195. the <code>google::COUNTER</code> identifier indicates which repetition is
  196. happening.
  197. <h2><A NAME=debug>Debug Mode Support</A></h2>
  198. <p>Special "debug mode" logging macros only have an effect in debug
  199. mode and are compiled away to nothing for non-debug mode
  200. compiles. Use these macros to avoid slowing down your production
  201. application due to excessive logging.
  202. <pre>
  203. DLOG(INFO) &lt;&lt; "Found cookies";
  204. DLOG_IF(INFO, num_cookies &gt; 10) &lt;&lt; "Got lots of cookies";
  205. DLOG_EVERY_N(INFO, 10) &lt;&lt; "Got the " &lt;&lt; google::COUNTER &lt;&lt; "th cookie";
  206. </pre>
  207. <h2><A NAME=check>CHECK Macros</A></h2>
  208. <p>It is a good practice to check expected conditions in your program
  209. frequently to detect errors as early as possible. The
  210. <code>CHECK</code> macro provides the ability to abort the application
  211. when a condition is not met, similar to the <code>assert</code> macro
  212. defined in the standard C library.
  213. <p><code>CHECK</code> aborts the application if a condition is not
  214. true. Unlike <code>assert</code>, it is *not* controlled by
  215. <code>NDEBUG</code>, so the check will be executed regardless of
  216. compilation mode. Therefore, <code>fp-&gt;Write(x)</code> in the
  217. following example is always executed:
  218. <pre>
  219. CHECK(fp-&gt;Write(x) == 4) &lt;&lt; "Write failed!";
  220. </pre>
  221. <p>There are various helper macros for
  222. equality/inequality checks - <code>CHECK_EQ</code>,
  223. <code>CHECK_NE</code>, <code>CHECK_LE</code>, <code>CHECK_LT</code>,
  224. <code>CHECK_GE</code>, and <code>CHECK_GT</code>.
  225. They compare two values, and log a
  226. <code>FATAL</code> message including the two values when the result is
  227. not as expected. The values must have <code>operator&lt;&lt;(ostream,
  228. ...)</code> defined.
  229. <p>You may append to the error message like so:
  230. <pre>
  231. CHECK_NE(1, 2) &lt;&lt; ": The world must be ending!";
  232. </pre>
  233. <p>We are very careful to ensure that each argument is evaluated exactly
  234. once, and that anything which is legal to pass as a function argument is
  235. legal here. In particular, the arguments may be temporary expressions
  236. which will end up being destroyed at the end of the apparent statement,
  237. for example:
  238. <pre>
  239. CHECK_EQ(string("abc")[1], 'b');
  240. </pre>
  241. <p>The compiler reports an error if one of the arguments is a
  242. pointer and the other is NULL. To work around this, simply static_cast
  243. NULL to the type of the desired pointer.
  244. <pre>
  245. CHECK_EQ(some_ptr, static_cast&lt;SomeType*&gt;(NULL));
  246. </pre>
  247. <p>Better yet, use the CHECK_NOTNULL macro:
  248. <pre>
  249. CHECK_NOTNULL(some_ptr);
  250. some_ptr-&gt;DoSomething();
  251. </pre>
  252. <p>Since this macro returns the given pointer, this is very useful in
  253. constructor initializer lists.
  254. <pre>
  255. struct S {
  256. S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
  257. Something* ptr_;
  258. };
  259. </pre>
  260. <p>Note that you cannot use this macro as a C++ stream due to this
  261. feature. Please use <code>CHECK_EQ</code> described above to log a
  262. custom message before aborting the application.
  263. <p>If you are comparing C strings (char *), a handy set of macros
  264. performs case sensitive as well as case insensitive comparisons -
  265. <code>CHECK_STREQ</code>, <code>CHECK_STRNE</code>,
  266. <code>CHECK_STRCASEEQ</code>, and <code>CHECK_STRCASENE</code>. The
  267. CASE versions are case-insensitive. You can safely pass <code>NULL</code>
  268. pointers for this macro. They treat <code>NULL</code> and any
  269. non-<code>NULL</code> string as not equal. Two <code>NULL</code>s are
  270. equal.
  271. <p>Note that both arguments may be temporary strings which are
  272. destructed at the end of the current "full expression"
  273. (e.g., <code>CHECK_STREQ(Foo().c_str(), Bar().c_str())</code> where
  274. <code>Foo</code> and <code>Bar</code> return C++'s
  275. <code>std::string</code>).
  276. <p>The <code>CHECK_DOUBLE_EQ</code> macro checks the equality of two
  277. floating point values, accepting a small error margin.
  278. <code>CHECK_NEAR</code> accepts a third floating point argument, which
  279. specifies the acceptable error margin.
  280. <h2><A NAME=verbose>Verbose Logging</A></h2>
  281. <p>When you are chasing difficult bugs, thorough log messages are very
  282. useful. However, you may want to ignore too verbose messages in usual
  283. development. For such verbose logging, glog provides the
  284. <code>VLOG</code> macro, which allows you to define your own numeric
  285. logging levels. The <code>--v</code> command line option controls
  286. which verbose messages are logged:
  287. <pre>
  288. VLOG(1) &lt;&lt; "I'm printed when you run the program with --v=1 or higher";
  289. VLOG(2) &lt;&lt; "I'm printed when you run the program with --v=2 or higher";
  290. </pre>
  291. <p>With <code>VLOG</code>, the lower the verbose level, the more
  292. likely messages are to be logged. For example, if
  293. <code>--v==1</code>, <code>VLOG(1)</code> will log, but
  294. <code>VLOG(2)</code> will not log. This is opposite of the severity
  295. level, where <code>INFO</code> is 0, and <code>ERROR</code> is 2.
  296. <code>--minloglevel</code> of 1 will log <code>WARNING</code> and
  297. above. Though you can specify any integers for both <code>VLOG</code>
  298. macro and <code>--v</code> flag, the common values for them are small
  299. positive integers. For example, if you write <code>VLOG(0)</code>,
  300. you should specify <code>--v=-1</code> or lower to silence it. This
  301. is less useful since we may not want verbose logs by default in most
  302. cases. The <code>VLOG</code> macros always log at the
  303. <code>INFO</code> log level (when they log at all).
  304. <p>Verbose logging can be controlled from the command line on a
  305. per-module basis:
  306. <pre>
  307. --vmodule=mapreduce=2,file=1,gfs*=3 --v=0
  308. </pre>
  309. <p>will:
  310. <ul>
  311. <li>a. Print VLOG(2) and lower messages from mapreduce.{h,cc}
  312. <li>b. Print VLOG(1) and lower messages from file.{h,cc}
  313. <li>c. Print VLOG(3) and lower messages from files prefixed with "gfs"
  314. <li>d. Print VLOG(0) and lower messages from elsewhere
  315. </ul>
  316. <p>The wildcarding functionality shown by (c) supports both '*'
  317. (matches 0 or more characters) and '?' (matches any single character)
  318. wildcards. Please also check the section about <a
  319. href="#flags">command line flags</a>.
  320. <p>There's also <code>VLOG_IS_ON(n)</code> "verbose level" condition
  321. macro. This macro returns true when the <code>--v</code> is equal or
  322. greater than <code>n</code>. To be used as
  323. <pre>
  324. if (VLOG_IS_ON(2)) {
  325. // do some logging preparation and logging
  326. // that can't be accomplished with just VLOG(2) &lt;&lt; ...;
  327. }
  328. </pre>
  329. <p>Verbose level condition macros <code>VLOG_IF</code>,
  330. <code>VLOG_EVERY_N</code> and <code>VLOG_IF_EVERY_N</code> behave
  331. analogous to <code>LOG_IF</code>, <code>LOG_EVERY_N</code>,
  332. <code>LOF_IF_EVERY</code>, but accept a numeric verbosity level as
  333. opposed to a severity level.
  334. <pre>
  335. VLOG_IF(1, (size &gt; 1024))
  336. &lt;&lt; "I'm printed when size is more than 1024 and when you run the "
  337. "program with --v=1 or more";
  338. VLOG_EVERY_N(1, 10)
  339. &lt;&lt; "I'm printed every 10th occurrence, and when you run the program "
  340. "with --v=1 or more. Present occurence is " &lt;&lt; google::COUNTER;
  341. VLOG_IF_EVERY_N(1, (size &gt; 1024), 10)
  342. &lt;&lt; "I'm printed on every 10th occurence of case when size is more "
  343. " than 1024, when you run the program with --v=1 or more. ";
  344. "Present occurence is " &lt;&lt; google::COUNTER;
  345. </pre>
  346. <h2> <A name="signal">Failure Signal Handler</A> </h2>
  347. <p>
  348. The library provides a convenient signal handler that will dump useful
  349. information when the program crashes on certain signals such as SIGSEGV.
  350. The signal handler can be installed by
  351. google::InstallFailureSignalHandler(). The following is an example of output
  352. from the signal handler.
  353. <pre>
  354. *** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date ***
  355. *** SIGSEGV (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: ***
  356. PC: @ 0x412eb1 TestWaitingLogSink::send()
  357. @ 0x7f892fb417d0 (unknown)
  358. @ 0x412eb1 TestWaitingLogSink::send()
  359. @ 0x7f89304f7f06 google::LogMessage::SendToLog()
  360. @ 0x7f89304f35af google::LogMessage::Flush()
  361. @ 0x7f89304f3739 google::LogMessage::~LogMessage()
  362. @ 0x408cf4 TestLogSinkWaitTillSent()
  363. @ 0x4115de main
  364. @ 0x7f892f7ef1c4 (unknown)
  365. @ 0x4046f9 (unknown)
  366. </pre>
  367. <p>
  368. By default, the signal handler writes the failure dump to the standard
  369. error. You can customize the destination by InstallFailureWriter().
  370. <h2> <A name="misc">Miscellaneous Notes</A> </h2>
  371. <h3><A NAME=message>Performance of Messages</A></h3>
  372. <p>The conditional logging macros provided by glog (e.g.,
  373. <code>CHECK</code>, <code>LOG_IF</code>, <code>VLOG</code>, ...) are
  374. carefully implemented and don't execute the right hand side
  375. expressions when the conditions are false. So, the following check
  376. may not sacrifice the performance of your application.
  377. <pre>
  378. CHECK(obj.ok) &lt;&lt; obj.CreatePrettyFormattedStringButVerySlow();
  379. </pre>
  380. <h3><A NAME=failure>User-defined Failure Function</A></h3>
  381. <p><code>FATAL</code> severity level messages or unsatisfied
  382. <code>CHECK</code> condition terminate your program. You can change
  383. the behavior of the termination by
  384. <code>InstallFailureFunction</code>.
  385. <pre>
  386. void YourFailureFunction() {
  387. // Reports something...
  388. exit(1);
  389. }
  390. int main(int argc, char* argv[]) {
  391. google::InstallFailureFunction(&amp;YourFailureFunction);
  392. }
  393. </pre>
  394. <p>By default, glog tries to dump stacktrace and makes the program
  395. exit with status 1. The stacktrace is produced only when you run the
  396. program on an architecture for which glog supports stack tracing (as
  397. of September 2008, glog supports stack tracing for x86 and x86_64).
  398. <h3><A NAME=raw>Raw Logging</A></h3>
  399. <p>The header file <code>&lt;glog/raw_logging.h&gt;</code> can be
  400. used for thread-safe logging, which does not allocate any memory or
  401. acquire any locks. Therefore, the macros defined in this
  402. header file can be used by low-level memory allocation and
  403. synchronization code.
  404. Please check <code>src/glog/raw_logging.h.in</code> for detail.
  405. </p>
  406. <h3><A NAME=plog>Google Style perror()</A></h3>
  407. <p><code>PLOG()</code> and <code>PLOG_IF()</code> and
  408. <code>PCHECK()</code> behave exactly like their <code>LOG*</code> and
  409. <code>CHECK</code> equivalents with the addition that they append a
  410. description of the current state of errno to their output lines.
  411. E.g.
  412. <pre>
  413. PCHECK(write(1, NULL, 2) &gt;= 0) &lt;&lt; "Write NULL failed";
  414. </pre>
  415. <p>This check fails with the following error message.
  416. <pre>
  417. F0825 185142 test.cc:22] Check failed: write(1, NULL, 2) &gt;= 0 Write NULL failed: Bad address [14]
  418. </pre>
  419. <h3><A NAME=syslog>Syslog</A></h3>
  420. <p><code>SYSLOG</code>, <code>SYSLOG_IF</code>, and
  421. <code>SYSLOG_EVERY_N</code> macros are available.
  422. These log to syslog in addition to the normal logs. Be aware that
  423. logging to syslog can drastically impact performance, especially if
  424. syslog is configured for remote logging! Make sure you understand the
  425. implications of outputting to syslog before you use these macros. In
  426. general, it's wise to use these macros sparingly.
  427. <h3><A NAME=strip>Strip Logging Messages</A></h3>
  428. <p>Strings used in log messages can increase the size of your binary
  429. and present a privacy concern. You can therefore instruct glog to
  430. remove all strings which fall below a certain severity level by using
  431. the GOOGLE_STRIP_LOG macro:
  432. <p>If your application has code like this:
  433. <pre>
  434. #define GOOGLE_STRIP_LOG 1 // this must go before the #include!
  435. #include &lt;glog/logging.h&gt;
  436. </pre>
  437. <p>The compiler will remove the log messages whose severities are less
  438. than the specified integer value. Since
  439. <code>VLOG</code> logs at the severity level <code>INFO</code>
  440. (numeric value <code>0</code>),
  441. setting <code>GOOGLE_STRIP_LOG</code> to 1 or greater removes
  442. all log messages associated with <code>VLOG</code>s as well as
  443. <code>INFO</code> log statements.
  444. <h3><A NAME=windows>Notes for Windows users</A></h3>
  445. <p>Google glog defines a severity level <code>ERROR</code>, which is
  446. also defined in <code>windows.h</code> . You can make glog not define
  447. <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
  448. and <code>FATAL</code> by defining
  449. <code>GLOG_NO_ABBREVIATED_SEVERITIES</code> before
  450. including <code>glog/logging.h</code> . Even with this macro, you can
  451. still use the iostream like logging facilities:
  452. <pre>
  453. #define GLOG_NO_ABBREVIATED_SEVERITIES
  454. #include &lt;windows.h&gt;
  455. #include &lt;glog/logging.h&gt;
  456. // ...
  457. LOG(ERROR) &lt;&lt; "This should work";
  458. LOG_IF(ERROR, x &gt; y) &lt;&lt; "This should be also OK";
  459. </pre>
  460. <p>
  461. However, you cannot
  462. use <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
  463. and <code>FATAL</code> anymore for functions defined
  464. in <code>glog/logging.h</code> .
  465. <pre>
  466. #define GLOG_NO_ABBREVIATED_SEVERITIES
  467. #include &lt;windows.h&gt;
  468. #include &lt;glog/logging.h&gt;
  469. // ...
  470. // This won't work.
  471. // google::FlushLogFiles(google::ERROR);
  472. // Use this instead.
  473. google::FlushLogFiles(google::GLOG_ERROR);
  474. </pre>
  475. <p>
  476. If you don't need <code>ERROR</code> defined
  477. by <code>windows.h</code>, there are a couple of more workarounds
  478. which sometimes don't work:
  479. <ul>
  480. <li>#define <code>WIN32_LEAN_AND_MEAN</code> or <code>NOGDI</code>
  481. <strong>before</strong> you #include <code>windows.h</code> .
  482. <li>#undef <code>ERROR</code> <strong>after</strong> you #include
  483. <code>windows.h</code> .
  484. </ul>
  485. <p>See <a href="http://code.google.com/p/google-glog/issues/detail?id=33">
  486. this issue</a> for more detail.
  487. <hr>
  488. <address>
  489. Shinichiro Hamaji<br>
  490. Gregor Hohpe<br>
  491. <script type=text/javascript>
  492. var lm = new Date(document.lastModified);
  493. document.write(lm.toDateString());
  494. </script>
  495. </address>
  496. </body>
  497. </html>