zoukankan      html  css  js  c++  java
  • 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 forthread-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.

  • 相关阅读:
    legend2---开发日志12(vue如何进一步学习)
    为什么现在的年轻人生育的欲望越来越低?(转自知乎)
    legend2---开发日志13(layer_mobile的content传入dom 出现【object object】如何解决)
    legend2---项目总结(legend2的意义)
    legend2---开发日志11(如何提高终极开发效率)
    公司项目架构的演变过程(转)
    创业公司如何实施敏捷开发(敏捷开发简单流程)(转)
    创业公司一年工作总结(转)(公司失败原因)
    LayaAir引擎开发HTML5最简单教程(面向JS开发者)
    [ACM] HDU 2295 Radar (二分法+DLX 重复覆盖)
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/3863124.html
Copyright © 2011-2022 走看看