~jackweirdy/vidalia/680192

« back to all changes in this revision

Viewing changes to src/common/Log.h

  • Committer: Package Import Robot
  • Author(s): Ulises Vitulli, intrigeri, Ulises Vitulli
  • Date: 2012-06-22 07:18:44 UTC
  • mfrom: (1.4.8) (8.2.13 sid)
  • Revision ID: package-import@ubuntu.com-20120622071844-s278v0p646pqt949
Tags: 0.2.19-1
[ intrigeri ]
* Imported Upstream version 0.2.19
* Install AppArmor profile.
* Enable hardening flags.

[ Ulises Vitulli ]
* Added runtime dependency on apparmor.
* Updated d/NEWS and d/README.Debian to reflect new features.
* Move dirs from d/rules to d/vidalia.dir.
* Updated Standard-version to 3.9.3 (no changes needed).

Show diffs side-by-side

added added

removed removed

Lines of Context:
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.
9
9
*/
10
10
 
25
25
 
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. */
30
30
class Log
31
31
{
41
41
    Unknown     /**< Unknown/invalid log level. */
42
42
  };
43
43
  class LogMessage;
44
 
  
 
44
 
45
45
  /** Default constructor. */
46
46
  Log();
47
47
  /** Destructor. */
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. */
56
56
  void close();
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(); }
61
 
  
 
61
 
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);
70
 
  
 
70
 
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);
80
 
  
 
80
 
81
81
private:
82
82
  LogLevel _logLevel; /**< Minimum log severity level. */
83
83
  QFile _logFile;     /**< Log output destination. */
84
84
};
85
85
 
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
90
90
{
91
91
public:
92
92
  struct Stream {
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;
96
96
    QIODevice *out;
97
97
    int ref;
98
98
    QString buf;
99
99
  } *stream;
100
 
 
 
100
 
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;
106
106
  ~LogMessage();
107
 
 
 
107
 
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; }