QtLog

#include "mainwindow.h"
#include <QApplication>
#include <QByteArray>
#include <QDebug> #define LOG_FILE_PATH "D:\\QtLog\\log.txt"
static FILE* g_log_fp=;
static void closLogFile(){
fclose(g_log_fp);//main函数退出关闭日志文档 }
static void myMessageOutPut(QtMsgType type,const QMessageLogContext &contex,const QString &msg){
QByteArray localMsg=msg.toLocal8Bit();
switch (type) {
case QtDebugMsg:
fprintf(g_log_fp,"Debug :%s(%s:%u,%s)\n",localMsg.constData(),contex.file,contex.line,contex.function); break;
case QtWarningMsg:
fprintf(g_log_fp,"Waring :%s(%s:%u,%s)\n",localMsg.constData(),contex.file,contex.line,contex.function); break;
case QtCriticalMsg:
fprintf(g_log_fp,"Critical :%s(%s:%u,%s)\n",localMsg.constData(),contex.file,contex.line,contex.function); break;
case QtFatalMsg:
fprintf(g_log_fp,"Fatal :%s(%s:%u,%s)\n",localMsg.constData(),contex.file,contex.line,contex.function);
abort();// 致命错误,程序停止退出
break; default:
break;
} }
int main(int argc, char *argv[])
{ g_log_fp=fopen(LOG_FILE_PATH,"wt");
atexit(closLogFile);//程序结束执行关闭文件
qInstallMessageHandler(myMessageOutPut);
QApplication a(argc, argv);
// MainWindow w;
// w.show(); qDebug()<<"I am debug;";
qWarning()<<"I am waring";
qCritical()<<"I am critical";
qFatal("I am fatal"); return a.exec();
}

http://blog.csdn.net/leejore11/article/details/46837185

QtLog的更多相关文章

随机推荐

  1. errant-transactions

    https://www.percona.com/blog/2015/12/02/gtid-failover-with-mysqlslavetrx-fix-errant-transactions/ 使用 ...

  2. json_encode和json_decode和isset和array_key_exists

    1.json_decode() json_decode — 对 JSON 格式的字符串进行编码         说明 mixed json_decode ( string $json [, bool ...

  3. 2-3 JAVA内存模型

  4. 【bzoj1444】[Jsoi2009]有趣的游戏

    1444: [Jsoi2009]有趣的游戏 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 1007  Solved: 334[Submit][Statu ...

  5. laravel Redis缓存

    首先在app/config/cache.php配置文件下改变一下缓存的驱动方式改为redis composer require predis/predis 先安装conposer的扩展安装包 然后在c ...

  6. SpringBoot20 集成SpringSecurity02 -> 利用SpringSecurity进行前后端分离的登录验证

    1 SpirngBoot环境搭建 创建一个SpringBoot项目即可,详情参见三少的相关博文 参考博文 -> 点击前往 SpirngBoot项目脚手架 -> 点击前往 2 引入Spirn ...

  7. 476. Number Complement 二进制中的相反对应数

    [抄题]: Given a positive integer, output its complement number. The complement strategy is to flip the ...

  8. 面试题:Java集合面试题(40道) 背1

    Java集合框架为Java编程语言的基础,也是Java面试中很重要的一个知识点.这里,我列出了一些关于Java集合的重要问题和答案. 1.Java集合框架是什么?说出一些集合框架的优点? 每种编程语言 ...

  9. laravel实现多对多的分析

    在实际开发中多对多的开发还是比较常见的 1.1首先由migrate来创建表(文章表) 1.2同理创建标签表 1.3这是 我会的到如下结果: 2.1在数据迁移表contents中添加几个字段 publi ...

  10. PHP文件的引用

    require "文件名" 或 include("文件名") 区别:若所包含文件出现错误,include()产生一个警告,require会导致程序终止