Vidalia 0.2.12
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If 00004 ** you did not receive the LICENSE file with this file, you may obtain it 00005 ** from the Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to 00008 ** the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file LogEvent.cpp 00013 ** \brief Event dispatched containing a log message from Tor 00014 */ 00015 00016 #include "LogEvent.h" 00017 #include "eventtype.h" 00018 00019 00020 /** Default constructor */ 00021 LogEvent::LogEvent(Severity severity, QString message) 00022 : QEvent((QEvent::Type)CustomEventType::LogEvent) 00023 { 00024 _severity = severity; 00025 _message = message.trimmed(); 00026 } 00027 00028 /** Converts a string description of a severity to its enum value */ 00029 LogEvent::Severity 00030 LogEvent::toSeverity(QString strSeverity) 00031 { 00032 Severity s; 00033 strSeverity = strSeverity.toUpper(); 00034 if (strSeverity == "DEBUG") { 00035 s = Debug; 00036 } else if (strSeverity == "INFO") { 00037 s = Info; 00038 } else if (strSeverity == "NOTICE") { 00039 s = Notice; 00040 } else if (strSeverity == "WARN") { 00041 s = Warn; 00042 } else if (strSeverity == "ERR" || strSeverity == "ERROR") { 00043 s = Error; 00044 } else { 00045 s = Unknown; 00046 } 00047 return s; 00048 } 00049 00050 /** Converts a Severity enum value to a string description */ 00051 QString 00052 LogEvent::severityToString(Severity s) 00053 { 00054 QString str; 00055 switch (s) { 00056 case Debug: str = tr("Debug"); break; 00057 case Info: str = tr("Info"); break; 00058 case Notice: str = tr("Notice"); break; 00059 case Warn: str = tr("Warning"); break; 00060 case Error: str = tr("Error"); break; 00061 default: str = tr("Unknown"); break; 00062 } 00063 return str; 00064 } 00065 00066 /** Returns the severity of this log event */ 00067 LogEvent::Severity 00068 LogEvent::severity() const 00069 { 00070 return _severity; 00071 } 00072 00073 /** Returns the message for this log event */ 00074 QString 00075 LogEvent::message() const 00076 { 00077 return _message; 00078 } 00079