Vidalia 0.2.10
|
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 ** \version $Id: LogEvent.cpp 3735 2009-04-28 20:28:01Z edmanm $ 00014 ** \brief Event dispatched containing a log message from Tor 00015 */ 00016 00017 #include "LogEvent.h" 00018 #include "eventtype.h" 00019 00020 00021 /** Default constructor */ 00022 LogEvent::LogEvent(Severity severity, QString message) 00023 : QEvent((QEvent::Type)CustomEventType::LogEvent) 00024 { 00025 _severity = severity; 00026 _message = message.trimmed(); 00027 } 00028 00029 /** Converts a string description of a severity to its enum value */ 00030 LogEvent::Severity 00031 LogEvent::toSeverity(QString strSeverity) 00032 { 00033 Severity s; 00034 strSeverity = strSeverity.toUpper(); 00035 if (strSeverity == "DEBUG") { 00036 s = Debug; 00037 } else if (strSeverity == "INFO") { 00038 s = Info; 00039 } else if (strSeverity == "NOTICE") { 00040 s = Notice; 00041 } else if (strSeverity == "WARN") { 00042 s = Warn; 00043 } else if (strSeverity == "ERR" || strSeverity == "ERROR") { 00044 s = Error; 00045 } else { 00046 s = Unknown; 00047 } 00048 return s; 00049 } 00050 00051 /** Converts a Severity enum value to a string description */ 00052 QString 00053 LogEvent::severityToString(Severity s) 00054 { 00055 QString str; 00056 switch (s) { 00057 case Debug: str = tr("Debug"); break; 00058 case Info: str = tr("Info"); break; 00059 case Notice: str = tr("Notice"); break; 00060 case Warn: str = tr("Warning"); break; 00061 case Error: str = tr("Error"); break; 00062 default: str = tr("Unknown"); break; 00063 } 00064 return str; 00065 } 00066 00067 /** Returns the severity of this log event */ 00068 LogEvent::Severity 00069 LogEvent::severity() const 00070 { 00071 return _severity; 00072 } 00073 00074 /** Returns the message for this log event */ 00075 QString 00076 LogEvent::message() const 00077 { 00078 return _message; 00079 } 00080