toolkit/crashreporter/google-breakpad/src/third_party/glog/doc/glog.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/crashreporter/google-breakpad/src/third_party/glog/doc/glog.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,554 @@
     1.4 +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
     1.5 +
     1.6 +<html>
     1.7 +<head>
     1.8 +<title>How To Use Google Logging Library (glog)</title>
     1.9 +
    1.10 +<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    1.11 +<link href="http://www.google.com/favicon.ico" type="image/x-icon"
    1.12 +      rel="shortcut icon">
    1.13 +<link href="designstyle.css" type="text/css" rel="stylesheet">
    1.14 +<style type="text/css">
    1.15 +<!--
    1.16 +  ol.bluelist li {
    1.17 +    color: #3366ff;
    1.18 +    font-family: sans-serif;
    1.19 +  }
    1.20 +  ol.bluelist li p {
    1.21 +    color: #000;
    1.22 +    font-family: "Times Roman", times, serif;
    1.23 +  }
    1.24 +  ul.blacklist li {
    1.25 +    color: #000;
    1.26 +    font-family: "Times Roman", times, serif;
    1.27 +  }
    1.28 +//-->
    1.29 +</style>
    1.30 +</head>
    1.31 +
    1.32 +<body>
    1.33 +
    1.34 +<h1>How To Use Google Logging Library (glog)</h1>
    1.35 +<small>(as of
    1.36 +<script type=text/javascript>
    1.37 +  var lm = new Date(document.lastModified);
    1.38 +  document.write(lm.toDateString());
    1.39 +</script>)
    1.40 +</small>
    1.41 +<br>
    1.42 +
    1.43 +<h2> <A NAME=intro>Introduction</A> </h2>
    1.44 +
    1.45 +<p><b>Google glog</b> is a library that implements application-level
    1.46 +logging.  This library provides logging APIs based on C++-style
    1.47 +streams and various helper macros.
    1.48 +You can log a message by simply streaming things to LOG(&lt;a
    1.49 +particular <a href="#severity">severity level</a>&gt;), e.g.
    1.50 +
    1.51 +<pre>
    1.52 +   #include &lt;glog/logging.h&gt;
    1.53 +
    1.54 +   int main(int argc, char* argv[]) {
    1.55 +     // Initialize Google's logging library.
    1.56 +     google::InitGoogleLogging(argv[0]);
    1.57 +
    1.58 +     // ...
    1.59 +     LOG(INFO) &lt;&lt; "Found " &lt;&lt; num_cookies &lt;&lt; " cookies";
    1.60 +   }
    1.61 +</pre>
    1.62 +
    1.63 +<p>Google glog defines a series of macros that simplify many common logging
    1.64 +tasks.  You can log messages by severity level, control logging
    1.65 +behavior from the command line, log based on conditionals, abort the
    1.66 +program when expected conditions are not met, introduce your own
    1.67 +verbose logging levels, and more.  This document describes the
    1.68 +functionality supported by glog.  Please note that this document
    1.69 +doesn't describe all features in this library, but the most useful
    1.70 +ones.  If you want to find less common features, please check
    1.71 +header files under <code>src/glog</code> directory.
    1.72 +
    1.73 +<h2> <A NAME=severity>Severity Level</A> </h2>
    1.74 +
    1.75 +<p>
    1.76 +You can specify one of the following severity levels (in
    1.77 +increasing order of severity): <code>INFO</code>, <code>WARNING</code>,
    1.78 +<code>ERROR</code>, and <code>FATAL</code>.
    1.79 +Logging a <code>FATAL</code> message terminates the program (after the
    1.80 +message is logged).
    1.81 +Note that messages of a given severity are logged not only in the
    1.82 +logfile for that severity, but also in all logfiles of lower severity.
    1.83 +E.g., a message of severity <code>FATAL</code> will be logged to the
    1.84 +logfiles of severity <code>FATAL</code>, <code>ERROR</code>,
    1.85 +<code>WARNING</code>, and <code>INFO</code>.
    1.86 +
    1.87 +<p>
    1.88 +The <code>DFATAL</code> severity logs a <code>FATAL</code> error in
    1.89 +debug mode (i.e., there is no <code>NDEBUG</code> macro defined), but
    1.90 +avoids halting the program in production by automatically reducing the
    1.91 +severity to <code>ERROR</code>.
    1.92 +
    1.93 +<p>Unless otherwise specified, glog writes to the filename
    1.94 +"/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;"
    1.95 +(e.g., "/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474").
    1.96 +By default, glog copies the log messages of severity level
    1.97 +<code>ERROR</code> or <code>FATAL</code> to standard error (stderr)
    1.98 +in addition to log files.
    1.99 +
   1.100 +<h2><A NAME=flags>Setting Flags</A></h2>
   1.101 +
   1.102 +<p>Several flags influence glog's output behavior.
   1.103 +If the <a href="http://code.google.com/p/google-gflags/">Google
   1.104 +gflags library</a> is installed on your machine, the
   1.105 +<code>configure</code> script (see the INSTALL file in the package for
   1.106 +detail of this script) will automatically detect and use it,
   1.107 +allowing you to pass flags on the command line.  For example, if you
   1.108 +want to turn the flag <code>--logtostderr</code> on, you can start
   1.109 +your application with the following command line:
   1.110 +
   1.111 +<pre>
   1.112 +   ./your_application --logtostderr=1
   1.113 +</pre>
   1.114 +
   1.115 +If the Google gflags library isn't installed, you set flags via
   1.116 +environment variables, prefixing the flag name with "GLOG_", e.g.
   1.117 +
   1.118 +<pre>
   1.119 +   GLOG_logtostderr=1 ./your_application
   1.120 +</pre>
   1.121 +
   1.122 +<!-- TODO(hamaji): Fill the version number
   1.123 +<p>By glog version 0.x.x, you can use GLOG_* environment variables
   1.124 +even if you have gflags. If both an environment variable and a flag
   1.125 +are specified, the value specified by a flag wins. E.g., if GLOG_v=0
   1.126 +and --v=1, the verbosity will be 1, not 0.
   1.127 +-->
   1.128 +
   1.129 +<p>The following flags are most commonly used:
   1.130 +
   1.131 +<dl>
   1.132 +<dt><code>logtostderr</code> (<code>bool</code>, default=<code>false</code>)
   1.133 +<dd>Log messages to stderr instead of logfiles.<br>
   1.134 +Note: you can set binary flags to <code>true</code> by specifying
   1.135 +<code>1</code>, <code>true</code>, or <code>yes</code> (case
   1.136 +insensitive).
   1.137 +Also, you can set binary flags to <code>false</code> by specifying
   1.138 +<code>0</code>, <code>false</code>, or <code>no</code> (again, case
   1.139 +insensitive).
   1.140 +<dt><code>stderrthreshold</code> (<code>int</code>, default=2, which
   1.141 +is <code>ERROR</code>)
   1.142 +<dd>Copy log messages at or above this level to stderr in
   1.143 +addition to logfiles.  The numbers of severity levels
   1.144 +<code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>, and
   1.145 +<code>FATAL</code> are 0, 1, 2, and 3, respectively.
   1.146 +<dt><code>minloglevel</code> (<code>int</code>, default=0, which
   1.147 +is <code>INFO</code>)
   1.148 +<dd>Log messages at or above this level.  Again, the numbers of
   1.149 +severity levels <code>INFO</code>, <code>WARNING</code>,
   1.150 +<code>ERROR</code>, and <code>FATAL</code> are 0, 1, 2, and 3,
   1.151 +respectively.
   1.152 +<dt><code>log_dir</code> (<code>string</code>, default="")
   1.153 +<dd>If specified, logfiles are written into this directory instead
   1.154 +of the default logging directory.
   1.155 +<dt><code>v</code> (<code>int</code>, default=0)
   1.156 +<dd>Show all <code>VLOG(m)</code> messages for <code>m</code> less or
   1.157 +equal the value of this flag.  Overridable by --vmodule.
   1.158 +See <a href="#verbose">the section about verbose logging</a> for more
   1.159 +detail.
   1.160 +<dt><code>vmodule</code> (<code>string</code>, default="")
   1.161 +<dd>Per-module verbose level.  The argument has to contain a
   1.162 +comma-separated list of &lt;module name&gt;=&lt;log level&gt;.
   1.163 +&lt;module name&gt;
   1.164 +is a glob pattern (e.g., <code>gfs*</code> for all modules whose name
   1.165 +starts with "gfs"), matched against the filename base
   1.166 +(that is, name ignoring .cc/.h./-inl.h).
   1.167 +&lt;log level&gt; overrides any value given by --v.
   1.168 +See also <a href="#verbose">the section about verbose logging</a>.
   1.169 +</dl>
   1.170 +
   1.171 +<p>There are some other flags defined in logging.cc.  Please grep the
   1.172 +source code for "DEFINE_" to see a complete list of all flags.
   1.173 +
   1.174 +<h2><A NAME=conditional>Conditional / Occasional Logging</A></h2>
   1.175 +
   1.176 +<p>Sometimes, you may only want to log a message under certain
   1.177 +conditions. You can use the following macros to perform conditional
   1.178 +logging:
   1.179 +
   1.180 +<pre>
   1.181 +   LOG_IF(INFO, num_cookies &gt; 10) &lt;&lt; "Got lots of cookies";
   1.182 +</pre>
   1.183 +
   1.184 +The "Got lots of cookies" message is logged only when the variable
   1.185 +<code>num_cookies</code> exceeds 10.
   1.186 +
   1.187 +If a line of code is executed many times, it may be useful to only log
   1.188 +a message at certain intervals.  This kind of logging is most useful
   1.189 +for informational messages.
   1.190 +
   1.191 +<pre>
   1.192 +   LOG_EVERY_N(INFO, 10) &lt;&lt; "Got the " &lt;&lt; google::COUNTER &lt;&lt; "th cookie";
   1.193 +</pre>
   1.194 +
   1.195 +<p>The above line outputs a log messages on the 1st, 11th,
   1.196 +21st, ... times it is executed.  Note that the special
   1.197 +<code>google::COUNTER</code> value is used to identify which repetition is
   1.198 +happening.
   1.199 +
   1.200 +<p>You can combine conditional and occasional logging with the
   1.201 +following macro.
   1.202 +
   1.203 +<pre>
   1.204 +   LOG_IF_EVERY_N(INFO, (size &gt; 1024), 10) &lt;&lt; "Got the " &lt;&lt; google::COUNTER
   1.205 +                                           &lt;&lt; "th big cookie";
   1.206 +</pre>
   1.207 +
   1.208 +<p>Instead of outputting a message every nth time, you can also limit
   1.209 +the output to the first n occurrences:
   1.210 +
   1.211 +<pre>
   1.212 +   LOG_FIRST_N(INFO, 20) &lt;&lt; "Got the " &lt;&lt; google::COUNTER &lt;&lt; "th cookie";
   1.213 +</pre>
   1.214 +
   1.215 +<p>Outputs log messages for the first 20 times it is executed.  Again,
   1.216 +the <code>google::COUNTER</code> identifier indicates which repetition is
   1.217 +happening.
   1.218 +
   1.219 +<h2><A NAME=debug>Debug Mode Support</A></h2>
   1.220 +
   1.221 +<p>Special "debug mode" logging macros only have an effect in debug
   1.222 +mode and are compiled away to nothing for non-debug mode
   1.223 +compiles.  Use these macros to avoid slowing down your production
   1.224 +application due to excessive logging.
   1.225 +
   1.226 +<pre>
   1.227 +   DLOG(INFO) &lt;&lt; "Found cookies";
   1.228 +
   1.229 +   DLOG_IF(INFO, num_cookies &gt; 10) &lt;&lt; "Got lots of cookies";
   1.230 +
   1.231 +   DLOG_EVERY_N(INFO, 10) &lt;&lt; "Got the " &lt;&lt; google::COUNTER &lt;&lt; "th cookie";
   1.232 +</pre>
   1.233 +
   1.234 +<h2><A NAME=check>CHECK Macros</A></h2>
   1.235 +
   1.236 +<p>It is a good practice to check expected conditions in your program
   1.237 +frequently to detect errors as early as possible. The
   1.238 +<code>CHECK</code> macro provides the ability to abort the application
   1.239 +when a condition is not met, similar to the <code>assert</code> macro
   1.240 +defined in the standard C library.
   1.241 +
   1.242 +<p><code>CHECK</code> aborts the application if a condition is not
   1.243 +true.  Unlike <code>assert</code>, it is *not* controlled by
   1.244 +<code>NDEBUG</code>, so the check will be executed regardless of
   1.245 +compilation mode.  Therefore, <code>fp-&gt;Write(x)</code> in the
   1.246 +following example is always executed:
   1.247 +
   1.248 +<pre>
   1.249 +   CHECK(fp-&gt;Write(x) == 4) &lt;&lt; "Write failed!";
   1.250 +</pre>
   1.251 +
   1.252 +<p>There are various helper macros for
   1.253 +equality/inequality checks - <code>CHECK_EQ</code>,
   1.254 +<code>CHECK_NE</code>, <code>CHECK_LE</code>, <code>CHECK_LT</code>,
   1.255 +<code>CHECK_GE</code>, and <code>CHECK_GT</code>.
   1.256 +They compare two values, and log a
   1.257 +<code>FATAL</code> message including the two values when the result is
   1.258 +not as expected.  The values must have <code>operator&lt;&lt;(ostream,
   1.259 +...)</code> defined.
   1.260 +
   1.261 +<p>You may append to the error message like so:
   1.262 +
   1.263 +<pre>
   1.264 +   CHECK_NE(1, 2) &lt;&lt; ": The world must be ending!";
   1.265 +</pre>
   1.266 +
   1.267 +<p>We are very careful to ensure that each argument is evaluated exactly
   1.268 +once, and that anything which is legal to pass as a function argument is
   1.269 +legal here.  In particular, the arguments may be temporary expressions
   1.270 +which will end up being destroyed at the end of the apparent statement,
   1.271 +for example:
   1.272 +
   1.273 +<pre>
   1.274 +   CHECK_EQ(string("abc")[1], 'b');
   1.275 +</pre>
   1.276 +
   1.277 +<p>The compiler reports an error if one of the arguments is a
   1.278 +pointer and the other is NULL. To work around this, simply static_cast
   1.279 +NULL to the type of the desired pointer.
   1.280 +
   1.281 +<pre>
   1.282 +   CHECK_EQ(some_ptr, static_cast&lt;SomeType*&gt;(NULL));
   1.283 +</pre>
   1.284 +
   1.285 +<p>Better yet, use the CHECK_NOTNULL macro:
   1.286 +
   1.287 +<pre>
   1.288 +   CHECK_NOTNULL(some_ptr);
   1.289 +   some_ptr-&gt;DoSomething();
   1.290 +</pre>
   1.291 +
   1.292 +<p>Since this macro returns the given pointer, this is very useful in
   1.293 +constructor initializer lists.
   1.294 +
   1.295 +<pre>
   1.296 +   struct S {
   1.297 +     S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
   1.298 +     Something* ptr_;
   1.299 +   };
   1.300 +</pre>
   1.301 +
   1.302 +<p>Note that you cannot use this macro as a C++ stream due to this
   1.303 +feature.  Please use <code>CHECK_EQ</code> described above to log a
   1.304 +custom message before aborting the application.
   1.305 +
   1.306 +<p>If you are comparing C strings (char *), a handy set of macros
   1.307 +performs case sensitive as well as case insensitive comparisons -
   1.308 +<code>CHECK_STREQ</code>, <code>CHECK_STRNE</code>,
   1.309 +<code>CHECK_STRCASEEQ</code>, and <code>CHECK_STRCASENE</code>.  The
   1.310 +CASE versions are case-insensitive.  You can safely pass <code>NULL</code>
   1.311 +pointers for this macro.  They treat <code>NULL</code> and any
   1.312 +non-<code>NULL</code> string as not equal.  Two <code>NULL</code>s are
   1.313 +equal.
   1.314 +
   1.315 +<p>Note that both arguments may be temporary strings which are
   1.316 +destructed at the end of the current "full expression"
   1.317 +(e.g., <code>CHECK_STREQ(Foo().c_str(), Bar().c_str())</code> where
   1.318 +<code>Foo</code> and <code>Bar</code> return C++'s
   1.319 +<code>std::string</code>).
   1.320 +
   1.321 +<p>The <code>CHECK_DOUBLE_EQ</code> macro checks the equality of two
   1.322 +floating point values, accepting a small error margin.
   1.323 +<code>CHECK_NEAR</code> accepts a third floating point argument, which
   1.324 +specifies the acceptable error margin.
   1.325 +
   1.326 +<h2><A NAME=verbose>Verbose Logging</A></h2>
   1.327 +
   1.328 +<p>When you are chasing difficult bugs, thorough log messages are very
   1.329 +useful.  However, you may want to ignore too verbose messages in usual
   1.330 +development.  For such verbose logging, glog provides the
   1.331 +<code>VLOG</code> macro, which allows you to define your own numeric
   1.332 +logging levels.  The <code>--v</code> command line option controls
   1.333 +which verbose messages are logged:
   1.334 +
   1.335 +<pre>
   1.336 +   VLOG(1) &lt;&lt; "I'm printed when you run the program with --v=1 or higher";
   1.337 +   VLOG(2) &lt;&lt; "I'm printed when you run the program with --v=2 or higher";
   1.338 +</pre>
   1.339 +
   1.340 +<p>With <code>VLOG</code>, the lower the verbose level, the more
   1.341 +likely messages are to be logged.  For example, if
   1.342 +<code>--v==1</code>, <code>VLOG(1)</code> will log, but
   1.343 +<code>VLOG(2)</code> will not log.  This is opposite of the severity
   1.344 +level, where <code>INFO</code> is 0, and <code>ERROR</code> is 2.
   1.345 +<code>--minloglevel</code> of 1 will log <code>WARNING</code> and
   1.346 +above.  Though you can specify any integers for both <code>VLOG</code>
   1.347 +macro and <code>--v</code> flag, the common values for them are small
   1.348 +positive integers.  For example, if you write <code>VLOG(0)</code>,
   1.349 +you should specify <code>--v=-1</code> or lower to silence it.  This
   1.350 +is less useful since we may not want verbose logs by default in most
   1.351 +cases.  The <code>VLOG</code> macros always log at the
   1.352 +<code>INFO</code> log level (when they log at all).
   1.353 +
   1.354 +<p>Verbose logging can be controlled from the command line on a
   1.355 +per-module basis:
   1.356 +
   1.357 +<pre>
   1.358 +   --vmodule=mapreduce=2,file=1,gfs*=3 --v=0
   1.359 +</pre>
   1.360 +
   1.361 +<p>will:
   1.362 +
   1.363 +<ul>
   1.364 +  <li>a. Print VLOG(2) and lower messages from mapreduce.{h,cc}
   1.365 +  <li>b. Print VLOG(1) and lower messages from file.{h,cc}
   1.366 +  <li>c. Print VLOG(3) and lower messages from files prefixed with "gfs"
   1.367 +  <li>d. Print VLOG(0) and lower messages from elsewhere
   1.368 +</ul>
   1.369 +
   1.370 +<p>The wildcarding functionality shown by (c) supports both '*'
   1.371 +(matches 0 or more characters) and '?' (matches any single character)
   1.372 +wildcards.  Please also check the section about <a
   1.373 +href="#flags">command line flags</a>.
   1.374 +
   1.375 +<p>There's also <code>VLOG_IS_ON(n)</code> "verbose level" condition
   1.376 +macro.  This macro returns true when the <code>--v</code> is equal or
   1.377 +greater than <code>n</code>.  To be used as
   1.378 +
   1.379 +<pre>
   1.380 +   if (VLOG_IS_ON(2)) {
   1.381 +     // do some logging preparation and logging
   1.382 +     // that can't be accomplished with just VLOG(2) &lt;&lt; ...;
   1.383 +   }
   1.384 +</pre>
   1.385 +
   1.386 +<p>Verbose level condition macros <code>VLOG_IF</code>,
   1.387 +<code>VLOG_EVERY_N</code> and <code>VLOG_IF_EVERY_N</code> behave
   1.388 +analogous to <code>LOG_IF</code>, <code>LOG_EVERY_N</code>,
   1.389 +<code>LOF_IF_EVERY</code>, but accept a numeric verbosity level as
   1.390 +opposed to a severity level.
   1.391 +
   1.392 +<pre>
   1.393 +   VLOG_IF(1, (size &gt; 1024))
   1.394 +      &lt;&lt; "I'm printed when size is more than 1024 and when you run the "
   1.395 +         "program with --v=1 or more";
   1.396 +   VLOG_EVERY_N(1, 10)
   1.397 +      &lt;&lt; "I'm printed every 10th occurrence, and when you run the program "
   1.398 +         "with --v=1 or more. Present occurence is " &lt;&lt; google::COUNTER;
   1.399 +   VLOG_IF_EVERY_N(1, (size &gt; 1024), 10)
   1.400 +      &lt;&lt; "I'm printed on every 10th occurence of case when size is more "
   1.401 +         " than 1024, when you run the program with --v=1 or more. ";
   1.402 +         "Present occurence is " &lt;&lt; google::COUNTER;
   1.403 +</pre>
   1.404 +
   1.405 +<h2> <A name="signal">Failure Signal Handler</A> </h2>
   1.406 +
   1.407 +<p>
   1.408 +The library provides a convenient signal handler that will dump useful
   1.409 +information when the program crashes on certain signals such as SIGSEGV.
   1.410 +The signal handler can be installed by
   1.411 +google::InstallFailureSignalHandler().  The following is an example of output
   1.412 +from the signal handler.
   1.413 +
   1.414 +<pre>
   1.415 +*** Aborted at 1225095260 (unix time) try "date -d @1225095260" if you are using GNU date ***
   1.416 +*** SIGSEGV (@0x0) received by PID 17711 (TID 0x7f893090a6f0) from PID 0; stack trace: ***
   1.417 +PC: @           0x412eb1 TestWaitingLogSink::send()
   1.418 +    @     0x7f892fb417d0 (unknown)
   1.419 +    @           0x412eb1 TestWaitingLogSink::send()
   1.420 +    @     0x7f89304f7f06 google::LogMessage::SendToLog()
   1.421 +    @     0x7f89304f35af google::LogMessage::Flush()
   1.422 +    @     0x7f89304f3739 google::LogMessage::~LogMessage()
   1.423 +    @           0x408cf4 TestLogSinkWaitTillSent()
   1.424 +    @           0x4115de main
   1.425 +    @     0x7f892f7ef1c4 (unknown)
   1.426 +    @           0x4046f9 (unknown)
   1.427 +</pre>
   1.428 +
   1.429 +<p>
   1.430 +By default, the signal handler writes the failure dump to the standard
   1.431 +error.  You can customize the destination by InstallFailureWriter().
   1.432 +
   1.433 +<h2> <A name="misc">Miscellaneous Notes</A> </h2>
   1.434 +
   1.435 +<h3><A NAME=message>Performance of Messages</A></h3>
   1.436 +
   1.437 +<p>The conditional logging macros provided by glog (e.g.,
   1.438 +<code>CHECK</code>, <code>LOG_IF</code>, <code>VLOG</code>, ...) are
   1.439 +carefully implemented and don't execute the right hand side
   1.440 +expressions when the conditions are false.  So, the following check
   1.441 +may not sacrifice the performance of your application.
   1.442 +
   1.443 +<pre>
   1.444 +   CHECK(obj.ok) &lt;&lt; obj.CreatePrettyFormattedStringButVerySlow();
   1.445 +</pre>
   1.446 +
   1.447 +<h3><A NAME=failure>User-defined Failure Function</A></h3>
   1.448 +
   1.449 +<p><code>FATAL</code> severity level messages or unsatisfied
   1.450 +<code>CHECK</code> condition terminate your program.  You can change
   1.451 +the behavior of the termination by
   1.452 +<code>InstallFailureFunction</code>.
   1.453 +
   1.454 +<pre>
   1.455 +   void YourFailureFunction() {
   1.456 +     // Reports something...
   1.457 +     exit(1);
   1.458 +   }
   1.459 +
   1.460 +   int main(int argc, char* argv[]) {
   1.461 +     google::InstallFailureFunction(&amp;YourFailureFunction);
   1.462 +   }
   1.463 +</pre>
   1.464 +
   1.465 +<p>By default, glog tries to dump stacktrace and makes the program
   1.466 +exit with status 1.  The stacktrace is produced only when you run the
   1.467 +program on an architecture for which glog supports stack tracing (as
   1.468 +of September 2008, glog supports stack tracing for x86 and x86_64).
   1.469 +
   1.470 +<h3><A NAME=raw>Raw Logging</A></h3>
   1.471 +
   1.472 +<p>The header file <code>&lt;glog/raw_logging.h&gt;</code> can be
   1.473 +used for thread-safe logging, which does not allocate any memory or
   1.474 +acquire any locks.  Therefore, the macros defined in this
   1.475 +header file can be used by low-level memory allocation and
   1.476 +synchronization code.
   1.477 +Please check <code>src/glog/raw_logging.h.in</code> for detail.
   1.478 +</p>
   1.479 +
   1.480 +<h3><A NAME=plog>Google Style perror()</A></h3>
   1.481 +
   1.482 +<p><code>PLOG()</code> and <code>PLOG_IF()</code> and
   1.483 +<code>PCHECK()</code> behave exactly like their <code>LOG*</code> and
   1.484 +<code>CHECK</code> equivalents with the addition that they append a
   1.485 +description of the current state of errno to their output lines.
   1.486 +E.g.
   1.487 +
   1.488 +<pre>
   1.489 +   PCHECK(write(1, NULL, 2) &gt;= 0) &lt;&lt; "Write NULL failed";
   1.490 +</pre>
   1.491 +
   1.492 +<p>This check fails with the following error message.
   1.493 +
   1.494 +<pre>
   1.495 +   F0825 185142 test.cc:22] Check failed: write(1, NULL, 2) &gt;= 0 Write NULL failed: Bad address [14]
   1.496 +</pre>
   1.497 +
   1.498 +<h3><A NAME=syslog>Syslog</A></h3>
   1.499 +
   1.500 +<p><code>SYSLOG</code>, <code>SYSLOG_IF</code>, and
   1.501 +<code>SYSLOG_EVERY_N</code> macros are available.
   1.502 +These log to syslog in addition to the normal logs.  Be aware that
   1.503 +logging to syslog can drastically impact performance, especially if
   1.504 +syslog is configured for remote logging!  Make sure you understand the
   1.505 +implications of outputting to syslog before you use these macros. In
   1.506 +general, it's wise to use these macros sparingly.
   1.507 +
   1.508 +<h3><A NAME=strip>Strip Logging Messages</A></h3>
   1.509 +
   1.510 +<p>Strings used in log messages can increase the size of your binary
   1.511 +and present a privacy concern.  You can therefore instruct glog to
   1.512 +remove all strings which fall below a certain severity level by using
   1.513 +the GOOGLE_STRIP_LOG macro:
   1.514 +
   1.515 +<p>If your application has code like this:
   1.516 +
   1.517 +<pre>
   1.518 +   #define GOOGLE_STRIP_LOG 1    // this must go before the #include!
   1.519 +   #include &lt;glog/logging.h&gt;
   1.520 +</pre>
   1.521 +
   1.522 +<p>The compiler will remove the log messages whose severities are less
   1.523 +than the specified integer value.  Since
   1.524 +<code>VLOG</code> logs at the severity level <code>INFO</code>
   1.525 +(numeric value <code>0</code>),
   1.526 +setting <code>GOOGLE_STRIP_LOG</code> to 1 or greater removes
   1.527 +all log messages associated with <code>VLOG</code>s as well as
   1.528 +<code>INFO</code> log statements.
   1.529 +
   1.530 +<h3><A NAME=windows>Notes for Windows users</A></h3>
   1.531 +
   1.532 +<p>Google glog defines a severity level <code>ERROR</code>, which is
   1.533 +also defined in <code>windows.h</code>
   1.534 +There are two known workarounds to avoid this conflict:
   1.535 +
   1.536 +<ul>
   1.537 +  <li>#define <code>WIN32_LEAN_AND_MEAN</code> or <code>NOGDI</code>
   1.538 +      <strong>before</strong> you #include <code>windows.h</code> .
   1.539 +  <li>#undef <code>ERROR</code> <strong>after</strong> you #include
   1.540 +      <code>windows.h</code> .
   1.541 +</ul>
   1.542 +
   1.543 +<p>See <a href="http://code.google.com/p/google-glog/issues/detail?id=33">
   1.544 +this issue</a> for more detail.
   1.545 +
   1.546 +<hr>
   1.547 +<address>
   1.548 +Shinichiro Hamaji<br>
   1.549 +Gregor Hohpe<br>
   1.550 +<script type=text/javascript>
   1.551 +  var lm = new Date(document.lastModified);
   1.552 +  document.write(lm.toDateString());
   1.553 +</script>
   1.554 +</address>
   1.555 +
   1.556 +</body>
   1.557 +</html>

mercurial