Log Class Reference

#include <log.h>

List of all members.

Public Types

enum  LogLevel {
  Debug = 0, Info, Notice, Warn,
  Error, Off, Unknown
}

Public Member Functions

 Log ()
 ~Log ()
bool open (FILE *file)
bool open (QString file)
void close ()
bool isOpen ()
QString errorString ()
void setLogLevel (LogLevel level)
LogMessage log (LogLevel level, QString message)
LogMessage log (LogLevel level)

Static Public Member Functions

static QStringList logLevels ()
static QString logLevelToString (LogLevel level)
static LogLevel stringToLogLevel (QString str)

Private Attributes

LogLevel _logLevel
QFile _logFile

Classes

class  LogMessage


Detailed Description

The Log class is similar to the QDebug class provided with Qt, but with finer-grained logging levels, slightly different output (for example, not everything is wrapped in double quotes), supports using .arg(), and can still be used even if Qt was compiled with QT_NO_DEBUG_STREAM.

Definition at line 31 of file log.h.


Member Enumeration Documentation

Logging severity levels.

Enumerator:
Debug  Verbose debugging output.
Info  Primarily program flow output.
Notice  Non-failure (but important) events.
Warn  Recoverable failure conditions.
Error  Critical, non-recoverable errors.
Off  No logging output.
Unknown  Unknown/invalid log level.

Definition at line 35 of file log.h.


Constructor & Destructor Documentation

Log::Log (  ) 

Default constructor.

Default constructor. Logs at level Notice by default.

Definition at line 30 of file log.cpp.

References _logLevel, and Notice.

Log::~Log (  ) 

Destructor.

Destructor. Closes the log file.

Definition at line 36 of file log.cpp.

References close().


Member Function Documentation

bool Log::open ( FILE *  file  ) 

Opens a file on disk (or stdout or stderr) to which log messages will be written.

Opens file for appending, to which log messages will be written.

Definition at line 63 of file log.cpp.

References _logFile, close(), isOpen(), and LOGFILE_MODE.

Referenced by Vidalia::Vidalia().

bool Log::open ( QString  file  ) 

Opens a file on disk to which log messages will be written.

Opens file for appending, to which log messages will be written.

Definition at line 74 of file log.cpp.

References _logFile, close(), isOpen(), and LOGFILE_MODE.

void Log::close (  ) 

Closes the log file.

Flushes any outstanding log messages and closes the log file.

Definition at line 86 of file log.cpp.

References _logFile.

Referenced by open(), and ~Log().

bool Log::isOpen (  )  [inline]

Returns true if the log file is open and ready for writing.

Definition at line 59 of file log.h.

References _logFile.

Referenced by open(), and Vidalia::validateArguments().

QString Log::errorString (  )  [inline]

Returns a string description of the last file error encountered.

Definition at line 61 of file log.h.

References _logFile.

Referenced by Vidalia::validateArguments().

void Log::setLogLevel ( LogLevel  level  ) 

Sets the current log level to level.

Sets the current log level to level. If level is Off, then the log file will be closed as well. If level is Unknown, no change to the current log level is made.

Definition at line 53 of file log.cpp.

References _logFile, _logLevel, Debug, Off, and Unknown.

Referenced by Vidalia::Vidalia().

QStringList Log::logLevels (  )  [static]

Returns a list of strings representing valid log levels.

Returns a list of strings representing available log levels.

Definition at line 43 of file log.cpp.

Referenced by Vidalia::showUsageMessageBox(), and Vidalia::validateArguments().

QString Log::logLevelToString ( LogLevel  level  )  [inline, static]

Returns a string description of the given LogLevel level.

Definition at line 117 of file log.cpp.

References Debug, Error, Info, Notice, Off, and Warn.

Referenced by Log::LogMessage::toString().

Log::LogLevel Log::stringToLogLevel ( QString  str  )  [static]

Returns a LogLevel for the level given by str.

Returns a LogLevel for the level given by str, or Unknown if the given string does not represent a valid LogLevel value.

Definition at line 133 of file log.cpp.

References Debug, Error, Info, Notice, Off, Unknown, and Warn.

Referenced by Vidalia::Vidalia().

Log::LogMessage Log::log ( LogLevel  level,
QString  msg 
)

Creates a log message with severity level and initial message contents message. The log message can be appended to until the returned LogMessage's destructor is called, at which point the complete message is written to the log file.

Creates a log message with severity level. The log message can be appended to until the returned LogMessage's destructor is called, at which point the complete message is written to the log file.

Definition at line 110 of file log.cpp.

Referenced by Vidalia::log(), and Log::LogMessage::~LogMessage().

Log::LogMessage Log::log ( LogLevel  level  )  [inline]

Creates a log message with severity level. The log message can be appended to until the returned LogMessage's destructor is called, at which point the complete message is written to the log file.

Creates a log message with severity level and initial message contents message. The log message can be appended to until the returned LogMessage's destructor is called, at which point the complete message is written to the log file.

Definition at line 99 of file log.cpp.

References _logFile, and _logLevel.


Member Data Documentation

Minimum log severity level.

Definition at line 83 of file log.h.

Referenced by log(), Log(), and setLogLevel().

QFile Log::_logFile [private]

Log output destination.

Definition at line 84 of file log.h.

Referenced by close(), errorString(), isOpen(), log(), open(), and setLogLevel().


The documentation for this class was generated from the following files:

Generated on Wed Nov 26 21:03:59 2008 for Vidalia by  doxygen 1.5.6