glog摘记

projcet url : https://code.google.com/p/google-glog/

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI记忆

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值