consolidate readme

This commit is contained in:
Sergiu Deitsch 2021-02-13 12:40:34 +01:00
parent e370cd5166
commit b9be6bb5db
2 changed files with 96 additions and 100 deletions

View File

@ -7,6 +7,19 @@ The Google Logging Library (glog) implements application-level logging.
The library provides logging APIs based on C++-style streams and various The library provides logging APIs based on C++-style streams and various
helper macros. helper macros.
.. role:: cmake(code)
:language: cmake
.. role:: cmd(code)
:language: bash
.. role:: cpp(code)
:language: cpp
.. role:: bazel(code)
:language: starlark
Getting Started Getting Started
--------------- ---------------
@ -45,7 +58,7 @@ To use glog within a project which uses the
`Bazel <https://bazel.build/>`__ build tool, add the following lines to `Bazel <https://bazel.build/>`__ build tool, add the following lines to
your ``WORKSPACE`` file: your ``WORKSPACE`` file:
.. code:: starlark .. code:: bazel
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
@ -63,11 +76,11 @@ your ``WORKSPACE`` file:
urls = ["https://github.com/google/glog/archive/d516278b1cd33cd148e8989aec488b6049a4ca0b.zip"], urls = ["https://github.com/google/glog/archive/d516278b1cd33cd148e8989aec488b6049a4ca0b.zip"],
) )
You can then add ``@com_github_google_glog//:glog`` to the deps section of a You can then add :bazel:`@com_github_google_glog//:glog` to the deps section
``cc_binary`` or ``cc_library`` rule, and ``#include <glog/logging.h>`` to of a :bazel:`cc_binary` or :bazel:`cc_library` rule, and :code:`#include
include it in your source code. Heres a simple example: <glog/logging.h>` to include it in your source code. Heres a simple example:
.. code:: starlark .. code:: bazel
cc_binary( cc_binary(
name = "main", name = "main",
@ -98,7 +111,7 @@ GNU Make as build tool, the typical workflow is:
.. code:: bash .. code:: bash
git clone git@github.com:google/glog.git git clone https://github.com/google/glog.git
cd glog cd glog
2. Run CMake to configure the build tree. 2. Run CMake to configure the build tree.
@ -107,7 +120,11 @@ GNU Make as build tool, the typical workflow is:
cmake -H . -B build -G "Unix Makefiles" cmake -H . -B build -G "Unix Makefiles"
Note: to get the list of available generators (e.g., Visual Studio), use ``-G ""`` CMake provides different generators, and by default will pick the most
relevant one to your environment. If you need a specific version of Visual
Studio, use :cmd:`cmake . -G <generator-name>`, and see :cmd:`cmake --help`
for the available generators. Also see :cmd:`-T <toolset-name>`, which can
be used to request the native x64 toolchain with :cmd:`-T host=x64`.
3. Afterwards, generated files can be used to compile the project. 3. Afterwards, generated files can be used to compile the project.
@ -131,7 +148,7 @@ Consuming glog in a CMake Project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you have glog installed in your system, you can use the CMake command If you have glog installed in your system, you can use the CMake command
``find_package`` to build against glog in your CMake Project as follows: :cmake:`find_package` to build against glog in your CMake Project as follows:
.. code:: cmake .. code:: cmake
@ -149,11 +166,11 @@ target as needed.
Incorporating glog into a CMake Project Incorporating glog into a CMake Project
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
You can also use the CMake command ``add_subdirectory`` to include glog You can also use the CMake command :cmake:`add_subdirectory` to include glog
directly from a subdirectory of your project by replacing the directly from a subdirectory of your project by replacing the
``find_package`` call from the previous example by ``add_subdirectory``. :cmake:`find_package` call from the previous example by
The ``glog::glog`` target is in this case an ``ALIAS`` library target :cmake:`add_subdirectory`. The :cmake:`glog::glog` target is in this case an
for the ``glog`` library target. :cmake:`ALIAS` library target for the ``glog`` library target.
Again, compile definitions and options will be added automatically to Again, compile definitions and options will be added automatically to
your target as needed. your target as needed.
@ -161,8 +178,8 @@ your target as needed.
vcpkg vcpkg
~~~~~ ~~~~~
The url of vcpkg is: https://github.com/Microsoft/vcpkg You can download You can download and install glog using the `vcpkg
and install glog using the vcpkg dependency manager: <https://github.com/Microsoft/vcpkg>`__ dependency manager:
.. code:: bash .. code:: bash
@ -185,10 +202,10 @@ the command line, log based on conditionals, abort the program when
expected conditions are not met, introduce your own verbose logging expected conditions are not met, introduce your own verbose logging
levels, and more. levels, and more.
Following sections describe the functionality supported by glog. Please Following sections describe the functionality supported by glog. Please note
note this description may not be complete but limited to the most useful this description may not be complete but limited to the most useful ones. If you
ones. If you want to find less common features, please check header want to find less common features, please check header files under `src/glog
files under ``src/glog`` directory. <src/glog>`__ directory.
Severity Levels Severity Levels
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
@ -215,13 +232,11 @@ By default, glog copies the log messages of severity level ``ERROR`` or
Setting Flags Setting Flags
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
Several flags influence glogs output behavior. If the `Google gflags Several flags influence glogs output behavior. If the `Google gflags library
library <https://github.com/gflags/gflags>`__ is installed on your <https://github.com/gflags/gflags>`__ is installed on your machine, the build
machine, the ``configure`` script (see the INSTALL file in the package system will automatically detect and use it, allowing you to pass flags on the
for detail of this script) will automatically detect and use it, command line. For example, if you want to turn the flag :cmd:`--logtostderr` on,
allowing you to pass flags on the command line. For example, if you want you can start your application with the following command line:
to turn the flag ``--logtostderr`` on, you can start your application
with the following command line:
.. code:: bash .. code:: bash
@ -258,7 +273,7 @@ The following flags are most commonly used:
``v`` (``int``, default=0) ``v`` (``int``, default=0)
Show all ``VLOG(m)`` messages for ``m`` less or equal the value of Show all ``VLOG(m)`` messages for ``m`` less or equal the value of
this flag. Overridable by ``--vmodule``. See `the section about this flag. Overridable by :cmd:`--vmodule`. See `the section about
verbose logging <#verbose>`__ for more detail. verbose logging <#verbose>`__ for more detail.
``vmodule`` (``string``, default="") ``vmodule`` (``string``, default="")
@ -266,7 +281,7 @@ The following flags are most commonly used:
comma-separated list of <module name>=<log level>. <module name> is 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 glob pattern (e.g., ``gfs*`` for all modules whose name starts with
"gfs"), matched against the filename base (that is, name ignoring "gfs"), matched against the filename base (that is, name ignoring
.cc/.h./-inl.h). <log level> overrides any value given by ``--v``. .cc/.h./-inl.h). <log level> overrides any value given by :cmd:`--v`.
See also `the section about verbose logging <#verbose>`__. See also `the section about verbose logging <#verbose>`__.
There are some other flags defined in logging.cc. Please grep the source There are some other flags defined in logging.cc. Please grep the source
@ -276,7 +291,7 @@ You can also modify flag values in your program by modifying global
variables ``FLAGS_*`` . Most settings start working immediately after variables ``FLAGS_*`` . Most settings start working immediately after
you update ``FLAGS_*`` . The exceptions are the flags related to you update ``FLAGS_*`` . The exceptions are the flags related to
destination files. For example, you might want to set ``FLAGS_log_dir`` destination files. For example, you might want to set ``FLAGS_log_dir``
before calling ``google::InitGoogleLogging`` . Here is an example: before calling :cpp:`google::InitGoogleLogging` . Here is an example:
.. code:: cpp .. code:: cpp
@ -367,7 +382,7 @@ There are various helper macros for equality/inequality checks -
``CHECK_EQ``, ``CHECK_NE``, ``CHECK_LE``, ``CHECK_LT``, ``CHECK_GE``, ``CHECK_EQ``, ``CHECK_NE``, ``CHECK_LE``, ``CHECK_LT``, ``CHECK_GE``,
and ``CHECK_GT``. They compare two values, and log a ``FATAL`` message 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 including the two values when the result is not as expected. The values
must have ``operator<<(ostream, ...)`` defined. must have :cpp:`operator<<(ostream, ...)` defined.
You may append to the error message like so: You may append to the error message like so:
@ -385,9 +400,9 @@ for example:
CHECK_EQ(string("abc")[1], b); CHECK_EQ(string("abc")[1], b);
The compiler reports an error if one of the arguments is a pointer and The compiler reports an error if one of the arguments is a pointer and the other
the other is ``NULL``. To work around this, simply ``static_cast`` is :cpp:`NULL`. To work around this, simply :cpp:`static_cast` :cpp:`NULL` to
``NULL`` to the type of the desired pointer. the type of the desired pointer.
.. code:: cpp .. code:: cpp
@ -414,17 +429,17 @@ Note that you cannot use this macro as a C++ stream due to this feature.
Please use ``CHECK_EQ`` described above to log a custom message before Please use ``CHECK_EQ`` described above to log a custom message before
aborting the application. aborting the application.
If you are comparing C strings (``char *``), a handy set of macros If you are comparing C strings (:cpp:`char *`), a handy set of macros performs
performs case sensitive as well as case insensitive comparisons - case sensitive as well as case insensitive comparisons - ``CHECK_STREQ``,
``CHECK_STREQ``, ``CHECK_STRNE``, ``CHECK_STRCASEEQ``, and ``CHECK_STRNE``, ``CHECK_STRCASEEQ``, and ``CHECK_STRCASENE``. The CASE versions
``CHECK_STRCASENE``. The CASE versions are case-insensitive. You can are case-insensitive. You can safely pass :cpp:`NULL` pointers for this macro. They
safely pass ``NULL`` pointers for this macro. They treat ``NULL`` and treat :cpp:`NULL` and any non-:cpp:`NULL` string as not equal. Two :cpp:`NULL`\
any non-``NULL`` string as not equal. Two ``NULL``\ s are equal. s are equal.
Note that both arguments may be temporary strings which are destructed Note that both arguments may be temporary strings which are destructed
at the end of the current "full expression" (e.g., at the end of the current "full expression" (e.g.,
``CHECK_STREQ(Foo().c_str(), Bar().c_str())`` where ``Foo`` and ``Bar`` :cpp:`CHECK_STREQ(Foo().c_str(), Bar().c_str())` where ``Foo`` and ``Bar``
return C++s ``std::string``). return C++s :cpp:`std::string`).
The ``CHECK_DOUBLE_EQ`` macro checks the equality of two floating point The ``CHECK_DOUBLE_EQ`` macro checks the equality of two floating point
values, accepting a small error margin. ``CHECK_NEAR`` accepts a third values, accepting a small error margin. ``CHECK_NEAR`` accepts a third
@ -433,27 +448,26 @@ floating point argument, which specifies the acceptable error margin.
Verbose Logging Verbose Logging
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~
When you are chasing difficult bugs, thorough log messages are very When you are chasing difficult bugs, thorough log messages are very useful.
useful. However, you may want to ignore too verbose messages in usual However, you may want to ignore too verbose messages in usual development. For
development. For such verbose logging, glog provides the ``VLOG`` macro, such verbose logging, glog provides the ``VLOG`` macro, which allows you to
which allows you to define your own numeric logging levels. The ``--v`` define your own numeric logging levels. The :cmd:`--v` command line option
command line option controls which verbose messages are logged: controls which verbose messages are logged:
.. code:: cpp .. code:: cpp
VLOG(1) << "Im printed when you run the program with --v=1 or higher"; 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"; 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 With ``VLOG``, the lower the verbose level, the more likely messages are to be
to be logged. For example, if ``--v==1``, ``VLOG(1)`` will log, but logged. For example, if :cmd:`--v==1`, ``VLOG(1)`` will log, but ``VLOG(2)``
``VLOG(2)`` will not log. This is opposite of the severity level, where will not log. This is opposite of the severity level, where ``INFO`` is 0, and
``INFO`` is 0, and ``ERROR`` is 2. ``--minloglevel`` of 1 will log ``ERROR`` is 2. :cmd:`--minloglevel` of 1 will log ``WARNING`` and above. Though
``WARNING`` and above. Though you can specify any integers for both you can specify any integers for both ``VLOG`` macro and :cmd:`--v` flag, the
``VLOG`` macro and ``--v`` flag, the common values for them are small common values for them are small positive integers. For example, if you write
positive integers. For example, if you write ``VLOG(0)``, you should ``VLOG(0)``, you should specify :cmd:`--v=-1` or lower to silence it. This is
specify ``--v=-1`` or lower to silence it. This is less useful since we less useful since we may not want verbose logs by default in most cases. The
may not want verbose logs by default in most cases. The ``VLOG`` macros ``VLOG`` macros always log at the ``INFO`` log level (when they log at all).
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 Verbose logging can be controlled from the command line on a per-module
basis: basis:
@ -474,7 +488,7 @@ or more characters) and ? (matches any single character) wildcards.
Please also check the section about `command line flags <#flags>`__. Please also check the section about `command line flags <#flags>`__.
Theres also ``VLOG_IS_ON(n)`` "verbose level" condition macro. This Theres also ``VLOG_IS_ON(n)`` "verbose level" condition macro. This
macro returns true when the ``--v`` is equal or greater than ``n``. To macro returns true when the :cmd:`--v` is equal or greater than ``n``. To
be used as be used as
.. code:: cpp .. code:: cpp
@ -506,10 +520,9 @@ Failure Signal Handler
~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~
The library provides a convenient signal handler that will dump useful The library provides a convenient signal handler that will dump useful
information when the program crashes on certain signals such as information when the program crashes on certain signals such as ``SIGSEGV``. The
``SIGSEGV``. The signal handler can be installed by signal handler can be installed by :cpp:`google::InstallFailureSignalHandler()`.
``google::InstallFailureSignalHandler()``. The following is an example The following is an example of output from the signal handler.
of output from the signal handler.
:: ::
@ -527,13 +540,13 @@ of output from the signal handler.
@ 0x4046f9 (unknown) @ 0x4046f9 (unknown)
By default, the signal handler writes the failure dump to the standard By default, the signal handler writes the failure dump to the standard
error. You can customize the destination by ``InstallFailureWriter()``. error. You can customize the destination by :cpp:`InstallFailureWriter()`.
Performance of Messages Performance of Messages
~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~
The conditional logging macros provided by glog (e.g., ``CHECK``, The conditional logging macros provided by glog (e.g., ``CHECK``,
``LOG_IF``, ``VLOG``, ...) are carefully implemented and dont execute ``LOG_IF``, ``VLOG``, etc.) are carefully implemented and dont execute
the right hand side expressions when the conditions are false. So, the the right hand side expressions when the conditions are false. So, the
following check may not sacrifice the performance of your application. following check may not sacrifice the performance of your application.
@ -546,7 +559,7 @@ User-defined Failure Function
``FATAL`` severity level messages or unsatisfied ``CHECK`` condition ``FATAL`` severity level messages or unsatisfied ``CHECK`` condition
terminate your program. You can change the behavior of the termination terminate your program. You can change the behavior of the termination
by ``InstallFailureFunction``. by :cpp:`InstallFailureFunction`.
.. code:: cpp .. code:: cpp
@ -567,11 +580,11 @@ September 2008, glog supports stack tracing for x86 and x86_64).
Raw Logging Raw Logging
~~~~~~~~~~~ ~~~~~~~~~~~
The header file ``<glog/raw_logging.h>`` can be used for thread-safe The header file ``<glog/raw_logging.h>`` can be used for thread-safe logging,
logging, which does not allocate any memory or acquire any locks. which does not allocate any memory or acquire any locks. Therefore, the macros
Therefore, the macros defined in this header file can be used by defined in this header file can be used by low-level memory allocation and
low-level memory allocation and synchronization code. Please check synchronization code. Please check `src/glog/raw_logging.h.in
``src/glog/raw_logging.h.in`` for detail. <src/glog/raw_logging.h.in>`__ for detail.
Google Style ``perror()`` Google Style ``perror()``
~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
@ -692,15 +705,15 @@ more detail.
Installation Notes for 64-bit Linux Systems Installation Notes for 64-bit Linux Systems
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The glibc built-in stack-unwinder on 64-bit systems has some problems The glibc built-in stack-unwinder on 64-bit systems has some problems with glog.
with glog. (In particular, if you are using (In particular, if you are using :cpp:`InstallFailureSignalHandler()`, the
InstallFailureSignalHandler(), the signal may be raised in the middle of signal may be raised in the middle of malloc, holding some malloc-related locks
malloc, holding some malloc-related locks when they invoke the stack when they invoke the stack unwinder. The built-in stack unwinder may call malloc
unwinder. The built-in stack unwinder may call malloc recursively, which recursively, which may require the thread to acquire a lock it already holds:
may require the thread to acquire a lock it already holds: deadlock.) deadlock.)
For that reason, if you use a 64-bit system and you need For that reason, if you use a 64-bit system and you need
``InstallFailureSignalHandler()``, we strongly recommend you install :cpp:`InstallFailureSignalHandler()`, we strongly recommend you install
``libunwind`` before trying to configure or install google glog. ``libunwind`` before trying to configure or install google glog.
libunwind can be found libunwind can be found
`here <http://download.savannah.nongnu.org/releases/libunwind/libunwind-snap-070410.tar.gz>`__. `here <http://download.savannah.nongnu.org/releases/libunwind/libunwind-snap-070410.tar.gz>`__.
@ -716,19 +729,19 @@ handling APIs, but they implement them differently on some platforms.
This is not likely to be a problem on ia64, but may be on x86-64. This is not likely to be a problem on ia64, but may be on x86-64.
Also, if you link binaries statically, make sure that you add Also, if you link binaries statically, make sure that you add
``-Wl,--eh-frame-hdr`` to your linker options. This is required so that :cmd:`-Wl,--eh-frame-hdr` to your linker options. This is required so that
``libunwind`` can find the information generated by the compiler ``libunwind`` can find the information generated by the compiler required for
required for stack unwinding. stack unwinding.
Using ``-static`` is rare, though, so unless you know this will affect Using :cmd:`-static` is rare, though, so unless you know this will affect you it
you it probably wont. probably wont.
If you cannot or do not wish to install libunwind, you can still try to If you cannot or do not wish to install libunwind, you can still try to
use two kinds of stack-unwinder: 1. glibc built-in stack-unwinder and 2. use two kinds of stack-unwinder: 1. glibc built-in stack-unwinder and 2.
frame pointer based stack-unwinder. frame pointer based stack-unwinder.
1. As we already mentioned, glibcs unwinder has a deadlock issue. 1. As we already mentioned, glibcs unwinder has a deadlock issue.
However, if you dont use ``InstallFailureSignalHandler()`` or you However, if you dont use :cpp:`InstallFailureSignalHandler()` or you
dont worry about the rare possibilities of deadlocks, you can use dont worry about the rare possibilities of deadlocks, you can use
this stack-unwinder. If you specify no options and ``libunwind`` this stack-unwinder. If you specify no options and ``libunwind``
isnt detected on your system, the configure script chooses this isnt detected on your system, the configure script chooses this
@ -767,7 +780,7 @@ dont need to do it again.
Once your CLA is submitted (or if you already submitted one for another Once your CLA is submitted (or if you already submitted one for another
Google project), make a commit adding yourself to the Google project), make a commit adding yourself to the
`AUTHORS <./AUTHORS>`__ and `CONTRIBUTORS <CONTRIBUTORS>`__ files. This `AUTHORS <./AUTHORS>`__ and `CONTRIBUTORS <./CONTRIBUTORS>`__ files. This
commit can be part of your first `pull commit can be part of your first `pull
request <https://help.github.com/articles/creating-a-pull-request>`__. request <https://help.github.com/articles/creating-a-pull-request>`__.

View File

@ -1,17 +0,0 @@
This project has been ported to Windows, including stack tracing, signal
handling, and unit tests.
A Visual Studio solution file is explicitly not provided because it is not
maintainable. Instead, a CMake build system exists to generate the correct
solution for your version of Visual Studio.
In short,
(1) Install CMake from: https://cmake.org/download/
(2) With CMake on your PATH, run `cmake .` to generate the build files
(3) Either use `cmake --build`, or open the generated solution
CMake provides different generators, and by default will pick the most relevant
one to your environment. If you need a specific version of Visual Studio, use
`cmake . -G <generator-name>`, and see `cmake --help` for the available
generators. Also see `-T <toolset-name>`, which can used to request the native
x64 toolchain with `-T host=x64`.