File: logFile.h

package info (click to toggle)
fastml 3.11-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,772 kB
  • sloc: cpp: 48,522; perl: 3,588; ansic: 819; makefile: 386; python: 83; sh: 55
file content (50 lines) | stat: -rw-r--r-- 1,227 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// $Id: logFile.h 6067 2009-04-14 19:12:28Z itaymay $

#ifndef ___LOG
#define ___LOG


#include <string>
#include <iostream>
#include <fstream>

using namespace std;
			
class myLog {
public:
	static int LogLevel() { return _loglvl;}
	static ostream& LogFile(void) {
		if (_out == NULL) return cerr;
		return *_out;
	}

	static void setLogLvl(const int newLogLvl) {_loglvl = newLogLvl;}
	static void setLogOstream(ostream* out) {_out = out;}

	// this function is problematic, because it issue a call to NEW
	// which because the function is static - cannot be deleted.
	// but, this will not effect the program, because there is only
	// 1 instance of _out and it will be released anyway in the end of the program.
	static void setLog(const string logfilename, const int loglvl);
	static void endLog(void);
	static void printArgv(int loglvl, int argc, char *argv[]) ;
private:
	static ostream* _out;
	static int _loglvl;
	static bool _firstTime;
};

#ifdef LOG
#undef LOG
#endif
		

#define LOG(Lev, ex) { if( Lev <= myLog::LogLevel() ) myLog::LogFile() ex; }
#define LOGnOUT(Lev, ex) { if( Lev <= myLog::LogLevel() ) {myLog::LogFile() ex; cerr ex; }}
#define LOGDO(Lev, ex) { if( Lev <= myLog::LogLevel() ) ex; }


#endif