Code Monkey home page Code Monkey logo

qlogger's Introduction

Qt 日志模块的使用

使用步骤

  • 拷贝**[cutelogger]**目录到自己的项目工程

  • 在自己的工程文件中添加如下代码

      include(../cutelogger/cutelogger.pri)
    
  • 在main.cpp中引入头文件

      #include "logmanager.h"
      #include "Logger.h"
    
  • 在main函数内部启动logmanager实例,debug模式log输出到终端和文件,release模式下log仅仅输出到文件

      LogManager::instance()->debug_log_console_on();
    

代码示例

#include <QCoreApplication>
#include "logmanager.h"
#include "Logger.h"
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    LogManager::instance()->debug_log_console_on();
    qDebug() << "Use qDebug";
    qWarning() << "Use qWarning";
    qCritical() << "Use qCritical";
    LOG_INFO() << LogManager::instance()->getlogFilePath();
    LOG_TRACE() << "Use LOG_DEBUG";
    LOG_DEBUG() << "Use LOG_DEBUG";
    LOG_INFO() << "Use LOG_INFO";
    LOG_WARNING() << "Use Warning";
    LOG_ERROR() << "Use LOG_ERROR";
    LOG_FATAL() << "Use LOG_FATAL";

    return a.exec();
}

###高级用法

  • 完全兼容Qt原生的 日志打印用法

     qDebug()  <==> LOG_DEBUG()
     qWarning()  <==> LOG_WARNING()
     qCritical()  <==> LOG_ERROR();
    
  • 参照loggermanager的使用基本用法,加以拓展

  • 阅读cutelogger的源码获取更多的使用方法

参考第三方库:https://github.com/dept2/CuteLogger

Logger: simple, convinient and thread safe logger for Qt-based C++ apps

qlogger's People

Contributors

dragondjf avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.