Qt 日志规范及原理分析

Qt中debug和release状态下输出内容有所不同,debug模式下包含了数百条警告及错误日志,除非在编译期间设置了QT_NO_WARNING_OUTPUT和/或QT_NO_DEBUG_OUTPUT,否则在发布模式下构建的Qt也包含此类警告。

一 格式化日志

qt 格式化输出内容有两种方法: qInstallMessageHandler 和 qSetMessagePattern

qSetMessagePattern 使用方法

Placeholder

Description

%{appname}

QCoreApplication::applicationName()

%{category}

Logging category

%{file}

Path to source file

%{function}

Function

%{line}

Line in source file

%{message}

The actual message

%{pid}

QCoreApplication::applicationPid()

%{threadid}

The system-wide ID of current thread (if it can be obtained)

%{qthreadptr}

A pointer to the current QThread (result of QThread::currentThread())

%{type}

"debug", "warning", "critical" or "fatal"

%{time process}

time of the message, in seconds since the process started (the token "process" is literal)

%{time boot}

the time of the message, in seconds since the system boot if that can be determined (the token "boot" is literal). If the time since boot could not be obtai

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值