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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
#include "Logfile.h"
#include <fstream>
using namespace std;
// constructor
// Aufgabe: bisher noch keine
Logfile::Logfile() {
}
// Destructor
// Gibt Meldung aus und schliesst das Logfile
Logfile::~Logfile() {
textout("<p>End of logfile!</font></p></body></html>");
textout("Destruktor!");
m_Logfile.close();
}
// CreateLogfile
// Aufgabe Logfile erstellen und Kopf schreiben
void Logfile::createLogfile(const char *logName) {
m_Logfile.open(logName, ios_base::in|ios_base::trunc);
textout("Die ist ein Teststring, ob das schreiben wirklich funktioniert!");
textout("<html><head><title>Logfile</title></head>");
textout("<body><font face='courier new'>");
writeTopic("Logfile", 3);
// Aktuelle Build-Konfiguration ausgeben
#ifdef _DEBUG
textout("BUILD: DEBUG<br>");
#else
textout("BUILD: RELEASE<br>");
#endif
// Link für E-Mail Adresse schreiben
textout("<a href='mailto:spam@internet>E-Mail</a>");
// Logfile schiessen und mit append wieder öffnen
m_Logfile.close();
m_Logfile.open(logName, ios_base::out|ios_base::app);
}
// WriteTopic
// Aufgabe: Überschrifterzeugen
void Logfile::writeTopic(const char *topic, int size) {
// Überschrift schreiben und flushen
textout("<table cellspacing=0 cellpadding=0 width='100%%' bgcolor='#DFDFE5'");
textout("\n<tr>\n<td>\n<font face='arial' ");
ftextout("size='+%i'>\n", size);
textout(topic);
textout("</font>\n</td>\n</tr>\n</table>\n<br>");
m_Logfile.flush();
}
// textout
// Aufgabe: Text ins Logfile schreiben (schwarz)
void Logfile::textout(const char *text) {
// Text schreiben und flushen
m_Logfile.write(text, sizeof(text));
m_Logfile.flush();
} // textout (schwarze)
// textout
// Aufgabe: Text ins Logfile schreiben (farbig)
void Logfile::textout(int color, const char *text) {
textout(color, false, text);
} // textout (farbig)
// textout
// Aufgabe: Text ins Logfile schreiben (farbig, liste)
void Logfile::textout(int color, bool list, const char *text) {
// Listen schreiben
if (list == true) {
textout("<li>");
}
switch (color) {
case BLACK:
textout("<font color='black'"); break;
case RED:
textout("<font color='red'"); break;
case GREEN:
textout("<font color='green'"); break;
case BLUE:
textout("<font color='blue'"); break;
case PURPLE:
textout("<font color='purple'"); break;
}
// Text schreiben
textout(text);
textout("</font>");
if (list == false) {
textout("<br>");
} else {
textout("</li>");
}
} // textout (farbig, liste)
void Logfile::ftextout(const char *text, ...) {
char buffer[MAX_BUFFER];
va_list pArgList; // Liste übergebener Argumente
va_start(pArgList, text);
vsprintf(buffer, text, pArgList);
va_end(pArgList);
// Erzeugten String schreiben
textout(buffer);
} // fTextout (schwarz)
// fTextout (farbe)
// Ausgabe: formatierten Text ins Logfile schreiben
void Logfile::ftextout(int color, const char *text, ...) {
char buffer[MAX_BUFFER];
va_list pArgList; // Liste übergebener Argumente
va_start(pArgList, text);
vsprintf(buffer, text, pArgList);
va_end(pArgList);
// Erzeugten String schreiben
textout(color, buffer);
} // fTextout (farbe)
// fTextout (farbe, liste)
// Ausgabe: formatierten Text ins Logfile schreiben
void Logfile::ftextout(int color, bool list, const char *text, ...) {
char buffer[MAX_BUFFER];
va_list pArgList; // Liste übergebener Argumente
va_start(pArgList, text);
vsprintf(buffer, text, pArgList);
va_end(pArgList);
// Erzeugten String schreiben
textout(color, list, buffer);
} // fTextout (farbe, liste)
// Function-Result
// Aufgabe: OK oder ERROR für Funktionsaufruf ausgeben
void Logfile::functionResult(const char *name, bool result) {
if (L_OK == result) {
textout("<table width='100%%' cellspacing='1' cellpadding='5'");
textout(" border='0' bgcolor='#C0C0C0'><tr><td bgcolor=");
ftextout("'#FFFFFF' width='35%'>%s</td>", name);
textout("<td bgcolor='#FFFFFF' width='30%%'><font color=");
textout("'green'>OK</FONT></TD><td bgcolor='#FFFFFF' ");
textout("width='35%%'>-/-</TD></tr></table>");
} else {
textout("<table width='100%%' cellspacing='1' cellpadding='5'");
textout(" border='0' bgcolor='#C0C0C0'><tr><td bgcolor=");
ftextout("'#FFFFFF' width='35%'>%s</td>", name);
textout("<td bgcolor='#FFFFFF' width='30%%'><font color=");
textout("'red'>ERROR</FONT></TD><td bgcolor='#FFFFFF' ");
textout("width='35%%'>-/-</TD></tr></table>");
}
}
|