Vidalia  0.2.17
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Attributes
Log Class Reference

#include <Log.h>

List of all members.

Classes

class  LogMessage

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

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 30 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 34 of file Log.h.


Constructor & Destructor Documentation

Log::Log ( )

Default constructor.

Default constructor. Logs at level Notice by default.

Definition at line 29 of file Log.cpp.

References _logLevel, and Notice.

Log::~Log ( )

Destructor.

Destructor. Closes the log file.

Definition at line 35 of file Log.cpp.

References close().


Member Function Documentation

void Log::close ( )

Closes the log file.

Flushes any outstanding log messages and closes the log file.

Definition at line 85 of file Log.cpp.

References _logFile.

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

QString Log::errorString ( ) [inline]

Returns a string description of the last file error encountered.

Definition at line 60 of file Log.h.

References _logFile.

Referenced by Vidalia::validateArguments().

bool Log::isOpen ( ) [inline]

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

Definition at line 58 of file Log.h.

References _logFile.

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

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 109 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 98 of file Log.cpp.

References _logFile, and _logLevel.

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 42 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 116 of file Log.cpp.

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

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

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 62 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 73 of file Log.cpp.

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

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 52 of file Log.cpp.

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

Referenced by Vidalia::Vidalia().

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 132 of file Log.cpp.

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

Referenced by Vidalia::Vidalia().


Member Data Documentation

QFile Log::_logFile [private]

Log output destination.

Definition at line 83 of file Log.h.

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

Minimum log severity level.

Definition at line 82 of file Log.h.

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


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