41
41
// Macro to prevent repeated logging calls for the same
43
#define LOG_ONCE(x) { static bool warned = false; if (!warned) { warned = true; x; } }
43
#define LOG_ONCE(x) { \
44
static bool warned = false; \
45
if (!warned) { warned = true; x; } \
45
// Define to switch between printf-style log formatting
47
48
# include <boost/preprocessor/arithmetic/inc.hpp>
48
49
# include <boost/preprocessor/repetition/enum_params.hpp>
49
50
# include <boost/preprocessor/repetition/repeat.hpp>
50
51
# include <boost/preprocessor/repetition/repeat_from_to.hpp>
51
52
# include <boost/preprocessor/seq/for_each.hpp>
54
// Mingw32 (win32 console) doesn't use the standard GCC defines that
55
// Gnash used for debug messages, so make it so...
57
#define __FUNCDNAME__ __FUNCTION__
55
#define GNASH_DEBUG_LEVEL 2
57
62
// This is a basic file logging class
58
class DSOEXPORT LogFile {
63
class DSOEXPORT LogFile
61
67
static LogFile& getDefaultInstance();
107
120
void setLogFilename(const std::string& fname);
109
122
// accessors for the verbose level
110
void setVerbosity () {
123
void setVerbosity() {
114
void setVerbosity (int x) {
127
void setVerbosity(int x) {
118
int getVerbosity () {
131
int getVerbosity() const {
122
void setActionDump (int x) {
135
void setActionDump(int x) {
126
int getActionDump () {
139
void setNetwork(int x) {
143
int getActionDump() const {
127
144
return _actiondump;
147
int getNetwork() const {
130
151
void setParserDump (int x) {
134
int getParserDump () {
155
int getParserDump() const {
135
156
return _parserdump;
183
204
boost::mutex _ioMutex;
185
206
/// Stream to write to stdout.
186
std::ofstream _outstream;
207
std::ofstream _outstream;
188
209
/// How much output is required: 2 or more gives debug output.
191
212
/// Whether to dump all SWF actions
215
/// Whether to dump all networking actions
194
218
/// Whether to dump parser output
197
221
/// The state of the log file.
198
222
FileState _state;
202
226
/// Whether to write the log file to disk.
205
229
std::string _filespec;
237
DSOEXPORT void processLog_network(const boost::format& fmt);
238
DSOEXPORT void processLog_error(const boost::format& fmt);
239
DSOEXPORT void processLog_unimpl(const boost::format& fmt);
240
DSOEXPORT void processLog_trace(const boost::format& fmt);
241
DSOEXPORT void processLog_debug(const boost::format& fmt);
242
DSOEXPORT void processLog_action(const boost::format& fmt);
243
DSOEXPORT void processLog_parse(const boost::format& fmt);
244
DSOEXPORT void processLog_security(const boost::format& fmt);
245
DSOEXPORT void processLog_swferror(const boost::format& fmt);
246
DSOEXPORT void processLog_amferror(const boost::format& fmt);
247
DSOEXPORT void processLog_aserror(const boost::format& fmt);
248
DSOEXPORT void processLog_abc(const boost::format& fmt);
213
250
/// This heap of steaming preprocessor code magically converts
214
251
/// printf-style statements into boost::format messages using templates.
225
262
/// This is a sequence of different log message types to be used in
226
263
/// the code. Append the name to log_ to call the function, e.g.
227
264
/// log_error, log_unimpl.
228
#define LOG_TYPES (error) (debug) (unimpl) (aserror) (swferror) (amferror) (security) (action) (parse) (trace)
265
#define LOG_TYPES (error) (debug) (unimpl) (aserror) (swferror) \
266
(amferror) (security) (action) (parse) (trace) (abc) (network)
230
268
/// This actually creates the template functions using the TOKENIZE
231
269
/// functions above. The templates look like this:
233
/// template< typename T0 , typename T1 , typename T2 , typename T3 >
235
/// log_security (const T0& t0, const T1& t1, const T2& t2, const T3& t3)
271
/// template<typename T0 , typename T1 , typename T2>
272
/// void log_error(const T0& t0 , const T1& t1 , const T2& t2)
237
/// if (_verbosity == 0) return;
238
/// processLog_security(myFormat(t0) % t1 % t2 % t3);
274
/// if (LogFile::getDefaultInstance().getVerbosity() == 0) return;
275
/// boost::format f(t0);
276
/// using namespace boost::io;
277
/// f.exceptions(all_error_bits ^ (too_many_args_bit |
278
/// too_few_args_bit |
279
/// bad_format_string_bit));
280
/// processLog_error(f % t1 % t2);
241
283
/// Only not as nicely indented.
243
/// Use "g++ -E log.h" or "gcc log.h" to check.
285
/// Use "g++ -E log.h" or "cpp log.h" to check.
244
286
#define LOG_TEMPLATES(z, n, data)\
246
BOOST_PP_ENUM_PARAMS(\
247
BOOST_PP_INC(n), typename T)\
287
template<BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n), typename T)>\
288
void log_##data(BOOST_PP_REPEAT(BOOST_PP_INC(n), TOKENIZE_ARGS, t)) \
254
290
if (LogFile::getDefaultInstance().getVerbosity() == 0) return; \
255
processLog_##data(logFormat(t0) \
256
BOOST_PP_REPEAT_FROM_TO(1, \
258
TOKENIZE_FORMAT, t));\
291
boost::format f(t0); \
292
using namespace boost::io; \
293
f.exceptions(all_error_bits ^ (too_many_args_bit | \
295
bad_format_string_bit)); \
296
processLog_##data(f BOOST_PP_REPEAT_FROM_TO(1, \
298
TOKENIZE_FORMAT, t));\
261
301
/// Defines the maximum number of template arguments
263
303
/// The preprocessor generates templates with 1..ARG_NUMBER
265
#define ARG_NUMBER 16
305
#define ARG_NUMBER 10
267
307
/// Calls the macro LOG_TEMPLATES an ARG_NUMBER number
268
308
/// of times, each time adding an extra typename argument to the
279
319
#undef LOG_TEMPLATES
280
320
#undef ARG_NUMBER
282
DSOEXPORT void processLog_error(const boost::format& fmt);
283
DSOEXPORT void processLog_unimpl(const boost::format& fmt);
284
DSOEXPORT void processLog_trace(const boost::format& fmt);
285
DSOEXPORT void processLog_debug(const boost::format& fmt);
286
DSOEXPORT void processLog_action(const boost::format& fmt);
287
DSOEXPORT void processLog_parse(const boost::format& fmt);
288
DSOEXPORT void processLog_security(const boost::format& fmt);
289
DSOEXPORT void processLog_swferror(const boost::format& fmt);
290
DSOEXPORT void processLog_amferror(const boost::format& fmt);
291
DSOEXPORT void processLog_aserror(const boost::format& fmt);
293
/// A fault-tolerant boost::format object for logging
295
/// Generally to be used in the LogFile macro BF(), which will also
296
/// be recognized by gettext for internationalization and is less
298
DSOEXPORT boost::format logFormat(const std::string &str);
300
322
/// Convert a sequence of bytes to hex or ascii format.
302
324
/// @param bytes the array of bytes to process
304
326
/// for checking that length does not exceed the array size.
305
327
/// @param ascii whether to return in ascii or space-separated hex format.
306
328
/// @return a string representation of the byte sequence.
307
DSOEXPORT std::string hexify(const unsigned char *bytes, size_t length, bool ascii);
329
DSOEXPORT std::string hexify(const unsigned char *bytes, size_t length,
309
332
// Define to 0 to completely remove parse debugging at compile-time
310
333
#ifndef VERBOSE_PARSE
344
371
#define IF_VERBOSE_ACTION(x)
375
#define IF_VERBOSE_NETWORK(x) do { if ( LogFile::getDefaultInstance().getNetwork() ) { x; } } while (0);
377
#define IF_VERBOSE_NETWORK(x)
347
380
#if VERBOSE_ASCODING_ERRORS
348
381
// TODO: check if it's worth to check verbosity level too...
349
382
#define IF_VERBOSE_ASCODING_ERRORS(x) { if ( gnash::RcInitFile::getDefaultInstance().showASCodingErrors() ) { x; } }