qInstallMsgHandler实现日志输出
2012-10-09 14:38
197 查看
#include <QtDebug> #include <QFile> #include <QTextStream> #define _TIME_ qPrintable (QTime::currentTime ().toString ("hh:mm:ss:zzz")) void Log(QtMsgType type, const char* msg) { QString qstrText; switch (type) { case QtDebugMsg: qstrText = QString("%1: %2").arg(_TIME_, msg); break; case QtWarningMsg: qstrText = QString("%1: %2").arg(_TIME_, msg); break; case QtCriticalMsg: qstrText = QString("%1: %2").arg(_TIME_, msg); break; case QtFatalMsg: qstrText = QString("%1: %2").arg(_TIME_, msg); exit(0); } QFile out("log.txt"); out.open(QIODevice::WriteOnly | QIODevice::Append); QTextStream ts(&out); ts<<qstrText<<endl; } int main(int argc, char *argv[]) { QApplication a(argc, argv); qInstallMsgHandler(Log); qDebug("this is a debug message"); qWarning("this is a warning message"); qCritical("this is a critical message"); qFatal("this is a fatal message"); return a.exec(); }
相关文章推荐
- 命令行脚本实现守护程序并日志输出
- 实现Qt日志功能并输出到文件(使用qInstallMsgHandler安装customMessageHandler)good
- 不使用spring的aop功能实现日志输出
- Log4J输出日志到WEB工程目录的实现方法
- LOG4J的配置..实现了输出到控制台、文件、回滚文件、发送日志邮件
- 【实现多窗口切换】和【日志输出-TextBox】
- 利用spring AOP实现每个请求的日志输出
- Java+Selenium3框架设计准备篇11-用Log4j实现日志输出
- Java用webSocket实现tomcat的日志实时输出到web页面
- Java 如何获取控制台日志输出的信息? WriterAppender 可以实现? 配置文件如何配置
- Spring+logback实现日志输出
- 【代码技巧】一段代码实现分级日志输出
- log4j2日志管理xml配置方式实现日志分类输出
- TestNG实现日志输出
- 简单的C++加载jvm实现--简单的日志输出
- 自定义Appender ,实现输出log4j日志到GUI
- Python使用logging结合decorator模式实现优化日志输出的方法
- 使用logback.xml配置来实现日志文件输出
- Python使用logging结合decorator模式实现优化日志输出的方法
- 5.8 把输出日志的实例改成用Spring的AOP来实现