dtkwidget/dutil/dlog
Iceyer 7c829db907 Fix utf8 char case build failed
Change-Id: I0c69fbc44ad836fb53aa84426f3f83e1e2dbdc00
2016-08-12 02:37:09 +00:00
..
AbstractAppender.cpp change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
AbstractAppender.h change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
AbstractStringAppender.cpp change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
AbstractStringAppender.h change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
ConsoleAppender.cpp change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
ConsoleAppender.h change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
CuteLogger_global.h format document 2016-02-18 15:43:05 +08:00
DLog change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
FileAppender.cpp Add log size limit 2016-07-28 13:53:41 +08:00
FileAppender.h Add log size limit 2016-07-28 13:53:41 +08:00
LICENSE change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
LogManager.cpp Fix utf8 char case build failed 2016-08-12 02:37:09 +00:00
LogManager.h Fix window build issue 2016-06-26 18:38:25 +08:00
Logger.cpp format document 2016-02-18 15:43:05 +08:00
Logger.h change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
OutputDebugAppender.cpp change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
OutputDebugAppender.h change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
README.md format document 2016-02-18 15:43:05 +08:00
RollingFileAppender.cpp Add log size limit 2016-07-28 13:53:41 +08:00
RollingFileAppender.h Add log size limit 2016-07-28 13:53:41 +08:00
cutelogger.pri change dlog -> dutil/log 2016-02-16 17:39:38 +08:00
dlog.pri change dlog -> dutil/log 2016-02-16 17:39:38 +08:00

README.md

Dtk/Util/DLog

DLog is the log module of deepin tool kit for Qt/C++

Logger is a simple way to write the history of your application lifecycle to any target logging device (which is called Appender and may write to any target you will implement with it: console, text file, XML or something - you choose) and to map logging message to a class, function, source file and line of code which it is called from.

Some simple appenders (which may be considered an examples) are provided with the Logger itself: see ConsoleAppender and FileAppender documentation.

It supports using it in a multithreaded applications, so all of its functions are thread safe.

Logger internally uses the lazy-initialized singleton object and needs no definite initialization, but you may consider registering a log appender before calling any log recording functions or macros.

The library design of Logger allows you to simply mass-replace all occurrences of qDebug and similar calls with similar Logger macros (e.g. dDebug())

Note Logger uses a singleton global instance which lives through all the application life cycle and self-destroys destruction of the QCoreApplication (or QApplication) instance. It needs a QCoreApplication instance to be created before any of the Logger's functions are called.

Usage

Just add pkgconfig in .pro file

unix {
    CONFIG+=link_pkgconfig
    PKGCONFIG+=dtkutil
}

Example


#include <QCoreApplication>
#include <DLog>
using namespace Dtk::Log;
int main(int argc, char* argv[])
{
    QCoreApplication app(argc, argv);
    // 1 you can use standrd deepin application log format
    // 1.1 log to console
    DLogManager::registerConsoleAppender();
    // 1.2 log to standrd deepin user cache path: ~/.cache/{organ}/{appname}/
    // app.setOrganizationName("dtk-test"); // must set
    // app.setApplicationName("dlog-example"); // must set
    // dInfo()<< "LogFile:" << DLogManager::getlogFilePath();
    // DLogManager::registerFileAppender();
    // 1.3 log to stdout and file
    // DLogManager::registerFileAppender();
    // DLogManager::registerConsoleAppender();
    // 2 Register your own logger format;
    //  ConsoleAppender* consoleAppender = new ConsoleAppender;
    //  consoleAppender->setFormat("[%{type:-7}] <%{Function}> %{message}\n");
    //  logger->registerAppender(consoleAppender);
    dInfo("Starting the application");
    int result = 1;
    dWarning() << "Something went wrong." << "Result code is" << result;
    return result;
}

\sa Dtk::Util::DLogManager