forked from alpha0010/ClangLib
-
Notifications
You must be signed in to change notification settings - Fork 4
/
cclogger.cpp
112 lines (95 loc) · 3.61 KB
/
cclogger.cpp
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
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
* http://www.gnu.org/licenses/gpl-3.0.html
*
* $Revision: 9644 $
* $Id: cclogger.cpp 9644 2014-02-10 08:05:48Z ollydbg $
* $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/trunk/src/plugins/codecompletion/parser/cclogger.cpp $
*/
#include "cclogger.h"
#include <wx/event.h>
#include <wx/textfile.h>
#include <wx/utils.h> // wxNewId
#include <logmanager.h> // F()
#include <globals.h> // cbC2U for cbAssert macro
std::auto_ptr<CCLogger> CCLogger::s_Inst;
bool g_EnableDebugTrace = false;
bool g_EnableDebugTraceFile = false; // true
const wxString g_DebugTraceFile = wxEmptyString;
long g_idCCAddToken = wxNewId();
long g_idCCLogger = wxNewId();
long g_idCCDebugLogger = wxNewId();
#define TRACE_TO_FILE(msg) \
if (g_EnableDebugTraceFile && !g_DebugTraceFile.IsEmpty()) \
{ \
wxTextFile f(g_DebugTraceFile); \
if ((f.Exists() && f.Open()) || (!f.Exists() && f.Create())) \
{ \
f.AddLine(msg); \
cbAssert(f.Write() && f.Close()); \
} \
} \
#define TRACE_THIS_TO_FILE(msg) \
if (!g_DebugTraceFile.IsEmpty()) \
{ \
wxTextFile f(g_DebugTraceFile); \
if ((f.Exists() && f.Open()) || (!f.Exists() && f.Create())) \
{ \
f.AddLine(msg); \
cbAssert(f.Write() && f.Close()); \
} \
} \
CCLogger::CCLogger() :
m_Parent(nullptr),
m_LogId(-1),
m_DebugLogId(-1),
m_AddTokenId(-1)
{
}
/*static*/ CCLogger* CCLogger::Get()
{
if (!s_Inst.get())
s_Inst.reset(new CCLogger);
return s_Inst.get();
}
// Initialized from plugin constructor
void CCLogger::Init(wxEvtHandler* parent, int logId, int debugLogId, int addTokenId)
{
m_Parent = parent;
m_LogId = logId;
m_DebugLogId = debugLogId;
m_AddTokenId = addTokenId;
}
void CCLogger::AddToken(const wxString& msg)
{
if (!m_Parent || m_AddTokenId<1) return;
CodeBlocksThreadEvent evt(wxEVT_COMMAND_MENU_SELECTED, m_AddTokenId);
evt.SetString(msg);
#if CC_PROCESS_LOG_EVENT_TO_PARENT
m_Parent->ProcessEvent(evt);
#else
wxPostEvent(m_Parent, evt);
#endif
}
void CCLogger::Log(const wxString& msg)
{
if (!m_Parent || m_LogId<1) return;
CodeBlocksThreadEvent evt(wxEVT_COMMAND_MENU_SELECTED, m_LogId);
evt.SetString(msg);
#if CC_PROCESS_LOG_EVENT_TO_PARENT
m_Parent->ProcessEvent(evt);
#else
wxPostEvent(m_Parent, evt);
#endif
}
void CCLogger::DebugLog(const wxString& msg)
{
if (!m_Parent || m_DebugLogId<1) return;
CodeBlocksThreadEvent evt(wxEVT_COMMAND_MENU_SELECTED, m_DebugLogId);
evt.SetString(msg);
#if CC_PROCESS_LOG_EVENT_TO_PARENT
m_Parent->ProcessEvent(evt);
#else
wxPostEvent(m_Parent, evt);
#endif
}