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