/*************************************************************************** * Copyright (C) 2006 by Nicolas PASCAL * * pascal@icare-pc12 * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ /** * @file logfile.h This file contains a class designed to make the usage of logging files easier * @author CGTD/UDEV N. PASCAL ( nicolas.pascal@icare.univ-lille1.fr ) * History: * 05/03/2007 : creation */ #ifndef LOGFILE_H #define LOGFILE_H #include "file_exceptions.h" #include "tools.h" #include using namespace std; /** * @class Logfile management of a logging file, that uses the standard fluxes syntax * @warning the file descriptor to this file is opened during all the "lifetime" of the Logfile object */ class Logfile { /** full pathname of the log file */ string filename; /** log file descriptor */ ofstream fp; public: /** * @brief constructor * @param filename the full name of the logging file to write */ Logfile(const string &filename); /** * @brief default constructor */ Logfile(); /** * @brief destructor */ ~Logfile(); /** * @brief write the string @a msg as a line in the log file * Add a "end of line" character at the end of @a msg is not required. The method does it by itself * @param msg the message to write * @param file [optionnal] name of file that is concerned by the message * @param line [optionnal] line of file that is concerned by the message */ void write(const string &msg, const string file="", const int line=-1); /** * @brief open the file in write mode * @param filename the full name of the logging file to write */ void open(const string &filename); /** * @brief check if the log file is opened * @return true if the log file is opened */ const bool is_opened (); /** * @brief close the log file */ void close(); }; #endif