| 1 |
/* |
| 2 |
Copyright (c) 2012 Boris Moiseev (cyberbobs at gmail dot com) |
| 3 |
|
| 4 |
This program is free software: you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU Lesser General Public License version 2.1 |
| 6 |
as published by the Free Software Foundation and appearing in the file |
| 7 |
LICENSE.LGPL included in the packaging of this file. |
| 8 |
|
| 9 |
This program is distributed in the hope that it will be useful, |
| 10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
GNU Lesser General Public License for more details. |
| 13 |
*/ |
| 14 |
#ifndef LOGGER_H |
| 15 |
#define LOGGER_H |
| 16 |
|
| 17 |
#include <QString> |
| 18 |
#include <QDebug> |
| 19 |
#include <QDateTime> |
| 20 |
|
| 21 |
#include "dloggerdefs.h" |
| 22 |
|
| 23 |
DLOG_CORE_BEGIN_NAMESPACE |
| 24 |
|
| 25 |
class AbstractAppender; |
| 26 |
class LoggerPrivate; |
| 27 |
class LIBDLOG_SHARED_EXPORT Logger |
| 28 |
{ |
| 29 |
Q_DISABLE_COPY(Logger) |
| 30 |
public: |
| 31 |
//!@~english the log levels |
| 32 |
enum LogLevel |
| 33 |
{ |
| 34 |
Trace, //!<@~english Trace level. Can be used for mostly unneeded records used for internal code tracing. |
| 35 |
Debug, //!<@~english Debug level.for the debugging of the software. |
| 36 |
Info, //!<@~english Info level. Can be used for informational records, which may be interesting for not only developers. |
| 37 |
Warning, //!<@~english Warning. May be used to log some non-fatal warnings detected by your application. |
| 38 |
Error, //!<@~english May be used for a big problems making your application work wrong but not crashing. |
| 39 |
Fatal //!<@~english Fatal. Used for unrecoverable errors, crashes the application (abort) right after the log record is written. |
| 40 |
}; |
| 41 |
|
| 42 |
Logger(); |
| 43 |
Logger(const QString &defaultCategory); |
| 44 |
~Logger(); |
| 45 |
|
| 46 |
static Logger *globalInstance(); |
| 47 |
|
| 48 |
static QString levelToString(LogLevel level); |
| 49 |
static LogLevel levelFromString(const QString &str); |
| 50 |
|
| 51 |
void registerAppender(AbstractAppender *appender); |
| 52 |
void registerCategoryAppender(const QString &category, AbstractAppender *appender); |
| 53 |
|
| 54 |
QT_DEPRECATED_X("no longer take effect") |
| 55 |
void logToGlobalInstance(const QString &category, bool logToGlobal = false); |
| 56 |
|
| 57 |
void setDefaultCategory(const QString &category); |
| 58 |
QString defaultCategory() const; |
| 59 |
|
| 60 |
void write(const QDateTime &time, LogLevel level, const char *file, int line, |
| 61 |
const char *func, const char *category, const QString &msg); |
| 62 |
void write(LogLevel level, const char *file, int line, |
| 63 |
const char *func, const char *category, const QString &msg); |
| 64 |
QDebug write(LogLevel level, const char *file, int line, |
| 65 |
const char *func, const char *category); |
| 66 |
void writeAssert(const char *file, int line, |
| 67 |
const char *func, const char *condition); |
| 68 |
|
| 69 |
private: |
| 70 |
void write(const QDateTime &time, LogLevel level, const char *file, int line, |
| 71 |
const char *func, const char *category, |
| 72 |
const QString &msg, bool fromLocalInstance); |
| 73 |
Q_DECLARE_PRIVATE(Logger) |
| 74 |
LoggerPrivate *d_ptr; |
| 75 |
}; |
| 76 |
|
| 77 |
DLOG_CORE_END_NAMESPACE |
| 78 |
#endif // LOGGER_H |