Deployed 0c10a02 to 0.8.0 with MkDocs 1.6.0 and mike 2.1.1

This commit is contained in:
Sergiu Deitsch 2024-06-12 23:01:44 +01:00
parent 7fea7f99f4
commit d78d6af613
19 changed files with 1966 additions and 252 deletions

View File

@ -343,6 +343,8 @@

View File

@ -492,6 +492,8 @@

View File

@ -354,6 +354,8 @@

View File

@ -356,6 +356,8 @@
@ -416,6 +418,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="../sinks/" class="md-nav__link"> <a href="../sinks/" class="md-nav__link">
@ -490,6 +513,15 @@
</span> </span>
</a> </a>
</li>
<li class="md-nav__item">
<a href="#customizing-handler-output" class="md-nav__link">
<span class="md-ellipsis">
Customizing Handler Output
</span>
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -678,6 +710,15 @@
</span> </span>
</a> </a>
</li>
<li class="md-nav__item">
<a href="#customizing-handler-output" class="md-nav__link">
<span class="md-ellipsis">
Customizing Handler Output
</span>
</a>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -731,27 +772,60 @@ PC: @ 0x412eb1 TestWaitingLogSink::send()
@ 0x7f892f7ef1c4 (unknown) @ 0x7f892f7ef1c4 (unknown)
@ 0x4046f9 (unknown) @ 0x4046f9 (unknown)
</code></pre></div> </code></pre></div>
<p>By default, the signal handler writes the failure dump to the standard <h2 id="customizing-handler-output">Customizing Handler Output<a class="headerlink" href="#customizing-handler-output" title="Permanent link">&para;</a></h2>
error. You can customize the destination by <p>By default, the signal handler writes the failure dump to the standard error.
<code class="language-cpp highlight"><span class="n">InstallFailureWriter</span><span class="p">()</span></code>.</p> However, it is possible to customize the destination by installing a callback
using the <code class="language-cpp highlight"><span class="n">google</span><span class="o">::</span><span class="n">InstallFailureWriter</span><span class="p">()</span></code> function. The function expects
a pointer to a function with the following signature:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kt">void</span><span class="w"> </span><span class="n">YourFailureWriter</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">message</span><span class="cm">/* (1)! */</span><span class="p">,</span><span class="w"> </span><span class="n">std</span><span class="o">::</span><span class="kt">size_t</span><span class="w"> </span><span class="n">length</span><span class="cm">/* (2)! */</span><span class="p">);</span>
</span></code></pre></div>
<ol>
<li>
<p>The pointer references the start of the failure message.</p>
<div class="admonition danger">
<p class="admonition-title">Danger</p>
<p>The string is <strong>not null-terminated</strong>.</p>
</div>
</li>
<li>
<p>The message length in characters.</p>
</li>
</ol>
<div class="admonition warning">
<p class="admonition-title">Possible overflow errors</p>
<p>Users should not expect the <code>message</code> string to be null-terminated.</p>
</div>
<h2 id="user-defined-failure-function">User-defined Failure Function<a class="headerlink" href="#user-defined-failure-function" title="Permanent link">&para;</a></h2> <h2 id="user-defined-failure-function">User-defined Failure Function<a class="headerlink" href="#user-defined-failure-function" title="Permanent link">&para;</a></h2>
<p><code>FATAL</code> severity level messages or unsatisfied <code>CHECK</code> condition <p><code>FATAL</code> severity level messages or unsatisfied <code>CHECK</code> condition
terminate your program. You can change the behavior of the termination terminate your program. You can change the behavior of the termination
by <code>InstallFailureFunction</code>.</p> by <code>google::InstallFailureFunction</code>.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kt">void</span><span class="w"> </span><span class="nf">YourFailureFunction</span><span class="p">()</span><span class="w"> </span><span class="p">{</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-1-1"><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="kt">void</span><span class="w"> </span><span class="nf">YourFailureFunction</span><span class="p">()</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="w"> </span><span class="c1">// Reports something...</span> </span><span id="__span-1-2"><a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="w"> </span><span class="c1">// Reports something...</span>
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="w"> </span><span class="n">exit</span><span class="p">(</span><span class="n">EXIT_FAILURE</span><span class="p">);</span> </span><span id="__span-1-3"><a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a><span class="w"> </span><span class="n">exit</span><span class="p">(</span><span class="n">EXIT_FAILURE</span><span class="p">);</span>
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="p">}</span> </span><span id="__span-1-4"><a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="p">}</span>
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a> </span><span id="__span-1-5"><a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a>
</span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a><span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">argv</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span> </span><span id="__span-1-6"><a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a><span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">argv</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-0-7"><a id="__codelineno-0-7" name="__codelineno-0-7" href="#__codelineno-0-7"></a><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">InstallFailureFunction</span><span class="p">(</span><span class="o">&amp;</span><span class="n">YourFailureFunction</span><span class="p">);</span> </span><span id="__span-1-7"><a id="__codelineno-1-7" name="__codelineno-1-7" href="#__codelineno-1-7"></a><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">InstallFailureFunction</span><span class="p">(</span><span class="o">&amp;</span><span class="n">YourFailureFunction</span><span class="p">);</span>
</span><span id="__span-0-8"><a id="__codelineno-0-8" name="__codelineno-0-8" href="#__codelineno-0-8"></a><span class="p">}</span> </span><span id="__span-1-8"><a id="__codelineno-1-8" name="__codelineno-1-8" href="#__codelineno-1-8"></a><span class="p">}</span>
</span></code></pre></div> </span></code></pre></div>
<p>By default, glog tries to dump the stacktrace and calls <code class="language-cpp highlight"><span class="n">std</span><span class="o">::</span><span class="n">abort</span></code>. The <p>By default, glog tries to dump the stacktrace and calls <code class="language-cpp highlight"><span class="n">std</span><span class="o">::</span><span class="n">abort</span></code>. The
stacktrace is generated only when running the application on a system supported stacktrace is generated only when running the application on a system
by glog. Currently, glog supports x86, x86_64, PowerPC architectures, supported<sup id="fnref:1"><a class="footnote-ref" href="#fn:1">1</a></sup> by glog.</p>
<code>libunwind</code>, and the Debug Help Library (<code>dbghelp</code>) on Windows for extracting <div class="footnote">
the stack trace.</p> <hr />
<ol>
<li id="fn:1">
<p>To extract the stack trace, glog currently supports the following targets:</p>
<ul>
<li>x86, x86_64,</li>
<li>PowerPC architectures,</li>
<li><code>libunwind</code>,</li>
<li>and the Debug Help Library (<code>dbghelp</code>) on Windows.</li>
</ul>
<p><a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
</ol>
</div>
@ -774,7 +848,7 @@ the stack trace.</p>
<span class="md-icon" title="Last update"> <span class="md-icon" title="Last update">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span> </span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 11, 2024</span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 12, 2024</span>
</span> </span>

1006
0.8.0/flags/index.html Normal file

File diff suppressed because it is too large Load Diff

View File

@ -432,6 +432,8 @@
@ -558,13 +560,14 @@ various helper macros.</p>
<div class="language-cpp highlight"><span class="filename">main.cpp</span><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;glog/logging.h&gt;</span> <div class="language-cpp highlight"><span class="filename">main.cpp</span><pre><span></span><code><span id="__span-0-1"><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;glog/logging.h&gt;</span>
</span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a> </span><span id="__span-0-2"><a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a>
</span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">argv</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span> </span><span id="__span-0-3"><a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="o">*</span><span class="w"> </span><span class="n">argv</span><span class="p">[])</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="w"> </span><span class="c1">// Initialize Googles logging library.</span> </span><span id="__span-0-4"><a id="__codelineno-0-4" name="__codelineno-0-4" href="#__codelineno-0-4"></a><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">InitGoogleLogging</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span><span class="w"> </span><span class="c1">// (1)!</span>
</span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">InitGoogleLogging</span><span class="p">(</span><span class="n">argv</span><span class="p">[</span><span class="mi">0</span><span class="p">]);</span> </span><span id="__span-0-5"><a id="__codelineno-0-5" name="__codelineno-0-5" href="#__codelineno-0-5"></a><span class="w"> </span><span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Found &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">num_cookies</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot; cookies&quot;</span><span class="p">;</span><span class="w"> </span><span class="c1">// (2)!</span>
</span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a> </span><span id="__span-0-6"><a id="__codelineno-0-6" name="__codelineno-0-6" href="#__codelineno-0-6"></a><span class="p">}</span>
</span><span id="__span-0-7"><a id="__codelineno-0-7" name="__codelineno-0-7" href="#__codelineno-0-7"></a><span class="w"> </span><span class="c1">// ...</span>
</span><span id="__span-0-8"><a id="__codelineno-0-8" name="__codelineno-0-8" href="#__codelineno-0-8"></a><span class="w"> </span><span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Found &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">num_cookies</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot; cookies&quot;</span><span class="p">;</span>
</span><span id="__span-0-9"><a id="__codelineno-0-9" name="__codelineno-0-9" href="#__codelineno-0-9"></a><span class="p">}</span>
</span></code></pre></div> </span></code></pre></div>
<ol>
<li>Initialize the Google Logging Library</li>
<li>Log a message with informational severity</li>
</ol>
<p>The library can be installed using various <a href="packages/">package managers</a> or <p>The library can be installed using various <a href="packages/">package managers</a> or
compiled <a href="build/">from source</a>. For a detailed overview of glog features and compiled <a href="build/">from source</a>. For a detailed overview of glog features and
their usage, please refer to the <a href="logging/">user guide</a>.</p> their usage, please refer to the <a href="logging/">user guide</a>.</p>
@ -595,7 +598,7 @@ their usage, please refer to the <a href="logging/">user guide</a>.</p>
<span class="md-icon" title="Last update"> <span class="md-icon" title="Last update">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span> </span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 11, 2024</span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 12, 2024</span>
</span> </span>

View File

@ -352,6 +352,8 @@

View File

@ -356,6 +356,8 @@
@ -416,6 +418,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="../sinks/" class="md-nav__link"> <a href="../sinks/" class="md-nav__link">

View File

@ -356,6 +356,8 @@
@ -416,6 +418,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="../sinks/" class="md-nav__link"> <a href="../sinks/" class="md-nav__link">

620
0.8.0/logging.md.orig Normal file
View File

@ -0,0 +1,620 @@
# Logging
glog defines a series of macros that simplify many common logging tasks. You can
log messages by [severity level](#severity-levels), [control logging](flags.md)
behavior from the command line, log based on
[conditionals](#conditional-occasional-logging), abort the program when
[expected conditions](#runtime-checks) are not met, introduce your [own logging
levels](#verbose-logging), [customize the prefix](#format-customization)
attached to log messages, and more.
## Severity Levels
You can specify one of the following severity levels (in increasing order of
severity):
1. `INFO`,
2. `WARNING`,
3. `ERROR`, and
4. `FATAL`.
Logging a `FATAL` message terminates the program (after the message is logged).
!!! note
Messages of a given severity are logged not only to corresponding severity
logfile but also to other logfiles of lower severity. For instance, a
message of severity `FATAL` will be logged to logfiles of severity `FATAL`,
`ERROR`, `WARNING`, and `INFO`.
The `DFATAL` severity logs a `FATAL` error in [debug mode](#debugging-support)
(i.e., there is no `NDEBUG` macro defined), but avoids halting the program in
production by automatically reducing the severity to `ERROR`.
## Log Files
Unless otherwise specified, glog uses the format
<tmp>/<program name>.<hostname>.<user name>.log.<severity level>.<date>-<time>.<pid>
for log filenames written to a directory designated as `<tmp>` and
determined according to the following rules.
**Windows**
: glog uses the
[GetTempPathA](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha)
API function to retrieve the directory for temporary files with a
fallback to
1. `C:\TMP\`
2. `C:\TEMP\`
(in the order given.)
**non-Windows**
: The directory is determined by referencing the environment variables
1. `TMPDIR`
2. `TMP`
if set with a fallback to `/tmp/`.
The default path to a log file on Linux, for instance, could be
/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474
By default, glog echos `ERROR` and `FATAL` messages to standard error in
addition to log files.
## Log Line Prefix Format
Log lines have this form:
Lyyyymmdd hh:mm:ss.uuuuuu threadid file:line] msg...
where the fields are defined as follows:
| Placeholder | Meaning |
| ------------------- | ----------------------------------------------------------------------|
| `L` | A single character, representing the log level (e.g., `I` for `INFO`) |
| `yyyy` | The year |
| `mm` | The month (zero padded; i.e., May is `05`) |
| `dd` | The day (zero padded) |
| `hh:mm:ss.uuuuuu` | Time in hours, minutes and fractional seconds |
| `threadid` | The space-padded thread ID |
| `file` | The file name |
| `line` | The line number |
| `msg` | The user-supplied message |
!!! example "Default log line prefix format"
```
I1103 11:57:31.739339 24395 google.cc:2341] Command line: ./some_prog
I1103 11:57:31.739403 24395 google.cc:2342] Process id 24395
```
!!! note
Although microseconds are useful for comparing events on a single machine,
clocks on different machines may not be well synchronized. Hence, use with
caution when comparing the low bits of timestamps from different machines.
### Format Customization
The predefined log line prefix can be replaced using a user-provided callback
that formats the corresponding output.
For each log entry, the callback will be invoked with a reference to a
`google::LogMessage` instance containing the severity, filename, line
number, thread ID, and time of the event. It will also be given a
reference to the output stream, whose contents will be prepended to the actual
message in the final log line.
To enable the use of a prefix formatter, use the
``` cpp
google::InstallPrefixFormatter(&MyPrefixFormatter);
```
function to pass a pointer to the corresponding `MyPrefixFormatter` callback
during initialization. `InstallPrefixFormatter` takes a second optional argument
of type `#!cpp void*` that allows supplying user data to the callback.
!!! example "Custom prefix formatter"
The following function outputs a prefix that matches glog's default format.
The third parameter `data` can be used to access user-supplied data which
unless specified defaults to `#!cpp nullptr`.
``` cpp
void MyPrefixFormatter(std::ostream& s, const google::LogMessage& m, void* /*data*/) {
s << google::GetLogSeverityName(m.severity())[0]
<< setw(4) << 1900 + m.time().year()
<< setw(2) << 1 + m.time().month()
<< setw(2) << m.time().day()
<< ' '
<< setw(2) << m.time().hour() << ':'
<< setw(2) << m.time().min() << ':'
<< setw(2) << m.time().sec() << "."
<< setw(6) << m.time().usec()
<< ' '
<< setfill(' ') << setw(5)
<< m.thread_id() << setfill('0')
<< ' '
<< m.basename() << ':' << m.line() << "]";
}
```
<<<<<<< HEAD
## Adjusting Output
Several flags influence glog's output behavior.
### Using Command-line Parameters and Environment Variables
If the [Google gflags
library](https://github.com/gflags/gflags) is installed on your machine,
the build system will automatically detect and use it, allowing you to
pass flags on the command line.
!!! example "Activate `--logtostderr` in an application from the command line"
A binary `you_application` that uses glog can be started using
``` bash
./your_application --logtostderr=1
```
to log to `stderr` instead of writing the output to a log file.
!!! tip
You can set boolean flags to `true` by specifying `1`, `true`, or `yes`. To
set boolean flags to `false`, specify `0`, `false`, or `no`. In either case
the spelling is case-insensitive.
If the Google gflags library isn't installed, you set flags via
environment variables, prefixing the flag name with `GLOG_`, e.g.,
!!! example "Activate `logtostderr` without gflags"
``` bash
GLOG_logtostderr=1 ./your_application
```
The following flags are most commonly used:
`logtostderr` (`bool`, default=`false`)
: Log messages to `stderr` instead of logfiles.
`stderrthreshold` (`int`, default=2, which is `ERROR`)
: Copy log messages at or above this level to `stderr` in addition to
logfiles. The numbers of severity levels `INFO`, `WARNING`, `ERROR`,
and `FATAL` are 0, 1, 2, and 3, respectively.
`minloglevel` (`int`, default=0, which is `INFO`)
: Log messages at or above this level. Again, the numbers of severity
levels `INFO`, `WARNING`, `ERROR`, and `FATAL` are 0, 1, 2, and 3,
respectively.
`log_dir` (`string`, default="")
: If specified, logfiles are written into this directory instead of
the default logging directory.
`v` (`int`, default=0)
: Show all `#!cpp VLOG(m)` messages for `m` less or equal the value of this
flag. Overridable by `#!bash --vmodule`. Refer to [verbose
logging](#verbose-logging) for more detail.
`vmodule` (`string`, default="")
: Per-module verbose level. The argument has to contain a
comma-separated list of `<module name>=<log level>`. `<module name>`
is a glob pattern (e.g., `gfs*` for all modules whose name starts
with "gfs"), matched against the filename base (that is, name
ignoring .cc/.h./-inl.h). `<log level>` overrides any value given by
`--v`. See also [verbose logging](#verbose-logging) for
more details.
Additional flags are defined in
[flags.cc](https://github.com/google/glog/blob/master/src/flags.cc). Please see
the source for their complete list.
### Modifying Flags Programmatically
You can also modify flag values in your program by modifying global variables
`FLAGS_*`. Most settings start working immediately after you update `FLAGS_*`.
The exceptions are the flags related to destination files. For instance, you
might want to set `FLAGS_log_dir` before calling `google::InitGoogleLogging`.
!!! example "Setting `log_dir` at runtime"
``` cpp
LOG(INFO) << "file";
// Most flags work immediately after updating values.
FLAGS_logtostderr = 1;
LOG(INFO) << "stderr";
FLAGS_logtostderr = 0;
// This wont 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";
```
||||||| df683bb
## Adjusting Output
Several flags influence glog's output behavior.
### Using Command-line Parameters and Environment Variables
If the [Google gflags
library](https://github.com/gflags/gflags) is installed on your machine,
the build system will automatically detect and use it, allowing you to
pass flags on the command line.
!!! example "Activate `--logtostderr` in an application from the command line"
A binary `you_application` that uses glog can be started using
``` bash
./your_application --logtostderr=1
```
to log to `stderr` instead of writing the output to a log file.
!!! tip
You can set boolean flags to `true` by specifying `1`, `true`, or `yes`. To
set boolean flags to `false`, specify `0`, `false`, or `no`. In either case
the spelling is case-insensitive.
If the Google gflags library isn't installed, you set flags via
environment variables, prefixing the flag name with `GLOG_`, e.g.,
!!! example "Activate `logtostderr` without gflags"
``` bash
GLOG_logtostderr=1 ./your_application
```
The following flags are most commonly used:
`logtostderr` (`bool`, default=`false`)
: Log messages to `stderr` instead of logfiles.
`stderrthreshold` (`int`, default=2, which is `ERROR`)
: Copy log messages at or above this level to `stderr` in addition to
logfiles. The numbers of severity levels `INFO`, `WARNING`, `ERROR`,
and `FATAL` are 0, 1, 2, and 3, respectively.
`minloglevel` (`int`, default=0, which is `INFO`)
: Log messages at or above this level. Again, the numbers of severity
levels `INFO`, `WARNING`, `ERROR`, and `FATAL` are 0, 1, 2, and 3,
respectively.
`log_dir` (`string`, default="")
: If specified, logfiles are written into this directory instead of
the default logging directory.
`v` (`int`, default=0)
: Show all `#!cpp VLOG(m)` messages for `m` less or equal the value of this
flag. Overridable by `#!bash --vmodule`. Refer to [verbose
logging](#verbose-logging) for more detail.
`vmodule` (`string`, default="")
: Per-module verbose level. The argument has to contain a
comma-separated list of `<module name>=<log level>`. `<module name>`
is a glob pattern (e.g., `gfs*` for all modules whose name starts
with "gfs"), matched against the filename base (that is, name
ignoring .cc/.h./-inl.h). `<log level>` overrides any value given by
`--v`. See also [verbose logging](#verbose-logging) for
more details.
Additional flags are defined in
[flags.cc](https://github.com/google/glog/blob/0.7.x/src/flags.cc). Please see
the source for their complete list.
### Modifying Flags Programmatically
You can also modify flag values in your program by modifying global variables
`FLAGS_*`. Most settings start working immediately after you update `FLAGS_*`.
The exceptions are the flags related to destination files. For instance, you
might want to set `FLAGS_log_dir` before calling `google::InitGoogleLogging`.
!!! example "Setting `log_dir` at runtime"
``` cpp
LOG(INFO) << "file";
// Most flags work immediately after updating values.
FLAGS_logtostderr = 1;
LOG(INFO) << "stderr";
FLAGS_logtostderr = 0;
// This wont 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";
```
=======
>>>>>>> 0.7.x
## Conditional / Occasional Logging
Sometimes, you may only want to log a message under certain conditions.
You can use the following macros to perform conditional logging:
``` cpp
LOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
```
The "Got lots of cookies" message is logged only when the variable
`num_cookies` exceeds 10. If a line of code is executed many times, it may be
useful to only log a message at certain intervals. This kind of logging is most
useful for informational messages.
``` cpp
LOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
```
The above line outputs a log messages on the 1st, 11th, 21st, ... times
it is executed.
!!! note
The placeholder `#!cpp google::COUNTER` identifies the recurring repetition.
You can combine conditional and occasional logging with the following
macro.
``` cpp
LOG_IF_EVERY_N(INFO, (size > 1024), 10) << "Got the " << google::COUNTER
<< "th big cookie";
```
Instead of outputting a message every nth time, you can also limit the
output to the first n occurrences:
``` cpp
LOG_FIRST_N(INFO, 20) << "Got the " << google::COUNTER << "th cookie";
```
Outputs log messages for the first 20 times it is executed. The `#!cpp
google::COUNTER` identifier indicates which repetition is happening.
Other times, it is desired to only log a message periodically based on a
time. For instance, to log a message every 10ms:
``` cpp
LOG_EVERY_T(INFO, 0.01) << "Got a cookie";
```
Or every 2.35s:
``` cpp
LOG_EVERY_T(INFO, 2.35) << "Got a cookie";
```
## Verbose Logging
When you are chasing difficult bugs, thorough log messages are very
useful. However, you may want to ignore too verbose messages in usual
development. For such verbose logging, glog provides the `VLOG` macro, which
allows you to define your own numeric logging levels.
The `#!bash --v` command line option controls which verbose messages are logged:
``` cpp
VLOG(1) << "Im printed when you run the program with --v=1 or higher";
VLOG(2) << "Im printed when you run the program with --v=2 or higher";
```
With `VLOG`, the lower the verbose level, the more likely messages are to be
logged. For example, if `#!bash --v==1`, `#!cpp VLOG(1)` will log, but `#!cpp
VLOG(2)` will not log.
!!! warning
The `VLOG` behavior is opposite of the severity level logging, where
`INFO`, `ERROR`, etc. are defined in increasing order and thus
`#!bash --minloglevel` of 1 will only log `WARNING` and above.
Though you can specify any integers for both `VLOG` macro and `--v` flag, the
common values for them are small positive integers. For example, if you write
`#!cpp VLOG(0)`, you should specify `--v=-1` or lower to silence it. This is less
useful since we may not want verbose logs by default in most cases. The `VLOG`
macros always log at the `INFO` log level (when they log at all).
Verbose logging can be controlled from the command line on a per-module basis:
``` bash
--vmodule=mapreduce=2,file=1,gfs*=3 --v=0
```
Specifying these options will specifically:
1. Print `#!cpp VLOG(2)` and lower messages from mapreduce.{h,cc}
2. Print `#!cpp VLOG(1)` and lower messages from file.{h,cc}
3. Print `#!cpp VLOG(3)` and lower messages from files prefixed with "gfs"
4. Print `#!cpp VLOG(0)` and lower messages from elsewhere
The wildcarding functionality 3. supports both `*` (matches 0 or more
characters) and `?` (matches any single character) wildcards. Please also refer
to [command line flags](flags.md) for more information.
There's also `#!cpp VLOG_IS_ON(n)` "verbose level" condition macro. This macro
returns `#!cpp true` when the `--v` is equal to or greater than `n`. The macro can be
used as follows:
``` cpp
if (VLOG_IS_ON(2)) {
// (1)
}
```
1. Here we can perform some logging preparation and logging that cant be
accomplished with just `#!cpp VLOG(2) << "message ...";`
Verbose level condition macros `VLOG_IF`, `VLOG_EVERY_N` and `VLOG_IF_EVERY_N`
behave analogous to `LOG_IF`, `LOG_EVERY_N`, `LOG_IF_EVERY_N`, but accept a
numeric verbosity level as opposed to a severity level.
``` cpp
VLOG_IF(1, (size > 1024))
<< "Im printed when size is more than 1024 and when you run the "
"program with --v=1 or more";
VLOG_EVERY_N(1, 10)
<< "Im printed every 10th occurrence, and when you run the program "
"with --v=1 or more. Present occurrence is " << google::COUNTER;
VLOG_IF_EVERY_N(1, (size > 1024), 10)
<< "Im printed on every 10th occurrence of case when size is more "
" than 1024, when you run the program with --v=1 or more. ";
"Present occurrence is " << google::COUNTER;
```
!!! info "Performance"
The conditional logging macros provided by glog (e.g., `CHECK`, `LOG_IF`,
`VLOG`, etc.) are carefully implemented and don't execute the right hand
side expressions when the conditions are false. So, the following check may
not sacrifice the performance of your application.
``` cpp
CHECK(obj.ok) << obj.CreatePrettyFormattedStringButVerySlow();
```
## Debugging Support
Special debug mode logging macros only have an effect in debug mode and are
compiled away to nothing for non-debug mode compiles. Use these macros to avoid
slowing down your production application due to excessive logging.
``` cpp
DLOG(INFO) << "Found cookies";
DLOG_IF(INFO, num_cookies > 10) << "Got lots of cookies";
DLOG_EVERY_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
DLOG_FIRST_N(INFO, 10) << "Got the " << google::COUNTER << "th cookie";
DLOG_EVERY_T(INFO, 0.01) << "Got a cookie";
```
## Runtime Checks
It is a good practice to check expected conditions in your program
frequently to detect errors as early as possible. The `CHECK` macro
provides the ability to abort the application when a condition is not met,
similar to the `assert` macro defined in the standard C library.
`CHECK` aborts the application if a condition is not true. Unlike
`assert`, it is **not** controlled by `NDEBUG`, so the check will be executed
regardless of compilation mode. Therefore, `fp->Write(x)` in the following
example is always executed:
``` cpp
CHECK(fp->Write(x) == 4) << "Write failed!";
```
There are various helper macros for equality/inequality checks
-`CHECK_EQ`, `CHECK_NE`, `CHECK_LE`, `CHECK_LT`, `CHECK_GE`, and
`CHECK_GT`. They compare two values, and log a `FATAL` message including the two
values when the result is not as expected. The values must have
`#!cpp operator<<(ostream, ...)` defined.
You may append to the error message like so:
``` cpp
CHECK_NE(1, 2) << ": The world must be ending!";
```
We are very careful to ensure that each argument is evaluated exactly
once, and that anything which is legal to pass as a function argument is legal
here. In particular, the arguments may be temporary expressions which will end
up being destroyed at the end of the apparent statement, for example:
``` cpp
CHECK_EQ(string("abc")[1], b);
```
The compiler reports an error if one of the arguments is a pointer and the other
is `#!cpp nullptr`. To work around this, simply `#!cpp static_cast` `#!cpp
nullptr` to the type of the desired pointer.
``` cpp
CHECK_EQ(some_ptr, static_cast<SomeType*>(nullptr));
```
Better yet, use the `CHECK_NOTNULL` macro:
``` cpp
CHECK_NOTNULL(some_ptr);
some_ptr->DoSomething();
```
Since this macro returns the given pointer, this is very useful in
constructor initializer lists.
``` cpp
struct S {
S(Something* ptr) : ptr_(CHECK_NOTNULL(ptr)) {}
Something* ptr_;
};
```
!!! warning
Due to the argument forwarding, `CHECK_NOTNULL` cannot be used to
simultaneously stream an additional custom message. To provide a custom
message, one can use the macro `CHECK_EQ` prior to the failing check.
If you are comparing C strings (`#!cpp char *`), a handy set of macros performs
both case sensitive and insensitive comparisons - `CHECK_STREQ`, `CHECK_STRNE`,
`CHECK_STRCASEEQ`, and `CHECK_STRCASENE`. The `CHECK_*CASE*` macro variants are
case-insensitive. You can safely pass `#!cpp nullptr` pointers to this macro.
They treat `#!cpp nullptr` and any non-`#!cpp nullptr` string as not equal. Two
`#!cpp nullptr`s are equal.
!!! note
Both arguments may be temporary objects which are destructed at the
end of the current *full expression*, such as
``` cpp
CHECK_STREQ(Foo().c_str(), Bar().c_str());
```
where `Foo` and `Bar` return `std::string`.
The `CHECK_DOUBLE_EQ` macro checks the equality of two floating point values,
accepting a small error margin. `CHECK_NEAR` accepts a third floating point
argument, which specifies the acceptable error margin.
## Raw Logging
The header file `<glog/raw_logging.h>` can be used for thread-safe logging,
which does not allocate any memory or acquire any locks. Therefore, the macros
defined in this header file can be used by low-level memory allocation and
synchronization code. Please check
[src/glog/raw_logging.h](https://github.com/google/glog/blob/master/src/glog/raw_logging.h)
for detail.
## Google Style `perror()`
`PLOG()` and `PLOG_IF()` and `PCHECK()` behave exactly like their `LOG*` and
`CHECK` equivalents with the addition that they append a description of the
current state of `errno` to their output lines. E.g.
``` cpp
PCHECK(write(1, nullptr, 2) >= 0) << "Write nullptr failed";
```
This check fails with the following error message.
F0825 185142 test.cc:22] Check failed: write(1, nullptr, 2) >= 0 Write nullptr failed: Bad address [14]
## Syslog
`SYSLOG`, `SYSLOG_IF`, and `SYSLOG_EVERY_N` macros are available. These log to
syslog in addition to the normal logs. Be aware that logging to syslog can
drastically impact performance, especially if syslog is configured for remote
logging! Make sure you understand the implications of outputting to syslog
before you use these macros. In general, it's wise to use these macros
sparingly.

View File

@ -14,7 +14,7 @@
<link rel="prev" href="../packages/"> <link rel="prev" href="../packages/">
<link rel="next" href="../sinks/"> <link rel="next" href="../flags/">
<link rel="icon" href="../assets/images/favicon.png"> <link rel="icon" href="../assets/images/favicon.png">
@ -356,6 +356,8 @@
@ -481,39 +483,6 @@
</ul> </ul>
</nav> </nav>
</li>
<li class="md-nav__item">
<a href="#adjusting-output" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
<nav class="md-nav" aria-label="Adjusting Output">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#using-command-line-parameters-and-environment-variables" class="md-nav__link">
<span class="md-ellipsis">
Using Command-line Parameters and Environment Variables
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#modifying-flags-programmatically" class="md-nav__link">
<span class="md-ellipsis">
Modifying Flags Programmatically
</span>
</a>
</li>
</ul>
</nav>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -594,6 +563,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="../sinks/" class="md-nav__link"> <a href="../sinks/" class="md-nav__link">
@ -831,39 +821,6 @@
</ul> </ul>
</nav> </nav>
</li>
<li class="md-nav__item">
<a href="#adjusting-output" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
<nav class="md-nav" aria-label="Adjusting Output">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#using-command-line-parameters-and-environment-variables" class="md-nav__link">
<span class="md-ellipsis">
Using Command-line Parameters and Environment Variables
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#modifying-flags-programmatically" class="md-nav__link">
<span class="md-ellipsis">
Modifying Flags Programmatically
</span>
</a>
</li>
</ul>
</nav>
</li> </li>
<li class="md-nav__item"> <li class="md-nav__item">
@ -954,8 +911,8 @@
<h1 id="logging">Logging<a class="headerlink" href="#logging" title="Permanent link">&para;</a></h1> <h1 id="logging">Logging<a class="headerlink" href="#logging" title="Permanent link">&para;</a></h1>
<p>glog defines a series of macros that simplify many common logging tasks. You can <p>glog defines a series of macros that simplify many common logging tasks. You can
log messages by <a href="#severity-levels">severity level</a>, <a href="#adjusting-output">control log messages by <a href="#severity-levels">severity level</a>, <a href="../flags/">control logging</a>
logging</a> behavior from the command line, log based on behavior from the command line, log based on
<a href="#conditional-occasional-logging">conditionals</a>, abort the program when <a href="#conditional-occasional-logging">conditionals</a>, abort the program when
<a href="#runtime-checks">expected conditions</a> are not met, introduce your <a href="#verbose-logging">own logging <a href="#runtime-checks">expected conditions</a> are not met, introduce your <a href="#verbose-logging">own logging
levels</a>, <a href="#format-customization">customize the prefix</a> levels</a>, <a href="#format-customization">customize the prefix</a>
@ -1114,104 +1071,16 @@ unless specified defaults to <code class="language-cpp highlight"><span class="k
</span><span id="__span-2-16"><a id="__codelineno-2-16" name="__codelineno-2-16" href="#__codelineno-2-16"></a><span class="p">}</span> </span><span id="__span-2-16"><a id="__codelineno-2-16" name="__codelineno-2-16" href="#__codelineno-2-16"></a><span class="p">}</span>
</span></code></pre></div> </span></code></pre></div>
</div> </div>
<h2 id="adjusting-output">Adjusting Output<a class="headerlink" href="#adjusting-output" title="Permanent link">&para;</a></h2>
<p>Several flags influence glog's output behavior.</p>
<h3 id="using-command-line-parameters-and-environment-variables">Using Command-line Parameters and Environment Variables<a class="headerlink" href="#using-command-line-parameters-and-environment-variables" title="Permanent link">&para;</a></h3>
<p>If the <a href="https://github.com/gflags/gflags">Google gflags
library</a> is installed on your machine,
the build system will automatically detect and use it, allowing you to
pass flags on the command line.</p>
<div class="admonition example">
<p class="admonition-title">Activate <code>--logtostderr</code> in an application from the command line</p>
<p>A binary <code>you_application</code> that uses glog can be started using
<div class="language-bash highlight"><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a>./your_application<span class="w"> </span>--logtostderr<span class="o">=</span><span class="m">1</span>
</span></code></pre></div>
to log to <code>stderr</code> instead of writing the output to a log file.</p>
</div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>You can set boolean flags to <code>true</code> by specifying <code>1</code>, <code>true</code>, or <code>yes</code>. To
set boolean flags to <code>false</code>, specify <code>0</code>, <code>false</code>, or <code>no</code>. In either case
the spelling is case-insensitive.</p>
</div>
<p>If the Google gflags library isn't installed, you set flags via
environment variables, prefixing the flag name with <code>GLOG_</code>, e.g.,</p>
<div class="admonition example">
<p class="admonition-title">Activate <code>logtostderr</code> without gflags</p>
<div class="language-bash highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="nv">GLOG_logtostderr</span><span class="o">=</span><span class="m">1</span><span class="w"> </span>./your_application
</span></code></pre></div>
</div>
<p>The following flags are most commonly used:</p>
<dl>
<dt><code>logtostderr</code> (<code>bool</code>, default=<code>false</code>)</dt>
<dd>
<p>Log messages to <code>stderr</code> instead of logfiles.</p>
</dd>
<dt><code>stderrthreshold</code> (<code>int</code>, default=2, which is <code>ERROR</code>)</dt>
<dd>
<p>Copy log messages at or above this level to <code>stderr</code> in addition to
logfiles. The numbers of severity levels <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>,
and <code>FATAL</code> are 0, 1, 2, and 3, respectively.</p>
</dd>
<dt><code>minloglevel</code> (<code>int</code>, default=0, which is <code>INFO</code>)</dt>
<dd>
<p>Log messages at or above this level. Again, the numbers of severity
levels <code>INFO</code>, <code>WARNING</code>, <code>ERROR</code>, and <code>FATAL</code> are 0, 1, 2, and 3,
respectively.</p>
</dd>
<dt><code>log_dir</code> (<code>string</code>, default="")</dt>
<dd>
<p>If specified, logfiles are written into this directory instead of
the default logging directory.</p>
</dd>
<dt><code>v</code> (<code>int</code>, default=0)</dt>
<dd>
<p>Show all <code class="language-cpp highlight"><span class="n">VLOG</span><span class="p">(</span><span class="n">m</span><span class="p">)</span></code> messages for <code>m</code> less or equal the value of this
flag. Overridable by <code class="language-bash highlight">--vmodule</code>. Refer to <a href="#verbose-logging">verbose
logging</a> for more detail.</p>
</dd>
<dt><code>vmodule</code> (<code>string</code>, default="")</dt>
<dd>
<p>Per-module verbose level. The argument has to contain a
comma-separated list of <code>&lt;module name&gt;=&lt;log level&gt;</code>. <code>&lt;module name&gt;</code>
is a glob pattern (e.g., <code>gfs*</code> for all modules whose name starts
with "gfs"), matched against the filename base (that is, name
ignoring .cc/.h./-inl.h). <code>&lt;log level&gt;</code> overrides any value given by
<code>--v</code>. See also <a href="#verbose-logging">verbose logging</a> for
more details.</p>
</dd>
</dl>
<p>Additional flags are defined in
<a href="https://github.com/google/glog/blob/master/src/flags.cc">flags.cc</a>. Please see
the source for their complete list.</p>
<h3 id="modifying-flags-programmatically">Modifying Flags Programmatically<a class="headerlink" href="#modifying-flags-programmatically" title="Permanent link">&para;</a></h3>
<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 instance, you
might want to set <code>FLAGS_log_dir</code> before calling <code>google::InitGoogleLogging</code>.</p>
<div class="admonition example">
<p class="admonition-title">Setting <code>log_dir</code> at runtime</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;file&quot;</span><span class="p">;</span>
</span><span id="__span-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="c1">// Most flags work immediately after updating values.</span>
</span><span id="__span-5-3"><a id="__codelineno-5-3" name="__codelineno-5-3" href="#__codelineno-5-3"></a><span class="n">FLAGS_logtostderr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
</span><span id="__span-5-4"><a id="__codelineno-5-4" name="__codelineno-5-4" href="#__codelineno-5-4"></a><span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;stderr&quot;</span><span class="p">;</span>
</span><span id="__span-5-5"><a id="__codelineno-5-5" name="__codelineno-5-5" href="#__codelineno-5-5"></a><span class="n">FLAGS_logtostderr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
</span><span id="__span-5-6"><a id="__codelineno-5-6" name="__codelineno-5-6" href="#__codelineno-5-6"></a><span class="c1">// This wont change the log destination. If you want to set this</span>
</span><span id="__span-5-7"><a id="__codelineno-5-7" name="__codelineno-5-7" href="#__codelineno-5-7"></a><span class="c1">// value, you should do this before google::InitGoogleLogging .</span>
</span><span id="__span-5-8"><a id="__codelineno-5-8" name="__codelineno-5-8" href="#__codelineno-5-8"></a><span class="n">FLAGS_log_dir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">&quot;/some/log/directory&quot;</span><span class="p">;</span>
</span><span id="__span-5-9"><a id="__codelineno-5-9" name="__codelineno-5-9" href="#__codelineno-5-9"></a><span class="n">LOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;the same file&quot;</span><span class="p">;</span>
</span></code></pre></div>
</div>
<h2 id="conditional-occasional-logging">Conditional / Occasional Logging<a class="headerlink" href="#conditional-occasional-logging" title="Permanent link">&para;</a></h2> <h2 id="conditional-occasional-logging">Conditional / Occasional Logging<a class="headerlink" href="#conditional-occasional-logging" title="Permanent link">&para;</a></h2>
<p>Sometimes, you may only want to log a message under certain conditions. <p>Sometimes, you may only want to log a message under certain conditions.
You can use the following macros to perform conditional logging:</p> You can use the following macros to perform conditional logging:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="n">LOG_IF</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="n">num_cookies</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got lots of cookies&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-3-1"><a id="__codelineno-3-1" name="__codelineno-3-1" href="#__codelineno-3-1"></a><span class="n">LOG_IF</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="n">num_cookies</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got lots of cookies&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>The "Got lots of cookies" message is logged only when the variable <p>The "Got lots of cookies" message is logged only when the variable
<code>num_cookies</code> exceeds 10. If a line of code is executed many times, it may be <code>num_cookies</code> exceeds 10. If a line of code is executed many times, it may be
useful to only log a message at certain intervals. This kind of logging is most useful to only log a message at certain intervals. This kind of logging is most
useful for informational messages.</p> useful for informational messages.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-7-1"><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="n">LOG_EVERY_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-4-1"><a id="__codelineno-4-1" name="__codelineno-4-1" href="#__codelineno-4-1"></a><span class="n">LOG_EVERY_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>The above line outputs a log messages on the 1st, 11th, 21st, ... times <p>The above line outputs a log messages on the 1st, 11th, 21st, ... times
it is executed.</p> it is executed.</p>
@ -1221,20 +1090,20 @@ it is executed.</p>
</div> </div>
<p>You can combine conditional and occasional logging with the following <p>You can combine conditional and occasional logging with the following
macro.</p> macro.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-8-1"><a id="__codelineno-8-1" name="__codelineno-8-1" href="#__codelineno-8-1"></a><span class="n">LOG_IF_EVERY_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1024</span><span class="p">),</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-5-1"><a id="__codelineno-5-1" name="__codelineno-5-1" href="#__codelineno-5-1"></a><span class="n">LOG_IF_EVERY_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1024</span><span class="p">),</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span>
</span><span id="__span-8-2"><a id="__codelineno-8-2" name="__codelineno-8-2" href="#__codelineno-8-2"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th big cookie&quot;</span><span class="p">;</span> </span><span id="__span-5-2"><a id="__codelineno-5-2" name="__codelineno-5-2" href="#__codelineno-5-2"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th big cookie&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>Instead of outputting a message every nth time, you can also limit the <p>Instead of outputting a message every nth time, you can also limit the
output to the first n occurrences:</p> output to the first n occurrences:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-9-1"><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a><span class="n">LOG_FIRST_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-6-1"><a id="__codelineno-6-1" name="__codelineno-6-1" href="#__codelineno-6-1"></a><span class="n">LOG_FIRST_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">20</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>Outputs log messages for the first 20 times it is executed. The <code class="language-cpp highlight"><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span></code> identifier indicates which repetition is happening.</p> <p>Outputs log messages for the first 20 times it is executed. The <code class="language-cpp highlight"><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span></code> identifier indicates which repetition is happening.</p>
<p>Other times, it is desired to only log a message periodically based on a <p>Other times, it is desired to only log a message periodically based on a
time. For instance, to log a message every 10ms:</p> time. For instance, to log a message every 10ms:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-10-1"><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a><span class="n">LOG_EVERY_T</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mf">0.01</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got a cookie&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-7-1"><a id="__codelineno-7-1" name="__codelineno-7-1" href="#__codelineno-7-1"></a><span class="n">LOG_EVERY_T</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mf">0.01</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got a cookie&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>Or every 2.35s:</p> <p>Or every 2.35s:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-11-1"><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a><span class="n">LOG_EVERY_T</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mf">2.35</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got a cookie&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-8-1"><a id="__codelineno-8-1" name="__codelineno-8-1" href="#__codelineno-8-1"></a><span class="n">LOG_EVERY_T</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mf">2.35</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got a cookie&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<h2 id="verbose-logging">Verbose Logging<a class="headerlink" href="#verbose-logging" title="Permanent link">&para;</a></h2> <h2 id="verbose-logging">Verbose Logging<a class="headerlink" href="#verbose-logging" title="Permanent link">&para;</a></h2>
<p>When you are chasing difficult bugs, thorough log messages are very <p>When you are chasing difficult bugs, thorough log messages are very
@ -1242,8 +1111,8 @@ useful. However, you may want to ignore too verbose messages in usual
development. For such verbose logging, glog provides the <code>VLOG</code> macro, which development. For such verbose logging, glog provides the <code>VLOG</code> macro, which
allows you to define your own numeric logging levels.</p> allows you to define your own numeric logging levels.</p>
<p>The <code class="language-bash highlight">--v</code> command line option controls which verbose messages are logged:</p> <p>The <code class="language-bash highlight">--v</code> command line option controls which verbose messages are logged:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-12-1"><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="n">VLOG</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed when you run the program with --v=1 or higher&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-9-1"><a id="__codelineno-9-1" name="__codelineno-9-1" href="#__codelineno-9-1"></a><span class="n">VLOG</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed when you run the program with --v=1 or higher&quot;</span><span class="p">;</span>
</span><span id="__span-12-2"><a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="n">VLOG</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed when you run the program with --v=2 or higher&quot;</span><span class="p">;</span> </span><span id="__span-9-2"><a id="__codelineno-9-2" name="__codelineno-9-2" href="#__codelineno-9-2"></a><span class="n">VLOG</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed when you run the program with --v=2 or higher&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>With <code>VLOG</code>, the lower the verbose level, the more likely messages are to be <p>With <code>VLOG</code>, the lower the verbose level, the more likely messages are to be
logged. For example, if <code class="language-bash highlight">--v<span class="o">==</span><span class="m">1</span></code>, <code class="language-cpp highlight"><span class="n">VLOG</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></code> will log, but <code class="language-cpp highlight"><span class="n">VLOG</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span></code> will not log.</p> logged. For example, if <code class="language-bash highlight">--v<span class="o">==</span><span class="m">1</span></code>, <code class="language-cpp highlight"><span class="n">VLOG</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span></code> will log, but <code class="language-cpp highlight"><span class="n">VLOG</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span></code> will not log.</p>
@ -1259,7 +1128,7 @@ common values for them are small positive integers. For example, if you write
useful since we may not want verbose logs by default in most cases. The <code>VLOG</code> useful since we may not want verbose logs by default in most cases. The <code>VLOG</code>
macros always log at the <code>INFO</code> log level (when they log at all).</p> macros always log at the <code>INFO</code> log level (when they log at all).</p>
<p>Verbose logging can be controlled from the command line on a per-module basis:</p> <p>Verbose logging can be controlled from the command line on a per-module basis:</p>
<div class="language-bash highlight"><pre><span></span><code><span id="__span-13-1"><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a>--vmodule<span class="o">=</span><span class="nv">mapreduce</span><span class="o">=</span><span class="m">2</span>,file<span class="o">=</span><span class="m">1</span>,gfs*<span class="o">=</span><span class="m">3</span><span class="w"> </span>--v<span class="o">=</span><span class="m">0</span> <div class="language-bash highlight"><pre><span></span><code><span id="__span-10-1"><a id="__codelineno-10-1" name="__codelineno-10-1" href="#__codelineno-10-1"></a>--vmodule<span class="o">=</span><span class="nv">mapreduce</span><span class="o">=</span><span class="m">2</span>,file<span class="o">=</span><span class="m">1</span>,gfs*<span class="o">=</span><span class="m">3</span><span class="w"> </span>--v<span class="o">=</span><span class="m">0</span>
</span></code></pre></div> </span></code></pre></div>
<p>Specifying these options will specifically:</p> <p>Specifying these options will specifically:</p>
<ol> <ol>
@ -1270,28 +1139,31 @@ macros always log at the <code>INFO</code> log level (when they log at all).</p>
</ol> </ol>
<p>The wildcarding functionality 3. supports both <code>*</code> (matches 0 or more <p>The wildcarding functionality 3. supports both <code>*</code> (matches 0 or more
characters) and <code>?</code> (matches any single character) wildcards. Please also refer characters) and <code>?</code> (matches any single character) wildcards. Please also refer
to <a href="#adjusting-output">command line flags</a> for more information.</p> to <a href="../flags/">command line flags</a> for more information.</p>
<p>There's also <code class="language-cpp highlight"><span class="n">VLOG_IS_ON</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></code> "verbose level" condition macro. This macro <p>There's also <code class="language-cpp highlight"><span class="n">VLOG_IS_ON</span><span class="p">(</span><span class="n">n</span><span class="p">)</span></code> "verbose level" condition macro. This macro
returns <code class="language-cpp highlight"><span class="nb">true</span></code> when the <code>--v</code> is equal to or greater than <code>n</code>. The macro can be returns <code class="language-cpp highlight"><span class="nb">true</span></code> when the <code>--v</code> is equal to or greater than <code>n</code>. The macro can be
used as follows:</p> used as follows:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-14-1"><a id="__codelineno-14-1" name="__codelineno-14-1" href="#__codelineno-14-1"></a><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">VLOG_IS_ON</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="w"> </span><span class="p">{</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-11-1"><a id="__codelineno-11-1" name="__codelineno-11-1" href="#__codelineno-11-1"></a><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">VLOG_IS_ON</span><span class="p">(</span><span class="mi">2</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-14-2"><a id="__codelineno-14-2" name="__codelineno-14-2" href="#__codelineno-14-2"></a><span class="w"> </span><span class="c1">// do some logging preparation and logging</span> </span><span id="__span-11-2"><a id="__codelineno-11-2" name="__codelineno-11-2" href="#__codelineno-11-2"></a><span class="w"> </span><span class="c1">// (1)</span>
</span><span id="__span-14-3"><a id="__codelineno-14-3" name="__codelineno-14-3" href="#__codelineno-14-3"></a><span class="w"> </span><span class="c1">// that cant be accomplished with just VLOG(2) &lt;&lt; ...;</span> </span><span id="__span-11-3"><a id="__codelineno-11-3" name="__codelineno-11-3" href="#__codelineno-11-3"></a><span class="p">}</span>
</span><span id="__span-14-4"><a id="__codelineno-14-4" name="__codelineno-14-4" href="#__codelineno-14-4"></a><span class="p">}</span>
</span></code></pre></div> </span></code></pre></div>
<ol>
<li>Here we can perform some logging preparation and logging that cant be
accomplished with just <code class="language-cpp highlight"><span class="n">VLOG</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;message ...&quot;</span><span class="p">;</span></code></li>
</ol>
<p>Verbose level condition macros <code>VLOG_IF</code>, <code>VLOG_EVERY_N</code> and <code>VLOG_IF_EVERY_N</code> <p>Verbose level condition macros <code>VLOG_IF</code>, <code>VLOG_EVERY_N</code> and <code>VLOG_IF_EVERY_N</code>
behave analogous to <code>LOG_IF</code>, <code>LOG_EVERY_N</code>, <code>LOG_IF_EVERY_N</code>, but accept a behave analogous to <code>LOG_IF</code>, <code>LOG_EVERY_N</code>, <code>LOG_IF_EVERY_N</code>, but accept a
numeric verbosity level as opposed to a severity level.</p> numeric verbosity level as opposed to a severity level.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-15-1"><a id="__codelineno-15-1" name="__codelineno-15-1" href="#__codelineno-15-1"></a><span class="n">VLOG_IF</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1024</span><span class="p">))</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-12-1"><a id="__codelineno-12-1" name="__codelineno-12-1" href="#__codelineno-12-1"></a><span class="n">VLOG_IF</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1024</span><span class="p">))</span>
</span><span id="__span-15-2"><a id="__codelineno-15-2" name="__codelineno-15-2" href="#__codelineno-15-2"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed when size is more than 1024 and when you run the &quot;</span> </span><span id="__span-12-2"><a id="__codelineno-12-2" name="__codelineno-12-2" href="#__codelineno-12-2"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed when size is more than 1024 and when you run the &quot;</span>
</span><span id="__span-15-3"><a id="__codelineno-15-3" name="__codelineno-15-3" href="#__codelineno-15-3"></a><span class="w"> </span><span class="s">&quot;program with --v=1 or more&quot;</span><span class="p">;</span> </span><span id="__span-12-3"><a id="__codelineno-12-3" name="__codelineno-12-3" href="#__codelineno-12-3"></a><span class="w"> </span><span class="s">&quot;program with --v=1 or more&quot;</span><span class="p">;</span>
</span><span id="__span-15-4"><a id="__codelineno-15-4" name="__codelineno-15-4" href="#__codelineno-15-4"></a><span class="n">VLOG_EVERY_N</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span> </span><span id="__span-12-4"><a id="__codelineno-12-4" name="__codelineno-12-4" href="#__codelineno-12-4"></a><span class="n">VLOG_EVERY_N</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span>
</span><span id="__span-15-5"><a id="__codelineno-15-5" name="__codelineno-15-5" href="#__codelineno-15-5"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed every 10th occurrence, and when you run the program &quot;</span> </span><span id="__span-12-5"><a id="__codelineno-12-5" name="__codelineno-12-5" href="#__codelineno-12-5"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed every 10th occurrence, and when you run the program &quot;</span>
</span><span id="__span-15-6"><a id="__codelineno-15-6" name="__codelineno-15-6" href="#__codelineno-15-6"></a><span class="w"> </span><span class="s">&quot;with --v=1 or more. Present occurrence is &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="p">;</span> </span><span id="__span-12-6"><a id="__codelineno-12-6" name="__codelineno-12-6" href="#__codelineno-12-6"></a><span class="w"> </span><span class="s">&quot;with --v=1 or more. Present occurrence is &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="p">;</span>
</span><span id="__span-15-7"><a id="__codelineno-15-7" name="__codelineno-15-7" href="#__codelineno-15-7"></a><span class="n">VLOG_IF_EVERY_N</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1024</span><span class="p">),</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span> </span><span id="__span-12-7"><a id="__codelineno-12-7" name="__codelineno-12-7" href="#__codelineno-12-7"></a><span class="n">VLOG_IF_EVERY_N</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="p">(</span><span class="n">size</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">1024</span><span class="p">),</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span>
</span><span id="__span-15-8"><a id="__codelineno-15-8" name="__codelineno-15-8" href="#__codelineno-15-8"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed on every 10th occurrence of case when size is more &quot;</span> </span><span id="__span-12-8"><a id="__codelineno-12-8" name="__codelineno-12-8" href="#__codelineno-12-8"></a><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Im printed on every 10th occurrence of case when size is more &quot;</span>
</span><span id="__span-15-9"><a id="__codelineno-15-9" name="__codelineno-15-9" href="#__codelineno-15-9"></a><span class="w"> </span><span class="s">&quot; than 1024, when you run the program with --v=1 or more. &quot;</span><span class="p">;</span> </span><span id="__span-12-9"><a id="__codelineno-12-9" name="__codelineno-12-9" href="#__codelineno-12-9"></a><span class="w"> </span><span class="s">&quot; than 1024, when you run the program with --v=1 or more. &quot;</span><span class="p">;</span>
</span><span id="__span-15-10"><a id="__codelineno-15-10" name="__codelineno-15-10" href="#__codelineno-15-10"></a><span class="w"> </span><span class="s">&quot;Present occurrence is &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="p">;</span> </span><span id="__span-12-10"><a id="__codelineno-12-10" name="__codelineno-12-10" href="#__codelineno-12-10"></a><span class="w"> </span><span class="s">&quot;Present occurrence is &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<div class="admonition info"> <div class="admonition info">
<p class="admonition-title">Performance</p> <p class="admonition-title">Performance</p>
@ -1299,18 +1171,18 @@ numeric verbosity level as opposed to a severity level.</p>
<code>VLOG</code>, etc.) are carefully implemented and don't execute the right hand <code>VLOG</code>, etc.) are carefully implemented and don't execute the right hand
side expressions when the conditions are false. So, the following check may side expressions when the conditions are false. So, the following check may
not sacrifice the performance of your application.</p> not sacrifice the performance of your application.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-16-1"><a id="__codelineno-16-1" name="__codelineno-16-1" href="#__codelineno-16-1"></a><span class="n">CHECK</span><span class="p">(</span><span class="n">obj</span><span class="p">.</span><span class="n">ok</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">obj</span><span class="p">.</span><span class="n">CreatePrettyFormattedStringButVerySlow</span><span class="p">();</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-13-1"><a id="__codelineno-13-1" name="__codelineno-13-1" href="#__codelineno-13-1"></a><span class="n">CHECK</span><span class="p">(</span><span class="n">obj</span><span class="p">.</span><span class="n">ok</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">obj</span><span class="p">.</span><span class="n">CreatePrettyFormattedStringButVerySlow</span><span class="p">();</span>
</span></code></pre></div> </span></code></pre></div>
</div> </div>
<h2 id="debugging-support">Debugging Support<a class="headerlink" href="#debugging-support" title="Permanent link">&para;</a></h2> <h2 id="debugging-support">Debugging Support<a class="headerlink" href="#debugging-support" title="Permanent link">&para;</a></h2>
<p>Special debug mode logging macros only have an effect in debug mode and are <p>Special debug mode logging macros only have an effect in debug mode and are
compiled away to nothing for non-debug mode compiles. Use these macros to avoid compiled away to nothing for non-debug mode compiles. Use these macros to avoid
slowing down your production application due to excessive logging.</p> slowing down your production application due to excessive logging.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-17-1"><a id="__codelineno-17-1" name="__codelineno-17-1" href="#__codelineno-17-1"></a><span class="n">DLOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Found cookies&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-14-1"><a id="__codelineno-14-1" name="__codelineno-14-1" href="#__codelineno-14-1"></a><span class="n">DLOG</span><span class="p">(</span><span class="n">INFO</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Found cookies&quot;</span><span class="p">;</span>
</span><span id="__span-17-2"><a id="__codelineno-17-2" name="__codelineno-17-2" href="#__codelineno-17-2"></a><span class="n">DLOG_IF</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="n">num_cookies</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got lots of cookies&quot;</span><span class="p">;</span> </span><span id="__span-14-2"><a id="__codelineno-14-2" name="__codelineno-14-2" href="#__codelineno-14-2"></a><span class="n">DLOG_IF</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="n">num_cookies</span><span class="w"> </span><span class="o">&gt;</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got lots of cookies&quot;</span><span class="p">;</span>
</span><span id="__span-17-3"><a id="__codelineno-17-3" name="__codelineno-17-3" href="#__codelineno-17-3"></a><span class="n">DLOG_EVERY_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span> </span><span id="__span-14-3"><a id="__codelineno-14-3" name="__codelineno-14-3" href="#__codelineno-14-3"></a><span class="n">DLOG_EVERY_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span>
</span><span id="__span-17-4"><a id="__codelineno-17-4" name="__codelineno-17-4" href="#__codelineno-17-4"></a><span class="n">DLOG_FIRST_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span> </span><span id="__span-14-4"><a id="__codelineno-14-4" name="__codelineno-14-4" href="#__codelineno-14-4"></a><span class="n">DLOG_FIRST_N</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mi">10</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got the &quot;</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="n">google</span><span class="o">::</span><span class="n">COUNTER</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;th cookie&quot;</span><span class="p">;</span>
</span><span id="__span-17-5"><a id="__codelineno-17-5" name="__codelineno-17-5" href="#__codelineno-17-5"></a><span class="n">DLOG_EVERY_T</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mf">0.01</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got a cookie&quot;</span><span class="p">;</span> </span><span id="__span-14-5"><a id="__codelineno-14-5" name="__codelineno-14-5" href="#__codelineno-14-5"></a><span class="n">DLOG_EVERY_T</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span><span class="w"> </span><span class="mf">0.01</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Got a cookie&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<h2 id="runtime-checks">Runtime Checks<a class="headerlink" href="#runtime-checks" title="Permanent link">&para;</a></h2> <h2 id="runtime-checks">Runtime Checks<a class="headerlink" href="#runtime-checks" title="Permanent link">&para;</a></h2>
<p>It is a good practice to check expected conditions in your program <p>It is a good practice to check expected conditions in your program
@ -1321,7 +1193,7 @@ similar to the <code>assert</code> macro defined in the standard C library.</p>
<code>assert</code>, it is <strong>not</strong> controlled by <code>NDEBUG</code>, so the check will be executed <code>assert</code>, it is <strong>not</strong> controlled by <code>NDEBUG</code>, so the check will be executed
regardless of compilation mode. Therefore, <code>fp-&gt;Write(x)</code> in the following regardless of compilation mode. Therefore, <code>fp-&gt;Write(x)</code> in the following
example is always executed:</p> example is always executed:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-18-1"><a id="__codelineno-18-1" name="__codelineno-18-1" href="#__codelineno-18-1"></a><span class="n">CHECK</span><span class="p">(</span><span class="n">fp</span><span class="o">-&gt;</span><span class="n">Write</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Write failed!&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-15-1"><a id="__codelineno-15-1" name="__codelineno-15-1" href="#__codelineno-15-1"></a><span class="n">CHECK</span><span class="p">(</span><span class="n">fp</span><span class="o">-&gt;</span><span class="n">Write</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="mi">4</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Write failed!&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>There are various helper macros for equality/inequality checks <p>There are various helper macros for equality/inequality checks
-<code>CHECK_EQ</code>, <code>CHECK_NE</code>, <code>CHECK_LE</code>, <code>CHECK_LT</code>, <code>CHECK_GE</code>, and -<code>CHECK_EQ</code>, <code>CHECK_NE</code>, <code>CHECK_LE</code>, <code>CHECK_LT</code>, <code>CHECK_GE</code>, and
@ -1329,28 +1201,28 @@ example is always executed:</p>
values when the result is not as expected. The values must have values when the result is not as expected. The values must have
<code class="language-cpp highlight"><span class="k">operator</span><span class="o">&lt;&lt;</span><span class="p">(</span><span class="n">ostream</span><span class="p">,</span><span class="w"> </span><span class="p">...)</span></code> defined.</p> <code class="language-cpp highlight"><span class="k">operator</span><span class="o">&lt;&lt;</span><span class="p">(</span><span class="n">ostream</span><span class="p">,</span><span class="w"> </span><span class="p">...)</span></code> defined.</p>
<p>You may append to the error message like so:</p> <p>You may append to the error message like so:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-19-1"><a id="__codelineno-19-1" name="__codelineno-19-1" href="#__codelineno-19-1"></a><span class="n">CHECK_NE</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;: The world must be ending!&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-16-1"><a id="__codelineno-16-1" name="__codelineno-16-1" href="#__codelineno-16-1"></a><span class="n">CHECK_NE</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;: The world must be ending!&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>We are very careful to ensure that each argument is evaluated exactly <p>We are very careful to ensure that each argument is evaluated exactly
once, and that anything which is legal to pass as a function argument is legal once, and that anything which is legal to pass as a function argument is legal
here. In particular, the arguments may be temporary expressions which will end here. In particular, the arguments may be temporary expressions which will end
up being destroyed at the end of the apparent statement, for example:</p> up being destroyed at the end of the apparent statement, for example:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-20-1"><a id="__codelineno-20-1" name="__codelineno-20-1" href="#__codelineno-20-1"></a><span class="n">CHECK_EQ</span><span class="p">(</span><span class="n">string</span><span class="p">(</span><span class="s">&quot;abc&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="err"></span><span class="n">b</span><span class="err"></span><span class="p">);</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-17-1"><a id="__codelineno-17-1" name="__codelineno-17-1" href="#__codelineno-17-1"></a><span class="n">CHECK_EQ</span><span class="p">(</span><span class="n">string</span><span class="p">(</span><span class="s">&quot;abc&quot;</span><span class="p">)[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="err"></span><span class="n">b</span><span class="err"></span><span class="p">);</span>
</span></code></pre></div> </span></code></pre></div>
<p>The compiler reports an error if one of the arguments is a pointer and the other <p>The compiler reports an error if one of the arguments is a pointer and the other
is <code class="language-cpp highlight"><span class="k">nullptr</span></code>. To work around this, simply <code class="language-cpp highlight"><span class="k">static_cast</span></code> <code class="language-cpp highlight"><span class="k">nullptr</span></code> to the type of the desired pointer.</p> is <code class="language-cpp highlight"><span class="k">nullptr</span></code>. To work around this, simply <code class="language-cpp highlight"><span class="k">static_cast</span></code> <code class="language-cpp highlight"><span class="k">nullptr</span></code> to the type of the desired pointer.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-21-1"><a id="__codelineno-21-1" name="__codelineno-21-1" href="#__codelineno-21-1"></a><span class="n">CHECK_EQ</span><span class="p">(</span><span class="n">some_ptr</span><span class="p">,</span><span class="w"> </span><span class="k">static_cast</span><span class="o">&lt;</span><span class="n">SomeType</span><span class="o">*&gt;</span><span class="p">(</span><span class="k">nullptr</span><span class="p">));</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-18-1"><a id="__codelineno-18-1" name="__codelineno-18-1" href="#__codelineno-18-1"></a><span class="n">CHECK_EQ</span><span class="p">(</span><span class="n">some_ptr</span><span class="p">,</span><span class="w"> </span><span class="k">static_cast</span><span class="o">&lt;</span><span class="n">SomeType</span><span class="o">*&gt;</span><span class="p">(</span><span class="k">nullptr</span><span class="p">));</span>
</span></code></pre></div> </span></code></pre></div>
<p>Better yet, use the <code>CHECK_NOTNULL</code> macro:</p> <p>Better yet, use the <code>CHECK_NOTNULL</code> macro:</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-22-1"><a id="__codelineno-22-1" name="__codelineno-22-1" href="#__codelineno-22-1"></a><span class="n">CHECK_NOTNULL</span><span class="p">(</span><span class="n">some_ptr</span><span class="p">);</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-19-1"><a id="__codelineno-19-1" name="__codelineno-19-1" href="#__codelineno-19-1"></a><span class="n">CHECK_NOTNULL</span><span class="p">(</span><span class="n">some_ptr</span><span class="p">);</span>
</span><span id="__span-22-2"><a id="__codelineno-22-2" name="__codelineno-22-2" href="#__codelineno-22-2"></a><span class="n">some_ptr</span><span class="o">-&gt;</span><span class="n">DoSomething</span><span class="p">();</span> </span><span id="__span-19-2"><a id="__codelineno-19-2" name="__codelineno-19-2" href="#__codelineno-19-2"></a><span class="n">some_ptr</span><span class="o">-&gt;</span><span class="n">DoSomething</span><span class="p">();</span>
</span></code></pre></div> </span></code></pre></div>
<p>Since this macro returns the given pointer, this is very useful in <p>Since this macro returns the given pointer, this is very useful in
constructor initializer lists.</p> constructor initializer lists.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-23-1"><a id="__codelineno-23-1" name="__codelineno-23-1" href="#__codelineno-23-1"></a><span class="k">struct</span><span class="w"> </span><span class="nc">S</span><span class="w"> </span><span class="p">{</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-20-1"><a id="__codelineno-20-1" name="__codelineno-20-1" href="#__codelineno-20-1"></a><span class="k">struct</span><span class="w"> </span><span class="nc">S</span><span class="w"> </span><span class="p">{</span>
</span><span id="__span-23-2"><a id="__codelineno-23-2" name="__codelineno-23-2" href="#__codelineno-23-2"></a><span class="w"> </span><span class="n">S</span><span class="p">(</span><span class="n">Something</span><span class="o">*</span><span class="w"> </span><span class="n">ptr</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">ptr_</span><span class="p">(</span><span class="n">CHECK_NOTNULL</span><span class="p">(</span><span class="n">ptr</span><span class="p">))</span><span class="w"> </span><span class="p">{}</span> </span><span id="__span-20-2"><a id="__codelineno-20-2" name="__codelineno-20-2" href="#__codelineno-20-2"></a><span class="w"> </span><span class="n">S</span><span class="p">(</span><span class="n">Something</span><span class="o">*</span><span class="w"> </span><span class="n">ptr</span><span class="p">)</span><span class="w"> </span><span class="o">:</span><span class="w"> </span><span class="n">ptr_</span><span class="p">(</span><span class="n">CHECK_NOTNULL</span><span class="p">(</span><span class="n">ptr</span><span class="p">))</span><span class="w"> </span><span class="p">{}</span>
</span><span id="__span-23-3"><a id="__codelineno-23-3" name="__codelineno-23-3" href="#__codelineno-23-3"></a><span class="w"> </span><span class="n">Something</span><span class="o">*</span><span class="w"> </span><span class="n">ptr_</span><span class="p">;</span> </span><span id="__span-20-3"><a id="__codelineno-20-3" name="__codelineno-20-3" href="#__codelineno-20-3"></a><span class="w"> </span><span class="n">Something</span><span class="o">*</span><span class="w"> </span><span class="n">ptr_</span><span class="p">;</span>
</span><span id="__span-23-4"><a id="__codelineno-23-4" name="__codelineno-23-4" href="#__codelineno-23-4"></a><span class="p">};</span> </span><span id="__span-20-4"><a id="__codelineno-20-4" name="__codelineno-20-4" href="#__codelineno-20-4"></a><span class="p">};</span>
</span></code></pre></div> </span></code></pre></div>
<div class="admonition warning"> <div class="admonition warning">
<p class="admonition-title">Warning</p> <p class="admonition-title">Warning</p>
@ -1368,7 +1240,7 @@ They treat <code class="language-cpp highlight"><span class="k">nullptr</span></
<p class="admonition-title">Note</p> <p class="admonition-title">Note</p>
<p>Both arguments may be temporary objects which are destructed at the <p>Both arguments may be temporary objects which are destructed at the
end of the current <em>full expression</em>, such as</p> end of the current <em>full expression</em>, such as</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-24-1"><a id="__codelineno-24-1" name="__codelineno-24-1" href="#__codelineno-24-1"></a><span class="n">CHECK_STREQ</span><span class="p">(</span><span class="n">Foo</span><span class="p">().</span><span class="n">c_str</span><span class="p">(),</span><span class="w"> </span><span class="n">Bar</span><span class="p">().</span><span class="n">c_str</span><span class="p">());</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-21-1"><a id="__codelineno-21-1" name="__codelineno-21-1" href="#__codelineno-21-1"></a><span class="n">CHECK_STREQ</span><span class="p">(</span><span class="n">Foo</span><span class="p">().</span><span class="n">c_str</span><span class="p">(),</span><span class="w"> </span><span class="n">Bar</span><span class="p">().</span><span class="n">c_str</span><span class="p">());</span>
</span></code></pre></div> </span></code></pre></div>
<p>where <code>Foo</code> and <code>Bar</code> return <code>std::string</code>.</p> <p>where <code>Foo</code> and <code>Bar</code> return <code>std::string</code>.</p>
</div> </div>
@ -1386,7 +1258,7 @@ for detail.</p>
<p><code>PLOG()</code> and <code>PLOG_IF()</code> and <code>PCHECK()</code> behave exactly like their <code>LOG*</code> and <p><code>PLOG()</code> and <code>PLOG_IF()</code> and <code>PCHECK()</code> behave exactly like their <code>LOG*</code> and
<code>CHECK</code> equivalents with the addition that they append a description of the <code>CHECK</code> equivalents with the addition that they append a description of the
current state of <code>errno</code> to their output lines. E.g.</p> current state of <code>errno</code> to their output lines. E.g.</p>
<div class="language-cpp highlight"><pre><span></span><code><span id="__span-25-1"><a id="__codelineno-25-1" name="__codelineno-25-1" href="#__codelineno-25-1"></a><span class="n">PCHECK</span><span class="p">(</span><span class="n">write</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="k">nullptr</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Write nullptr failed&quot;</span><span class="p">;</span> <div class="language-cpp highlight"><pre><span></span><code><span id="__span-22-1"><a id="__codelineno-22-1" name="__codelineno-22-1" href="#__codelineno-22-1"></a><span class="n">PCHECK</span><span class="p">(</span><span class="n">write</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="k">nullptr</span><span class="p">,</span><span class="w"> </span><span class="mi">2</span><span class="p">)</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="o">&lt;&lt;</span><span class="w"> </span><span class="s">&quot;Write nullptr failed&quot;</span><span class="p">;</span>
</span></code></pre></div> </span></code></pre></div>
<p>This check fails with the following error message.</p> <p>This check fails with the following error message.</p>
<div class="language-text highlight"><pre><span></span><code>F0825 185142 test.cc:22] Check failed: write(1, nullptr, 2) &gt;= 0 Write nullptr failed: Bad address [14] <div class="language-text highlight"><pre><span></span><code>F0825 185142 test.cc:22] Check failed: write(1, nullptr, 2) &gt;= 0 Write nullptr failed: Bad address [14]
@ -1420,7 +1292,7 @@ sparingly.</p>
<span class="md-icon" title="Last update"> <span class="md-icon" title="Last update">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span> </span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 11, 2024</span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 12, 2024</span>
</span> </span>

View File

@ -492,6 +492,8 @@

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,7 @@
<link rel="canonical" href="https://google.github.io/glog/0.8.0/sinks/"> <link rel="canonical" href="https://google.github.io/glog/0.8.0/sinks/">
<link rel="prev" href="../logging/"> <link rel="prev" href="../flags/">
<link rel="next" href="../failures/"> <link rel="next" href="../failures/">
@ -356,6 +356,8 @@
@ -414,6 +416,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>

View File

@ -2,67 +2,72 @@
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://google.github.io/glog/0.8.0/</loc> <loc>https://google.github.io/glog/0.8.0/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/build/</loc> <loc>https://google.github.io/glog/0.8.0/build/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/contribute/</loc> <loc>https://google.github.io/glog/0.8.0/contribute/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/failures/</loc> <loc>https://google.github.io/glog/0.8.0/failures/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq>
</url>
<url>
<loc>https://google.github.io/glog/0.8.0/flags/</loc>
<lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/license/</loc> <loc>https://google.github.io/glog/0.8.0/license/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/log_cleaner/</loc> <loc>https://google.github.io/glog/0.8.0/log_cleaner/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/log_stripping/</loc> <loc>https://google.github.io/glog/0.8.0/log_stripping/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/logging/</loc> <loc>https://google.github.io/glog/0.8.0/logging/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/packages/</loc> <loc>https://google.github.io/glog/0.8.0/packages/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/sinks/</loc> <loc>https://google.github.io/glog/0.8.0/sinks/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/unwinder/</loc> <loc>https://google.github.io/glog/0.8.0/unwinder/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/usage/</loc> <loc>https://google.github.io/glog/0.8.0/usage/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
<url> <url>
<loc>https://google.github.io/glog/0.8.0/windows/</loc> <loc>https://google.github.io/glog/0.8.0/windows/</loc>
<lastmod>2024-06-11</lastmod> <lastmod>2024-06-12</lastmod>
<changefreq>daily</changefreq> <changefreq>daily</changefreq>
</url> </url>
</urlset> </urlset>

Binary file not shown.

View File

@ -356,6 +356,8 @@
@ -416,6 +418,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="../sinks/" class="md-nav__link"> <a href="../sinks/" class="md-nav__link">
@ -518,10 +541,10 @@
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_6" checked> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_7" checked>
<label class="md-nav__link" for="__nav_2_6" id="__nav_2_6_label" tabindex="0"> <label class="md-nav__link" for="__nav_2_7" id="__nav_2_7_label" tabindex="0">
<span class="md-ellipsis"> <span class="md-ellipsis">
@ -532,8 +555,8 @@
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>
</label> </label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_6_label" aria-expanded="true"> <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_7_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_2_6"> <label class="md-nav__title" for="__nav_2_7">
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>
System-specific Considerations System-specific Considerations
</label> </label>

View File

@ -444,6 +444,8 @@

View File

@ -356,6 +356,8 @@
@ -416,6 +418,27 @@
<li class="md-nav__item">
<a href="../flags/" class="md-nav__link">
<span class="md-ellipsis">
Adjusting Output
</span>
</a>
</li>
<li class="md-nav__item"> <li class="md-nav__item">
<a href="../sinks/" class="md-nav__link"> <a href="../sinks/" class="md-nav__link">
@ -518,10 +541,10 @@
<input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_6" checked> <input class="md-nav__toggle md-toggle " type="checkbox" id="__nav_2_7" checked>
<label class="md-nav__link" for="__nav_2_6" id="__nav_2_6_label" tabindex="0"> <label class="md-nav__link" for="__nav_2_7" id="__nav_2_7_label" tabindex="0">
<span class="md-ellipsis"> <span class="md-ellipsis">
@ -532,8 +555,8 @@
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>
</label> </label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_6_label" aria-expanded="true"> <nav class="md-nav" data-md-level="2" aria-labelledby="__nav_2_7_label" aria-expanded="true">
<label class="md-nav__title" for="__nav_2_6"> <label class="md-nav__title" for="__nav_2_7">
<span class="md-nav__icon md-icon"></span> <span class="md-nav__icon md-icon"></span>
System-specific Considerations System-specific Considerations
</label> </label>
@ -716,14 +739,21 @@ functions defined in <code>glog/logging.h</code>.</p>
</span><span id="__span-1-11"><a id="__codelineno-1-11" name="__codelineno-1-11" href="#__codelineno-1-11"></a><span class="n">google</span><span class="o">::</span><span class="n">FlushLogFiles</span><span class="p">(</span><span class="n">google</span><span class="o">::</span><span class="n">GLOG_ERROR</span><span class="p">);</span> </span><span id="__span-1-11"><a id="__codelineno-1-11" name="__codelineno-1-11" href="#__codelineno-1-11"></a><span class="n">google</span><span class="o">::</span><span class="n">FlushLogFiles</span><span class="p">(</span><span class="n">google</span><span class="o">::</span><span class="n">GLOG_ERROR</span><span class="p">);</span>
</span></code></pre></div> </span></code></pre></div>
<p>If you don't need <code>ERROR</code> defined by <code>windows.h</code>, there are a couple of more <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:</p> workarounds which sometimes don't work<sup id="fnref:1"><a class="footnote-ref" href="#fn:1">1</a></sup>:</p>
<ul> <ul>
<li><code class="language-cpp highlight"><span class="cp">#define WIN32_LEAN_AND_MEAN</span></code> or <code>NOGDI</code> <strong>before</strong> <li><code class="language-cpp highlight"><span class="cp">#define WIN32_LEAN_AND_MEAN</span></code> or <code>NOGDI</code> <strong>before</strong>
<code class="language-cpp highlight"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;windows.h&gt;</span></code>.</li> <code class="language-cpp highlight"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;windows.h&gt;</span></code>.</li>
<li><code class="language-cpp highlight"><span class="cp">#undef ERROR</span></code> <strong>after</strong> <code class="language-cpp highlight"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;windows.h&gt;</span></code>.</li> <li><code class="language-cpp highlight"><span class="cp">#undef ERROR</span></code> <strong>after</strong> <code class="language-cpp highlight"><span class="cp">#include</span><span class="w"> </span><span class="cpf">&lt;windows.h&gt;</span></code>.</li>
</ul> </ul>
<p>See <a href="http://code.google.com/p/google-glog/issues/detail?id=33">this issue</a> for <div class="footnote">
more detail.</p> <hr />
<ol>
<li id="fn:1">
<p>For more information refer to <a href="http://code.google.com/p/google-glog/issues/detail?id=33">this
issue</a>.&#160;<a class="footnote-backref" href="#fnref:1" title="Jump back to footnote 1 in the text">&#8617;</a></p>
</li>
</ol>
</div>
@ -746,7 +776,7 @@ more detail.</p>
<span class="md-icon" title="Last update"> <span class="md-icon" title="Last update">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M21 13.1c-.1 0-.3.1-.4.2l-1 1 2.1 2.1 1-1c.2-.2.2-.6 0-.8l-1.3-1.3c-.1-.1-.2-.2-.4-.2m-1.9 1.8-6.1 6V23h2.1l6.1-6.1-2.1-2M12.5 7v5.2l4 2.4-1 1L11 13V7h1.5M11 21.9c-5.1-.5-9-4.8-9-9.9C2 6.5 6.5 2 12 2c5.3 0 9.6 4.1 10 9.3-.3-.1-.6-.2-1-.2s-.7.1-1 .2C19.6 7.2 16.2 4 12 4c-4.4 0-8 3.6-8 8 0 4.1 3.1 7.5 7.1 7.9l-.1.2v1.8Z"/></svg>
</span> </span>
<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 11, 2024</span> <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">June 12, 2024</span>
</span> </span>