3
3
** LICENSE file, found in the top level directory of this distribution. If you
4
4
** did not receive the LICENSE file with this file, you may obtain it from the
5
5
** Vidalia source package distributed by the Vidalia Project at
6
** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7
** including this file, may be copied, modified, propagated, or distributed
6
** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7
** including this file, may be copied, modified, propagated, or distributed
8
8
** except according to the terms described in the LICENSE file.
26
26
/** The Log class is similar to the QDebug class provided with Qt, but with
27
27
* finer-grained logging levels, slightly different output (for example, not
28
* everything is wrapped in double quotes), supports using .arg(), and can
28
* everything is wrapped in double quotes), supports using .arg(), and can
29
29
* still be used even if Qt was compiled with QT_NO_DEBUG_STREAM. */
52
52
bool open(FILE *file);
53
53
/** Opens a file on disk to which log messages will be written. */
54
54
bool open(QString file);
55
/** Closes the log file. */
55
/** Closes the log file. */
57
57
/** Returns true if the log file is open and ready for writing. */
58
58
bool isOpen() { return _logFile.isOpen() && _logFile.isWritable(); }
59
59
/** Returns a string description of the last file error encountered. */
60
60
QString errorString() { return _logFile.errorString(); }
62
62
/** Sets the current log level to <b>level</b>. */
63
63
void setLogLevel(LogLevel level);
64
64
/** Returns a list of strings representing valid log levels. */
67
67
static inline QString logLevelToString(LogLevel level);
68
68
/** Returns a LogLevel for the level given by <b>str</b>. */
69
69
static LogLevel stringToLogLevel(QString str);
71
71
/** Creates a log message with severity <b>level</b> and initial message
72
72
* contents <b>message</b>. The log message can be appended to until the
73
73
* returned LogMessage's destructor is called, at which point the complete
77
77
* appended to until the returned LogMessage's destructor is called, at
78
78
* which point the complete message is written to the log file. */
79
79
inline LogMessage log(LogLevel level);
82
82
LogLevel _logLevel; /**< Minimum log severity level. */
83
83
QFile _logFile; /**< Log output destination. */
86
/** This internal class represents a single message that is to be written to
86
/** This internal class represents a single message that is to be written to
87
87
* the log destination. The message is buffered until it is written to the
88
88
* log in this class's destructor. */
89
89
class Log::LogMessage
93
Stream(Log::LogLevel t, QIODevice *o)
93
Stream(Log::LogLevel t, QIODevice *o)
94
94
: type(t), out(o), ref(1) {}
95
95
Log::LogLevel type;
101
101
inline LogMessage(Log::LogLevel t, QIODevice *o)
102
102
: stream(new Stream(t,o)) {}
103
inline LogMessage(const LogMessage &o)
103
inline LogMessage(const LogMessage &o)
104
104
: stream(o.stream) { ++stream->ref; }
105
105
inline QString toString() const;
108
108
/* Support both the << and .arg() methods */
109
inline LogMessage &operator<<(const QString &t)
109
inline LogMessage &operator<<(const QString &t)
110
110
{ stream->buf += t; return *this; }
111
111
inline LogMessage arg(const QString &a)
112
112
{ stream->buf = stream->buf.arg(a); return *this; }