当前位置:网站首页>Logging system in chromium
Logging system in chromium
2022-06-13 01:45:00 【weijun23】
chromium The logging in actually uses libglog
ubuntu Lower installation libglog: sudo apt install libgoogle-glog-dev
libglog Examples of use :
#include <iostream>
#include "glog/logging.h" // glog The header file
using namespace std;
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]); // initialization
// FLAGS_log_dir="."; // Set up log Catalog , Print to by default "/tmp/ The program name .INFO"
LOG(INFO) << "hello glog"; // Print log:“hello glog. Be similar to C++ stream.
}
Compile command : g++ main.cpp -lglog chromium in logging Log system initialization :
void InitLogging() {
base::FilePath log_filename;
PathService::Get(base::DIR_EXE, &log_filename);
log_filename = log_filename.AppendASCII("content_shell.log"); // Get the log file under the current executable directory content_shell.log
logging::LoggingSettings settings;
settings.logging_dest = logging::LOG_TO_ALL; // Logs are saved to file and system modal logs
settings.log_file = log_filename.value().c_str(); // Specify log files content_shell.log
settings.delete_old = logging::DELETE_OLD_LOG_FILE; // Delete old logs
logging::InitLogging(settings);
logging::SetLogItems(true, true, true, true); // Log save item : process ID、 Threads ID、 Time stamp 、tick Count
}
The log level :
typedef int LogSeverity;
const LogSeverity LOG_VERBOSE = -1; // This is level 1 verbosity
// Note: the log severities are used to index into the array of names, see log_severity_names.
const LogSeverity LOG_INFO = 0;
const LogSeverity LOG_WARNING = 1;
const LogSeverity LOG_ERROR = 2;
const LogSeverity LOG_FATAL = 3;
const LogSeverity LOG_NUM_SEVERITIES = 4;
Log usage :
1)LOG macro :
LOG It's like c++ The output of the standard library is overloaded <<, It has several common grades ,
image ”VERBOSE“,“INFO”, “WARNING”, “ERROR”, “FATAL”,”NUM_SEVERITIES“ etc.
such as ”FATAL”LOG Will trigger a breakpoint , And print out the stack backtracking information .
LOG(INFO) << "info Grade = " << logging::LOG_INFO;
LOG(WARNING) << "WARNING Grade = " << logging::LOG_WARNING;
LOG(ERROR) << "ERROR Grade = " << logging::LOG_ERROR;
LOG(FATAL) << "FATAL Grade = " << logging::LOG_FATAL;2)LOG_IF macro :
Use LOG_IF Macros can output only when the expression condition is true log:
int if_int = 5;
LOG_IF(INFO, if_int < 10 ) << "if_int < 10";3)CHECK macro :
CHECK The macro executes when the expression is false LOG(FATAL) The effect of ,
If there is no debugger attached , It will also generate a crash dump.
//CHECK macro , If the condition fails, an LOG(FATAL)
CHECK(0);4)DLOG macro :
DLOG Follow LOG similar , The difference is DLOG Only in DEBUG Mode ,
In Africa DEBUG In mode , This part of the code will not be compiled into the program .
DLOG(INFO) << "DLOG onlg debug";
DLOG_IF(INFO, if_int < 10) << "DLOG_IF onlg debug";
LOG_ASSERT(0);
DLOG_ASSERT(0);3)VLOG macro :
This is an output that can be dynamically adjusted through command line parameters log Macro of policy , These are all INFO Grade .
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";4)PLOG macro :
PLOG In addition to outputting the output information we specify , The last error message of the system is attached ,
windows On is GetLastError(),POSIX On is errno Value .
LOG Macro decomposition :
#define LOG(severity) LAZY_STREAM(LOG_STREAM(severity), LOG_IS_ON(severity))
#define LOG_IS_ON(severity) ((::logging::LOG_ ## severity) >= ::logging::GetMinLogLevel())
#define LOG_STREAM(severity) (COMPACT_GOOGLE_LOG_ ## severity.stream())
#define LAZY_STREAM(stream, condition) !(condition) ? (void) 0 : ::logging::LogMessageVoidify() & (stream)(logging::LOG_INFO < logging::GetMinLogLevel()) ? (void) 0 : logging::LogMessageVoidify() & (logging::LogMessage(__FILE__, __LINE__, LOG_INFO).stream())
LOG(INFO) << "info Grade " Decompose into
(logging::LOG_INFO < logging::GetMinLogLevel()) ? (void) 0 : logging::LogMessageVoidify() & (logging::LogMessage(__FILE__, __LINE__, LOG_INFO).stream()) << "info Grade "
边栏推荐
- 关于tkinter.Canvas 不显示图片的问题
- Unity JsonUtility 无法序列化List
- How many smart bids does Google have?
- Devaxpress Chinese description -- tdxgallerycontrol object (gallery component)
- JSON and protobuf Any interchange
- Mysql database listening -canal
- Wsl2 + vcxsrv + opengl3.3 configuration
- Note: common gadgets in project architecture
- Super complete regular expressions
- About the proposed signature file migration to industry standard format pkcs12
猜你喜欢

Should the audience choose observation mode or positioning mode?

五、库存查询功能的完善

What is Google plus large text ads? How to use it?

MySQL connection query

【MathType】利用MathType输出LaTex样式的公式

Network communication tcp/ip

Explanation and application of prefix sum (one-dimensional, two-dimensional)

服务器安装jupyterlab以及远程登录配置

STM32 3*3矩阵按键(寄存器版本)

The second round of mesa
随机推荐
dfs与bfs解决宝岛探险
Getting started with phaser 3
Record the VMware installation process of VMware Tools and some problems encountered
水管工游戏
4、 Improvement of warehousing management function
[从零开始学习FPGA编程-22]:进阶篇 - 架构 - FPGA内部硬件电路的设计与建模
redis
[official document summary] writing standards for academic dissertations of National University of science and technology
TensorFlow 2. X multi graphics card distributed training
TensorFlow 2.x 多显卡分布式训练
MySQL connection query
TensorFlow2的Conv1D, Conv2D,Conv3D机器对应的MaxPooling详解
The method of drawing rounded panel with Delphi
30: Kakfa simulates JSON data generation and transmission
pytorch : srcIndex < srcSelectDimSize
URI, URL and urn difference, relation and syntax diagram
3、 Upload fabric photos to SQL server and provide name to display fabric photos
如何通过受众群体定位解决实际问题?
Qt实现思维导图功能(二)
Leetcode question 20