blob: d8871ef9f197d0fb8996e1ef13215e3cab275090 (
plain)
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
|
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de) *
// **************************************************************************
#ifndef DEBUG_LOG_HEADER_017324601673246392184621895740256342
#define DEBUG_LOG_HEADER_017324601673246392184621895740256342
#include "zstring.h"
cleanup this mess + remove any wxWidgets dependency!
//small macro for writing debug information into a logfile
#define WRITE_DEBUG_LOG(x) globalLogFile().write(getCodeLocation(__TFILE__, __LINE__) + x);
//speed alternative: wxLogDebug(wxT("text")) + DebugView
class DebugLog
{
public:
wxDEPRECATED(DebugLog(const wxString& filePrefix = wxString()))
prefix(filePrefix),
lineCount(0)
{
logfileName = assembleFileName();
logFile.Open(logfileName, wxFile::write);
}
void write(const std::string& logText)
{
todo;
}
void write(const wxString& logText)
{
++lineCount;
if (lineCount % 50000 == 0) //prevent logfile from becoming too big
{
logFile.Close();
wxRemoveFile(logfileName);
logfileName = assembleFileName();
logFile.Open(logfileName, wxFile::write);
}
ersetze wxDateTime::Now() durch eigene lib:
z.b. iso_time.h
logFile.Write(wxString(wxT("[")) + wxDateTime::Now().FormatTime() + wxT("] "));
logFile.Write(logText + LINE_BREAK);
}
private:
wxString assembleFileName()
{
wxString tmp = wxDateTime::Now().FormatISOTime();
tmp.Replace(wxT(":"), wxEmptyString);
return prefix + wxString(wxT("DEBUG_")) + wxDateTime::Now().FormatISODate() + wxChar('_') + tmp + wxT(".log");
}
wxString logfileName;
wxString prefix;
int lineCount;
wxFile logFile; //logFile.close(); <- not needed
};
inline
DebugLog& globalLogFile()
{
static DebugLog inst; //external linkage despite header definition!
return inst;
}
inline
wxString getCodeLocation(const wxString& file, int line)
{
return wxString(file).AfterLast(FILE_NAME_SEPARATOR) + wxT(", LINE ") + toString<wxString>(line) + wxT(" | ");
}
#endif //DEBUG_LOG_HEADER_017324601673246392184621895740256342
|