1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 
20 #ifndef utility_logH
21 #define utility_logH
22 
23 #include <fstream>
24 
25 #include "defines.h"
26 #include "utility/thread/mutex.h"
27 
28 class cLog
29 {
30 public:
31 	enum eLogType
32 	{
33 		eLOG_TYPE_DEBUG,
34 		eLOG_TYPE_INFO,
35 		eLOG_TYPE_WARNING,
36 		eLOG_TYPE_ERROR,
37 		eLOG_TYPE_MEM,
38 		eLOG_TYPE_NET_DEBUG,
39 		eLOG_TYPE_NET_WARNING,
40 		eLOG_TYPE_NET_ERROR,
41 	};
42 
43 	/**
44 	* Writes message with default type (II) to the logfile
45 	*/
46 	void write(const char* msg);
47 	void write(const std::string& msg);
48 
49 	/**
50 	* Writes message with given type to logfile
51 	*
52 	* @param str Message for the log
53 	* @param type Type for the log
54 	*/
55 	void write (const char* msg, eLogType type);
56 	void write (const std::string& msg, eLogType type);
57 
58 	/**
59 	* Writes a marker into logfile - please use only veeeery few times!
60 	*/
61 	void mark();
62 
63 private:
64 	std::ofstream logfile;
65 	std::ofstream netLogfile;
66 	cMutex mutex;
67 
68 	void checkOpenFile(eLogType type);
69 
70 	void writeToFile(const std::string &msg, std::ofstream& file);
71 
72 } EX Log;
73 
74 #endif // utility_logH
75