projcet url :
usage: application-level logging
setting flags GLOG_logtostderr: If gflags not installed, you can useGLOG_logtostderr=1 ./your_application stderrthreshold: Copy log messages at or above this level to stderr in addition to logfiles. log_dir: If specified, logfiles are written into this directory instead of the default logging directory.
Conditional / Occasional Logging
LOG_IF(INFO, num_cookies > 10): LOG_EVERY_N(INFO, 10): log messages on the 1st, 11th, 21st, ... times it is executed. LOG_IF_EVERY_N(INFO, (size > 1024), 10): you can also limit the output to the first n occurrences.LOG_FIRST_N(INFO, 20): you can also limit the output to the first n occurrences.
Debug Mode Support
Just need to add "D" before LOG, then these LOG will be compiled away to nothing for non-debug mode compiles.
CHECK Macros
CHECK() CHECK_NE() CHECK_EQ() CHECK_NOTNULL() If you are comparing C strings (char *), a handy set of macros performs case sensitive as well as case insensitive comparisons - CHECK_STREQ, CHECK_STRNE, CHECK_STRCASEEQ, and CHECK_STRCASENE. The CASE versions are case-insensitive. You can safely pass NULL pointers for this macro. They treat NULL and any non-NULL string as not equal. Two NULLs are equal. If you are comparing C strings (char *), a handy set of macros performs case sensitive as well as case insensitive comparisons - CHECK_STREQ, CHECK_STRNE, CHECK_STRCASEEQ, and CHECK_STRCASENE. The CASE versions are case-insensitive. You can safely pass NULL pointers for this macro. They treat NULL and any non-NULL string as not equal. Two NULLs are equal.
Verbose Logging
VLOG(1) << "I'm printed when you run the program with --v=1 or higher"; VLOG(2) << "I'm printed when you run the program with --v=2 or higher"; Verbose logging can be controlled from the command line on a per-module basis: --vmodule=mapreduce=2,file=1,gfs*=3 --v=0 will: a. Print VLOG(2) and lower messages from mapreduce.{h,cc} b. Print VLOG(1) and lower messages from file.{h,cc} c. Print VLOG(3) and lower messages from files prefixed with "gfs" d. Print VLOG(0) and lower messages from elsewhere
Failure Signal Handler
The signal handler can be installed by google::InstallFailureSignalHandler(). By default, the signal handler writes the failure dump to the standard error. You can customize the destination by InstallFailureWriter().
User-defined Failure Function
FATAL severity level messages or unsatisfied CHECK condition terminate your program. You can change the behavior of the termination by InstallFailureFunction. void YourFailureFunction() { // Reports something... exit(1); } int main(int argc, char* argv[]) { google::InstallFailureFunction(&YourFailureFunction);}
By default, glog tries to dump stacktrace and makes the program exit with status 1. The stacktrace is produced only when you run the program on an architecture for which glog supports stack tracing (as of September 2008, glog supports stack tracing for x86 and x86_64).
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.in for detail.