00001 /**************************************************************** 00002 * Vidalia is distributed under the following license: 00003 * 00004 * Copyright (C) 2006, Matt Edman, Justin Hipple 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 * Boston, MA 02110-1301, USA. 00020 ****************************************************************/ 00021 00022 /** 00023 * \file logfile.h 00024 * \version $Id: logfile.h 1563 2006-12-26 06:06:04Z edmanm $ 00025 * \brief Logs messages from Tor to a file 00026 */ 00027 00028 #ifndef _LOGFILE_H 00029 #define _LOGFILE_H 00030 00031 #include <QFile> 00032 #include <QObject> 00033 #include <QString> 00034 #include <QTextStream> 00035 00036 00037 class LogFile : QObject 00038 { 00039 Q_OBJECT 00040 00041 public: 00042 /** Default constructor. */ 00043 LogFile(); 00044 /** Destructor. */ 00045 ~LogFile(); 00046 00047 /** Opens a log file for writing. */ 00048 bool open(QString filename, QString *errmsg = 0); 00049 /** Closes an open log file. */ 00050 void close(); 00051 00052 /** Returns true if the logfile is currently open. */ 00053 bool isOpen(); 00054 /** Returns the filename of the current log file. */ 00055 QString filename(); 00056 00057 /** Overloaded ostream operator. */ 00058 LogFile& operator<<(const QString &s); 00059 00060 private: 00061 /** Creates a path to the given log file */ 00062 bool createPathToFile(QString filename); 00063 00064 QFile* _file; /**< The log file. */ 00065 QTextStream _stream; /**< Stream used to write to the log file. */ 00066 }; 00067 00068 #endif 00069