博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
glog摘记
阅读量:5318 次
发布时间:2019-06-14

本文共 3321 字,大约阅读时间需要 11 分钟。

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.

转载于:https://www.cnblogs.com/zfyouxi/p/3863124.html

你可能感兴趣的文章
Spring整合MyBatis
查看>>
Java/Java Web中乱码解决汇总
查看>>
表格操作
查看>>
TortoiseGit使用指南
查看>>
大数据学习——securecrt同时向多个tab窗口发送相同的命令
查看>>
Swift学习笔记(4):字符串
查看>>
Windows下部署多个Tomcat
查看>>
[BZOJ1672][Usaco2005 Dec]Cleaning Shifts 清理牛棚
查看>>
VBoxManage命令速记
查看>>
(转载)我们工作到底为了什么 (HP大中华区总裁孙振耀退休感言)
查看>>
phpstudy + dvws
查看>>
2016/3/10 数据库简单操作( 创建数据库 创建表 数值类型 主键 外键 自动递增 )...
查看>>
Redis客户端连接池问题
查看>>
linux C print
查看>>
Mac-Navicat Premium For Mac 12 破解 - [数据库可视化工具,亲测完美破解]
查看>>
利用Chrome查看网页渲染机制
查看>>
第5章 初始化与清理
查看>>
委托与事件
查看>>
MVC实战之排球计分(七)——软件的具体实现与测试
查看>>
maven的pom.xml文件标签含义
查看>>