How To Use Google Logging Library (glog)

Google glog 是一个应用级的日志库,提供基于C++风格流的API和宏。它可以按严重级别记录消息,支持命令行标志设置,条件性日志,调试模式,CHECK宏,详细日志等。glog的默认日志文件路径为"/tmp/<程序名>.<hostname>.<user name>.log.<severity level>.<date>.<time>.<pid>"。用户可以通过设置标志来改变输出行为,如控制到标准错误的输出。glog还提供了如`LOG(INFO)`, `DCHECK`, `VLOG`等宏,用于不同场景的日志记录。" 119860009,9582878,Java编程:101至2100年间所有闰年展示,"['Java', '编程实践', '算法', '日期处理']
摘要由CSDN通过智能技术生成
(as of Fri Jan 25 2013) 

Introduction

Google glog is a library that implements application-level logging. This library provides logging APIs based on C++-style streams and various helper macros. You can log a message by simply streaming things to LOG(<a particular severity level>), e.g.

   #include <glog/logging.h>

   int main(int argc, char* argv[]) {
     // Initialize Google's logging library.
     google::InitGoogleLogging(argv[0]);

     // ...
     LOG(INFO) << "Found " << num_cookies << " cookies";
   }

Google glog defines a series of macros that simplify many common logging tasks. 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. This document describes the functionality supported by glog. Please note that this document doesn't describe all features in this library, but the most useful ones. If you want to find less common features, please check header files under src/glog directory.

Severity Level

You can specify one of the following severity levels (in increasing order of severity): INFOWARNINGERROR, and FATAL. Logging a FATAL message terminates the program (after the message is logged). Note that messages of a given severity are logged not only in the logfile for that severity, but also in all logfiles of lower severity. E.g., a message of severity FATAL will be logged to the logfiles of severity FATALERRORWARNING, andINFO.

The DFATAL severity logs a FATAL error in debug mode (i.e., there is no NDEBUG macro defined), but avoids halting the program in production by automatically reducing the severity to ERROR.

Unless otherwise specified, glog writes to the filename "/tmp/<program name>.<hostname>.<user name>.log.<severity level>.<date>.<time>.<pid>" (e.g., "/tmp/hello_world.example.com.hamaji.log.INFO.20080709-222411.10474"). By default, glog copies the log messages of severity level ERROR orFATAL to standard error (stderr) in addition to log files.

Setting Flags

Several flags influence glog's output behavior. If the Google gflags library is installed on your machine, the configure script (see the INSTALL file in the package for detail of this script) will automatically detect and use it, allowing you to pass flags on the command line. For example, if you want to turn the flag --logtostderr on, you can start your application with the following command line:

   ./your_application --logtostderr=1
If the Google gflags library isn't installed, you set flags via environment variables, prefixing the flag name with "GLOG_", e.g.
   GLOG_logtostderr=1 ./your_application

The following flags are most commonly used:

logtostderr ( bool, default= false)
Log messages to stderr instead of logfiles.
Note: you can set binary flags to  true by specifying  1true, or  yes (case insensitive). Also, you can set binary flags to  false by specifying 0false, or  no (again, case insensitive).
stderrthreshold ( int, default=2, which is  ERROR)
Copy log messages at or above this level to stderr in addition to logfiles. The numbers of severity levels  INFOWARNINGERROR, and  FATAL are 0, 1, 2, and 3,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值