Google Logging (glog)
repository·master·Indexed 27 days ago
https://github.com/google/glogA C++14 library for application-level logging providing stream-based APIs and helper macros. It features severity levels (INFO, WARNING, ERROR, FATAL), verbose logging (VLOG), runtime condition checks via CHECK macros, and failure signal handling for diagnostic stack traces. The library supports configuration via command-line flags or environment variables and can be built using Bazel or CMake. Note: This project is deprecated and scheduled for archiving on 2025-06-30.
What's inside glog
- Google Logging (glog) is a C++14 library designed for application-level logging. It provides logging APIs using C++-style streams and various helper macros.
Enable the automatic log cleaner
masterYou can enable a background process that automatically removes old log files. When enabled,
glogchecks for overdue logs whenever a flush is performed. A log file is considered overdue if its last modified time is greater than the duration specified. The files are removed usingunlink().using namespace std::chrono_literals; // Keep logs for 3 days google::EnableLogCleaner(24h * 3);Build glog using CMake
masterYou can build glog using CMake on most platforms. The standard workflow involves configuring the build tree withcmake -S . -B build, building the project withcmake --build build, and optionally running tests or installing the library.Install glog using vcpkg
masterYou can install glog using the vcpkg dependency manager. This requires cloning the vcpkg repository, bootstrapping it, integrating it with your environment, and then installing the glog port.
git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install glogChoose a stack-unwinder for glog
masterDepending on your system constraints and usage of
InstallFailureSignalHandler(), you can choose from three stack-unwinder options:libunwind(Recommended): The preferred choice for 64-bit systems to avoid deadlocks when usingInstallFailureSignalHandler().- glibc Built-in Stack-unwinder: The default choice if
libunwindis not detected. Use this only if you do not useInstallFailureSignalHandler()or if you are willing to risk rare deadlocks during signal handling. - Frame Pointer based Stack-unwinder: An alternative that requires your application,
glog, and system libraries (likelibc) to all be compiled with a frame pointer. Note that this is not the default for x86-64.
Install glog using Conan
masterYou can install glog using the Conan package manager. First, ensure Conan is installed via pip, then use the
conan installcommand specifying theconancenterremote and the desired glog version.pip install conan conan install -r conancenter glog/<glog-version>@Submit a patch to glog
masterFollow these steps to contribute code to the project:
- Open an issue: Describe the bug or feature you intend to address. Mention in the issue that you plan to work on it so it can be assigned to you.
- Fork and Branch: Fork the repository and create a new branch for your changes. Use separate branches for different groups of changes to ensure pull requests are focused.
- Commit: Use well-formed commit messages for each change to maintain project consistency.
- Pull Request: Push your commits to your fork and submit a pull request.
Integrate glog into a CMake project using find_package
masterIf glog has been built using CMake or installed via a package manager, you can integrate it into your project using
find_package. This method automatically handles necessary compile definitions and options for your target. Link against theglog::glogtarget.cmake_minimum_required (VERSION 3.16) project (myproj VERSION 1.0) find_package (glog 0.8.0 REQUIRED) add_executable (myapp main.cpp) target_link_libraries (myapp glog::glog)Integrate glog into a CMake project using add_subdirectory
masterTo include glog directly from a subdirectory of your project, use the
add_subdirectorycommand instead offind_package. In this configuration, theglog::glogtarget acts as anALIASto the maingloglibrary target.cmake_minimum_required (VERSION 3.16) project (myproj VERSION 1.0) # Replace find_package with add_subdirectory add_subdirectory(path/to/glog) add_executable (myapp main.cpp) target_link_libraries (myapp glog::glog)Install the default failure signal handler
masterTo dump useful diagnostic information (like stack traces) when your program crashes on signals such asSIGSEGV, install the default signal handler usinggoogle::InstallFailureSignalHandler(). This is particularly useful for debugging segmentation faults.Sign the Contributor License Agreement (CLA)
masterAll contributions to Google projects require a signed Contributor License Agreement (CLA). This grants Google permission to use and redistribute your contributions.
- Individuals: If you are writing original code and own the intellectual property, sign the individual CLA.
- Corporations: If you are contributing on behalf of a company, sign the corporate CLA.
Note: If you have already submitted a CLA for another Google project, you likely do not need to submit it again.
Add glog to a Bazel project
masterTo use glog in a Bazel-based project, add the
glogdependency and anarchive_overrideto yourMODULE.bazelfile. Once configured, you can depend on@glog//:glogin yourcc_binaryorcc_libraryrules and include the header using#include <glog/logging.h>.bazel_dep(name = "glog") archive_override( module_name = "glog", urls = "https://github.com/google/glog/archive/cc0de6c200375b33d907ee7632eee2f173b33a09.tar.gz", strip_prefix = "glog-cc0de6c200375b33d907ee7632eee2f173b33a09", integrity = "sha256-rUrv4EBkdc+4Wbhfxp+KoRstlj2Iw842/OpLfDq0ivg=", )cc_binary( name = "main", srcs = ["main.cc"], deps = ["@glog//:glog"], )