Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
cefpython/src/LOG_DEBUG.h at cefpython52 · studyNowHa/cefpython · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
studyNowHa
/
cefpython
Public
forked from
cztomczak/cefpython
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
cefpython52
Breadcrumbs
cefpython
/
src
/
LOG_DEBUG.h
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
211 lines (181 loc) · 5.14 KB
cefpython52
Breadcrumbs
cefpython
/
src
/
LOG_DEBUG.h
Copy path
Top
File metadata and controls
Code
Blame
211 lines (181 loc) · 5.14 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//
Taken from here: http://www.drdobbs.com/cpp/logging-in-c/201804215
//
Original author: Petru Marginean <petru.marginean@gmail.com>
//
Modified by: Czarek Tomczak <czarek.tomczak@gmail.com>
//
Usage:
//
LOG_DEBUG << "Browser: someVar = " << someVar;
//
Warning:
//
Log is written when ~Log() destructor is called, which
//
occurs when outside of scope. This could result in log
//
not being written if program crashes before code goes
//
outside of current scope. You could embrace LOG_DEBUG
//
statements with braces {} to guarantee the log to be
//
written immediately.
#
ifndef
__LOG_DEBUG_H__
#
define
__LOG_DEBUG_H__
#
include
<
sstream
>
#
include
<
string
>
#
include
<
stdio.h
>
#
include
"
DebugLog.h
"
inline
std::string
NowTime
();
enum
TLogLevel {logERROR, logWARNING, logINFO, logDEBUG,
logDEBUG1, logDEBUG2, logDEBUG3, logDEBUG4};
template
<
typename
T>
class
Log
{
public:
Log
();
virtual
~Log
();
std::ostringstream&
Get
(TLogLevel level = logINFO);
public:
static
TLogLevel&
ReportingLevel
();
static
std::string
ToString
(TLogLevel level);
static
TLogLevel
FromString
(
const
std::string& level);
protected:
std::ostringstream os;
private:
Log
(
const
Log&);
Log&
operator
=(
const
Log&);
};
template
<
typename
T>
Log<T>::Log()
{
}
template
<
typename
T>
std::ostringstream& Log<T>::Get(TLogLevel level)
{
//
os << "- " << NowTime();
//
os << " " << ToString(level) << ": ";
//
os << std::string(level > logDEBUG ? level - logDEBUG : 0, '\t');
return
os;
}
template
<
typename
T>
Log<T>::
~Log
()
{
os << std::endl;
/*
if (T::Stream() != stderr) {
fprintf(stderr, "%s", os.str().c_str());
fflush(stderr);
}
T::Output(os.str());
*/
DebugLog
(os.
str
().
c_str
());
}
template
<
typename
T>
TLogLevel& Log<T>::ReportingLevel()
{
static
TLogLevel reportingLevel = logDEBUG4;
return
reportingLevel;
}
template
<
typename
T>
std::string Log<T>::ToString(TLogLevel level)
{
static
const
char
*
const
buffer[] = {
"
ERROR
"
,
"
WARNING
"
,
"
INFO
"
,
"
DEBUG
"
,
"
DEBUG1
"
,
"
DEBUG2
"
,
"
DEBUG3
"
,
"
DEBUG4
"
};
return
buffer[level];
}
template
<
typename
T>
TLogLevel Log<T>::FromString(
const
std::string& level)
{
if
(level ==
"
DEBUG4
"
)
return
logDEBUG4;
if
(level ==
"
DEBUG3
"
)
return
logDEBUG3;
if
(level ==
"
DEBUG2
"
)
return
logDEBUG2;
if
(level ==
"
DEBUG1
"
)
return
logDEBUG1;
if
(level ==
"
DEBUG
"
)
return
logDEBUG;
if
(level ==
"
INFO
"
)
return
logINFO;
if
(level ==
"
WARNING
"
)
return
logWARNING;
if
(level ==
"
ERROR
"
)
return
logERROR;
Log<T>().
Get
(logWARNING) <<
"
Unknown logging level '
"
<< level
<<
"
'. Using INFO level as default.
"
;
return
logINFO;
}
class
Output2FILE
{
public:
static
FILE
*&
Stream
();
static
void
Output
(
const
std::string& msg);
};
inline
FILE
*&
Output2FILE::Stream
()
{
static
FILE
* pStream = stderr;
return
pStream;
}
inline
void
Output2FILE::Output
(
const
std::string& msg)
{
/*
FILE* pStream = Stream();
if (!pStream)
return;
fprintf(pStream, "%s", msg.c_str());
fflush(pStream);
*/
}
#
if
defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#
if
defined (BUILDING_FILELOG_DLL)
#
define
FILELOG_DECLSPEC
__declspec
(dllexport)
#
elif
defined (USING_FILELOG_DLL)
#
define
FILELOG_DECLSPEC
__declspec
(dllimport)
#
else
#
define
FILELOG_DECLSPEC
#
endif
//
BUILDING_DBSIMPLE_DLL
#
else
#
define
FILELOG_DECLSPEC
#
endif
//
_WIN32
class
FILELOG_DECLSPEC
FILELog : public Log<Output2FILE> {};
//
typedef Log<Output2FILE> FILELog;
#
ifndef
FILELOG_MAX_LEVEL
#
define
FILELOG_MAX_LEVEL
logDEBUG4
#
endif
//
Name conflits with cef_logging.h, see:
//
https://bitbucket.org/chromiumembedded/cef/issues/1830
//
LOG, LOG_ERROR, LOG_WARNING and LOG_INFO are already defined
//
in cef_logging.h and must not be used here. So far we've only
//
used LOG_DEBUG in code.
#
define
CEFPYTHON_LOG
(
level
) \
if
(level >
FILELOG_MAX_LEVEL
) ;\
else
if
(level >
FILELog::ReportingLevel
() || !Output2FILE::Stream()) ; \
else
FILELog().Get(level) \
//
#define LOG_ERROR LOG(logERROR)
//
#define LOG_WARNING LOG(logWARNING)
//
#define LOG_INFO LOG(logINFO)
#
define
LOG_DEBUG
CEFPYTHON_LOG
(logDEBUG)
#
if
defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#
include
<
windows.h
>
inline
std::string
NowTime
()
{
const
int
MAX_LEN
=
200
;
char
buffer[
MAX_LEN
];
if
(
GetTimeFormatA
(
LOCALE_USER_DEFAULT
,
0
,
0
,
"
HH':'mm':'ss
"
, buffer,
MAX_LEN
) ==
0
)
return
"
Error in NowTime()
"
;
char
result[
100
] = {
0
};
static
DWORD
first =
GetTickCount
();
#
pragma
warning(suppress: 4996)
sprintf
(result,
"
%s.%03ld
"
, buffer, (
long
)(
GetTickCount
() - first) %
1000
);
return
result;
}
#
else
#
include
<
sys/time.h
>
inline
std::string
NowTime
()
{
char
buffer[
11
];
time_t
t;
time
(&t);
tm r = {
0
};
strftime
(buffer,
sizeof
(buffer),
"
%X
"
,
localtime_r
(&t, &r));
struct
timeval
tv;
gettimeofday
(&tv,
0
);
char
result[
100
] = {
0
};
sprintf
(result,
"
%s.%03ld
"
, buffer, (
long
)tv.
tv_usec
/
1000
);
return
result;
}
#
endif
//
WIN32
#
endif
//
__LOG_DEBUG_H__
You can’t perform that action at this time.