# glog **Repository Path**: feuyeux/glog ## Basic Information - **Project Name**: glog - **Description**: sync with https://github.com/google/glog - **Primary Language**: Unknown - **License**: BSD-3-Clause - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2021-09-24 - **Last Updated**: 2025-02-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: GitHub ## README Google Logging Library ====================== |Linux Github actions| |Windows Github actions| |macOS Github actions| |Codecov| Google Logging (glog) is a C++14 library that implements application-level logging. The library provides logging APIs based on C++-style streams and various helper macros. .. role:: cmake(code) :language: cmake .. role:: cmd(code) :language: bash .. role:: cpp(code) :language: cpp .. role:: bazel(code) :language: starlark Getting Started --------------- You can log a message by simply streaming things to ``LOG``\ (`__>), e.g., .. code:: cpp #include int main(int argc, char* argv[]) { // Initialize Google’s logging library. google::InitGoogleLogging(argv[0]); // ... LOG(INFO) << "Found " << num_cookies << " cookies"; } The library can be installed using various package managers or compiled from `source <#building-from-source>`__. For a detailed overview of glog features and their usage, please refer to the `user guide <#user-guide>`__. .. pull-quote:: [!IMPORTANT] The above example requires further `Bazel <#bazel>`__ or `CMake <#usage-in-projects>`__ setup for use in own projects. .. contents:: Table of Contents Usage in Projects ~~~~~~~~~~~~~~~~~ Assuming that glog was previously `built using CMake <#cmake>`__ or installed using a package manager, you can use the CMake command :cmake:`find_package` to build against glog in your CMake project as follows: .. code:: cmake cmake_minimum_required (VERSION 3.16) project (myproj VERSION 1.0) find_package (glog 0.7.0 REQUIRED) add_executable (myapp main.cpp) target_link_libraries (myapp glog::glog) Compile definitions and options will be added automatically to your target as needed. Alternatively, glog can be incorporated into using the CMake command :cmake:`add_subdirectory` to include glog directly from a subdirectory of your project by replacing the :cmake:`find_package` call from the previous snippet by :cmake:`add_subdirectory`. The :cmake:`glog::glog` target is in this case an :cmake:`ALIAS` library target for the ``glog`` library target. Building from Source ~~~~~~~~~~~~~~~~~~~~ Bazel ^^^^^ To use glog within a project which uses the `Bazel `__ build tool, add the following lines to your ``WORKSPACE`` file: .. code:: bazel load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "com_github_gflags_gflags", sha256 = "34af2f15cf7367513b352bdcd2493ab14ce43692d2dcd9dfc499492966c64dcf", strip_prefix = "gflags-2.2.2", urls = ["https://github.com/gflags/gflags/archive/v2.2.2.tar.gz"], ) http_archive( name = "com_github_google_glog", sha256 = "122fb6b712808ef43fbf80f75c52a21c9760683dae470154f02bddfc61135022", strip_prefix = "glog-0.6.0", urls = ["https://github.com/google/glog/archive/v0.6.0.zip"], ) You can then add :bazel:`@com_github_google_glog//:glog` to the deps section of a :bazel:`cc_binary` or :bazel:`cc_library` rule, and :code:`#include ` to include it in your source code. Here’s a simple example: .. code:: bazel cc_binary( name = "main", srcs = ["main.cc"], deps = ["@com_github_google_glog//:glog"], ) CMake ^^^^^ glog can be compiled using `CMake `__ on a wide range of platforms. The typical workflow for building glog on a Unix-like system with GNU Make as build tool is as follows: 1. Clone the repository and change into source directory. .. code:: bash git clone https://github.com/google/glog.git cd glog 2. Run CMake to configure the build tree. .. code:: bash cmake -S . -B build -G "Unix Makefiles" 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 `, and see :cmd:`cmake --help` for the available generators. Also see :cmd:`-T `, 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. .. code:: bash cmake --build build 4. Test the build software (optional). .. code:: bash cmake --build build --target test 5. Install the built files (optional). .. code:: bash cmake --build build --target install Once successfully built, glog can be `integrated into own projects <#usage-in-projects>`__. conan ~~~~~ You can download and install glog using the `conan `__ package manager: .. code:: bash pip install conan conan install -r conancenter glog/@ The glog recipe in conan center is kept up to date by conan center index community contributors. If the version is out of date, please create an issue or pull request on the `conan-center-index `__ repository. vcpkg ~~~~~ You can download and install glog using the `vcpkg `__ dependency manager: .. code:: bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install glog The glog port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository. User Guide ---------- glog defines a series of macros that simplify many common logging tasks. You can log messages by severity level, control logging behavior from the command line, log based on conditionals, abort the program when expected conditions are not met, introduce your own verbose logging levels, customize the prefix attached to log messages, and more. Following sections describe the functionality supported by glog. Please note this description may not be complete but limited to the most useful ones. If you want to find less common features, please check header files under `src/glog `__ directory. 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). .. pull-quote:: [!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 (i.e., there is no ``NDEBUG`` macro defined), but avoids halting the program in production by automatically reducing the severity to ``ERROR``. Unless otherwise specified, glog uses the format :: /...log..-