GLog
Installation in Ubuntu
Usage in CMake
Google GLog team does provide GlogConfig.cmake
file, but it is not adopted by the default apt package available in Ubuntu. You can
compile glog from source and enable CMake support, so that config file will be installed; or
use default Ubuntu package by
sudo apt install libgoogle-glog-dev
, and then find aFindGlog.cmake
file and add the path to this file toCMAKE_MODULE_PATH
variable, such that CMake will use this file to load glog.
After the package is found, use the following variables for header files and libraries.
References
Tutorial / User Guide
Google glog defines a series of macros that simplify many common logging tasks. It provides logging APIs based on C++-style streams and various helper macros. 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, and more.
You can log a message by simply streaming things to LOG(<severity level>)
, e.g.,
Unless otherwise specified, glog writes to the filename
/tmp/<program_name>.<hostname>.<username>.log.<severity_level>.<date>.<time>.<pid>
, or/tmp/test.hteng-nuc.hteng.log.INFO.20210806-211849
for example.
Note that if InitGoogleLogging
is not called for initialization, glog will turn into logtostderr
mode and this log file will not be generated under /tmp
. (corresponding source code)
Severity Level
You can specify one of the following severity levels (in increasing order of severity): INFO
, WARNING
, ERROR
, and FATAL
.
Logging a
FATAL
message terminates the program (after the message is logged).Messages of a given severity are logged not only in the logfile for that severity, but also in all logfiles of lower severity. For example, a message of severity
FATAL
will be logged to the logfiles of severityFATAL
,ERROR
,WARNING
, andINFO
.The
DFATAL
severity logs aFATAL
error in debug mode (i.e., there is noNDEBUG
macro defined), but avoids halting the program in production by automatically reducing the severity toERROR
.By default, glog copies the log messages of severity level
ERROR
orFATAL
to standard error (stderr) in addition to log files.
See the official User Guide for more tutorials.
Last updated