chromium源码学习-调试日志 LOG

在学习 chromium 源码时,我们经常需要增加调试日志,常见的用法一般是

// TurboNet.mm
  133
  134  LOG(INFO) << "TurboNet Engine started.";  
  135  LOG(INFO);
  136  LOG(WARNING);
  137  VLOG(1);
  138  VLOG(2);
  139  PLOG(INFO); // 会输出系统错误码信息
  140  PLOG(WARNING);
  141  DLOG(INFO);
  142  DLOG(WARNING);

日志输出效果如下:
在这里插入图片描述

其中 INFO 代表当前这条日志的级别(详见下面 2 小节),使用的时候就是输入 INFO 就行。接下来我们在探索下这个宏背后的内容。 LOG 在 release 和 debug 模式均生效,DLOG 仅在 debug 模式生效。VLOG 支持模式匹配,比如指定特定文件的日志级别、特定目录的日志级别、特定前缀的文件的日志级别等,详见官方注释:

// There are "verbose level" logging macros.  They look like
//
//   VLOG(1) << "I'm printed when you run the program with --v=1 or more";
//   VLOG(2) << "I'm printed when you run the program with --v=2 or more";
//
// These always log at the INFO log level (when they log at all).
// The verbose logging can also be turned on module-by-module.  For instance,
//    --vmodule=profile=2,icon_loader=1,browser_*=3,*/chromeos/*=4 --v=0
// will cause:
//   a. VLOG(2) and lower messages to be printed from profile.{h,cc}
//   b. VLOG(1) and lower messages to be printed from icon_loader.{h,cc}
//   c. VLOG(3) and lower messages to be printed from files prefixed with
//      "browser"
//   d. VLOG(4) and lower messages to be printed from files under a
//     "chromeos" directory.
//   e. VLOG(0) and lower messages to be printed from elsewhere

一、基本用法

LOG 本身是一个宏:

#define LOG(severity) LAZY_STREAM
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值