logger.cpp

来自「QT4的utils库源码包.解压后运行./configure配置,然后make.」· C++ 代码 · 共 40 行

CPP
40
字号
#include <QDebug>#include <QString>#include <QDateTime>#include "logger.h"#include <QDebug>QMap<QString, Logger*> Logger::sm_LogMap;void Logger::myDebugHandler( QtMsgType type, const char *msg ) {    Q_UNUSED(type);    Logger* l = getLogger("debug");    l->data(msg);}void Logger::info(QString str) {    emit data(str);    if ((str.length()>0) && (objectName() == "debug")) {		qDebug() << "\nINFO: " <<  QDateTime::currentDateTime().toString()              << endl << str;    }}Logger* Logger::getLogger(QString logname) {    if (!sm_LogMap.contains(logname)) {        Logger* log = new Logger(logname);        sm_LogMap[logname]=log;        if (logname == "debug") {            qInstallMsgHandler(Logger::myDebugHandler );        }    }    return sm_LogMap[logname];}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?