Almetare  1.15
Alle meine Taschenrechner - Eine C++-Bibliothek zur Entwicklung von Taschenrechnern
logging.h
gehe zur Dokumentation dieser Datei
1 //******************************************************************************
2 // Copyright (c) 2002-2004 by Friedemann Seebass, Germany.
3 // Dieses Programm ist freie Software. Siehe GNU GPL Notiz in Datei main.cpp.
4 // This program is free software. See the GNU GPL notice in file main.cpp.
5 // Projekt: Almetare - Alle meine Taschenrechner
6 //******************************************************************************
9 //******************************************************************************
10 // Wann Wer Was
11 // ---------- -------- ---------------------------------------------------------
12 // 20.03.2003 fse dbgLog->gDbgLog, errLog->gErrLog, onlLog->gOnlLog
13 // 28.03.2002 fse Alle speziellen Ausgabeoperatoren entfernt und durch
14 // Template ersetzt.
15 // 29.03.2002 fse Ausgabeoperatoren als Template
16 // 29.11.2001 fse channelsToStr(), strToChannels() zugefuegt
17 // 10.11.2001 fse writeHeader() zugefuegt
18 // 19.12.2000 fse erzeugt
19 //******************************************************************************
20 
21 #ifndef LOGGING_H
22 #define LOGGING_H
23 
24 #ifndef __cplusplus
25 #error logging.h is only for C++!
26 #endif
27 
28 //******************************************************************************
29 
30 #include <iostream>
31 #include <string>
32 #include <fstream>
33 
34 using namespace std;
35 
36 //******************************************************************************
37 
38 #define DBG_LOG(channel) if (gDbgLog.configured(channel, __FILE__, __LINE__)) gDbgLog
39 #define ERR_LOG(channel) if (gErrLog.configured(channel, __FILE__, __LINE__)) gErrLog
40 #define ONL_LOG(channel) if (gOnlLog.configured(channel, __FILE__, __LINE__)) gOnlLog
41 #define NL "\n"
42 
43 typedef void (*funcp)(void);
44 
45 //******************************************************************************
46 // Log-Klasse
47 //******************************************************************************
48 
49 enum
50 {
51  ctl = 1,
52  mem = 2,
53  gnl = 4,
54  hgh = 8,
55  med = 16,
56  low = 32,
57  all = ctl + mem + gnl + hgh + med + low,
58  cns = 64
59 };
60 
61 //******************************************************************************
62 
105 // fse, 19.12.02
106 
107 class Log
108 {
109  string mFname;
110  ofstream* mFstreamP;
112  string mFileToLog;
115  string mProgName;
116  string mVersion;
117  void writeHeader();
118  int backupLogFile();
119 public:
120  Log(const string& fname = "",
121  int channels = hgh | cns | med,
122  int maxLen = 50000,
123  const string& toLog = "",
124  const string& progName = "Unknown",
125  const string& version = "Vx.x");
126  ~Log();
127  int init(const string& fname,
128  int channels,
129  int maxLogLen,
130  const string& fileToLog,
131  const string& progName,
132  const string& version);
133  ofstream* getFstreamP() { return mFstreamP; }
134  int getConfChannels() const { return mConfChannels; }
135  void stopLogging();
136  void setConfChannels(int chans) { mConfChannels = chans; }
137  static string getDate();
138  static string getTime();
139  static string channelsToStr(int channels);
140  static int strToChannels(const string& str);
141  bool configured(int channels, const char* file, int line);
142  ios::fmtflags setf(ios::fmtflags format) { return mFstreamP->setf(format); }
143  // Ausgabeoperatoren:
144 // Log& operator<<(const char* out);
145 // Log& operator<<(const string& out);
146 // Log& operator<<(string& out);
147 // Log& operator<<(const int out);
148 // Log& operator<<(const float out);
149 // Log& operator<<(const double out);
150 // Log& operator<<(const void* out);
151 // Log& operator<<(const unsigned int out);
152 // Log& operator<<(Symbol& out);
153 // Log& operator<<(Computer& out);
154 // Log& operator<<(CalcDisplay& out);
155 // Log& operator<<(const funcp);
156  // geht leider nicht mit VC++, nur mit GNU (s. Kommentar bei Node::new()):
157 //#ifdef _MSC_VER
158 // Log& operator<<(_Smanip<int> out);
159 //#else
160 // Log& operator<<(smanip<int> out);
161 //#endif
162 };
163 
164 //******************************************************************************
165 
169 // fse, 28.03.02
170 
171 template<class T> Log& operator<<(Log& log, const T& out)
172 {
173  if (log.getFstreamP() ) *log.getFstreamP() << out;
174  if (log.getConfChannels() & cns) cout << out;
175  return log;
176 }
177 
178 //******************************************************************************
179 
180 extern Log gDbgLog;
181 extern Log gErrLog;
182 extern Log gOnlLog;
183 void logFlush(void);
184 void errFlush(void);
185 void onlFlush(void);
186 
187 #endif // !LOGGING_H
ofstream * mFstreamP
Filestream der Datei.
Definition: logging.h:110
"High" - wichtige Ausgaben
Definition: logging.h:54
"Memory" - Speicherverwaltung
Definition: logging.h:52
bool mIsSuppressed
Ausgabe unterdrueckt.
Definition: logging.h:114
string mFileToLog
Name der Quelltextdatei, die als einzige geloggt wird.
Definition: logging.h:112
int mMaxLogLen
maximale Laenge der Log-Dateien in Byte
Definition: logging.h:113
"Control" - Kontrollfluss
Definition: logging.h:51
"Medium" - normale Ausgaben
Definition: logging.h:55
"General" - allgemeine Ausgaben
Definition: logging.h:53
"Console" - Ausgaben zusaetzlich auf Konsole
Definition: logging.h:58
string mProgName
Name des Programms (fuer Titelzeile der Log-Datei)
Definition: logging.h:115
string mFname
Name d. Datei, in die geloggt wird ("" = Konsole)
Definition: logging.h:109
Klasse zum Loggen von Laufzeitausgaben in eine Datei.
Definition: logging.h:107
Log & operator<<(Log &log, const T &out)
Globales Funktions-Template.
Definition: logging.h:171
string mVersion
Version des Programms (fuer Titelzeile der Log-Datei)
Definition: logging.h:116
int mConfChannels
Kanaele, die konfiguriert sind (z. B. per Ini-Datei)
Definition: logging.h:111
"Low" - unwichtige Ausgaben
Definition: logging.h:56