File: logFile.cpp

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 (48 lines) | stat: -rw-r--r-- 1,179 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
// $Id: logFile.cpp 962 2006-11-07 15:13:34Z privmane $

#include "logFile.h"
#include "errorMsg.h"

int myLog::_loglvl = 3;
ostream *myLog::_out= NULL;
bool myLog::_firstTime = true;

void myLog::setLog(const string logfilename, const int loglvl) {
	if (_out != NULL) myLog::endLog();
	if ((logfilename == "-")|| (logfilename == "")) {
		myLog::setLogOstream(&cout);
	} else {
		ofstream* outLF = new ofstream;
		if (_firstTime) {
		  outLF->open(logfilename.c_str());
		  _firstTime = false;
		}
		else
		  outLF->open(logfilename.c_str(), ofstream::out | ofstream::app); // append
		if (!outLF->is_open()) {
			errorMsg::reportError(string("Can't open for writing the log file ")+logfilename);
		}
		myLog::setLogOstream(outLF);
	}
	myLog::setLogLvl(loglvl);
	LOG(3,<<"START OF LOG FILE"<<endl);
}

void myLog::endLog(void){
	LOG(3,<<"END OF LOG FILE"<<endl);
        if (_out!=&cout && _out != NULL) {
	  ((ofstream*)_out)->close();
	  delete _out;
	  _out = NULL;
	  _firstTime=false;
	}
}

void myLog::printArgv(int loglvl, int argc, char *argv[]) {
  LOG(loglvl,<<"argv =");
  
  for (int i=0;i<argc;++i)
    LOG(loglvl,<<" \""<<argv[i]<<"\"");
  LOG(loglvl,<<endl);
  
}