/usr/include/gnash/log.h is in gnash-dev 0.8.11~git20160109-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | //
// Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
// Free Software Foundation, Inc
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef GNASH_LOG_H
#define GNASH_LOG_H
#ifdef HAVE_CONFIG_H
#include "gnashconfig.h"
#endif
#include "rc.h" // for IF_VERBOSE_* implementation
#include "dsodefs.h" // for DSOEXPORT
#include <fstream>
#include <mutex>
#include <boost/format.hpp>
// This is needed so we can print to the Android log file, which can
// be retrieved with logcat.
#ifdef __ANDROID__
#include <android/log.h>
#endif
// the default name for the debug log
#define DEFAULT_LOGFILE "gnash-dbg.log"
// Support compilation with (or without) native language support
#include "gettext.h"
#define _(String) gettext (String)
#define N_(String) gettext_noop (String)
// Macro to prevent repeated logging calls for the same
// event
#define LOG_ONCE(x) { \
static bool warned = false; \
if (!warned) { warned = true; x; } \
}
// Mingw32 (win32 console) doesn't use the standard GCC defines that
// Gnash used for debug messages, so make it so...
#ifndef __FUNCDNAME__
#define __FUNCDNAME__ __FUNCTION__
#endif
namespace gnash {
// This is a basic file logging class
class DSOEXPORT LogFile
{
public:
static LogFile& getDefaultInstance();
~LogFile();
enum LogLevel {
LOG_SILENT,
LOG_NORMAL,
LOG_DEBUG,
LOG_EXTRA
};
enum FileState {
CLOSED,
OPEN,
INPROGRESS,
IDLE
};
/// Intended for use by log_*(). Thread-safe (locks _ioMutex)
//
/// @param label
/// The label string ie: "ERROR" for "ERROR: <msg>"
///
/// @param msg
/// The message string ie: "bah" for "ERROR: bah"
///
void log(const std::string& label, const std::string& msg);
/// Intended for use by log_*(). Thread-safe (locks _ioMutex)
//
/// @param msg
/// The message to print
///
void log(const std::string& msg);
/// Remove the log file
//
/// Does NOT lock _ioMutex (should it?)
///
bool removeLog();
/// Close the log file
//
/// Locks _ioMutex to prevent race conditions accessing _outstream
///
bool closeLog();
/// Set log filename
//
/// If a log file is opened already, it will be closed
/// by this call, and will be reopened on next use
/// if needed.
///
void setLogFilename(const std::string& fname);
// accessors for the verbose level
void setVerbosity() {
++_verbose;
}
void setVerbosity(int x) {
_verbose = x;
}
int getVerbosity() const {
return _verbose;
}
void setActionDump(int x) {
_actiondump = x;
}
void setNetwork(int x) {
_network = x;
}
int getActionDump() const {
return _actiondump;
}
int getNetwork() const {
return _network;
}
void setParserDump (int x) {
_parserdump = x;
}
int getParserDump() const {
return _parserdump;
}
void setStamp (bool b) {
_stamp = b;
}
bool getStamp() const {
return _stamp;
}
/// Set whether to write logs to file
void setWriteDisk(bool b);
bool getWriteDisk() const {
return _write;
}
typedef void (*logListener)(const std::string& s);
void registerLogCallback(logListener l) { _listener = l; }
private:
/// Open the specified file to write logs on disk
//
/// Locks _ioMutex to prevent race conditions accessing _outstream
///
/// @return true on success, false on failure
///
bool openLog(const std::string& filespec);
/// \brief
/// Open the RcInitFile-specified log file if log write
/// is requested.
//
/// This method is called before any attempt to write is made.
/// It will return true if the file was opened, false if wasn't
/// (either not requested or error).
///
/// On error, will print a message on stderr
///
bool openLogIfNeeded();
// Use getDefaultInstance for getting the singleton
LogFile ();
/// Mutex for locking I/O during logfile access.
std::mutex _ioMutex;
/// Stream to write to stdout.
std::ofstream _outstream;
/// How much output is required: 2 or more gives debug output.
int _verbose;
/// Whether to dump all SWF actions
bool _actiondump;
/// Whether to dump all networking actions
bool _network;
/// Whether to dump parser output
bool _parserdump;
/// The state of the log file.
FileState _state;
bool _stamp;
/// Whether to write the log file to disk.
bool _write;
std::string _filespec;
std::string _logFilename;
logListener _listener;
};
DSOEXPORT void processLog_network(const boost::format& fmt);
DSOEXPORT void processLog_error(const boost::format& fmt);
DSOEXPORT void processLog_unimpl(const boost::format& fmt);
DSOEXPORT void processLog_trace(const boost::format& fmt);
DSOEXPORT void processLog_debug(const boost::format& fmt);
DSOEXPORT void processLog_action(const boost::format& fmt);
DSOEXPORT void processLog_parse(const boost::format& fmt);
DSOEXPORT void processLog_security(const boost::format& fmt);
DSOEXPORT void processLog_swferror(const boost::format& fmt);
DSOEXPORT void processLog_aserror(const boost::format& fmt);
DSOEXPORT void processLog_abc(const boost::format& fmt);
template <typename FuncType>
inline void
log_impl(boost::format& fmt, FuncType func)
{
func(fmt);
}
template<typename FuncType, typename Arg, typename... Args>
inline void
log_impl(boost::format& fmt, FuncType processFunc, Arg arg, Args... args)
{
fmt % arg;
log_impl(fmt, processFunc, args...);
}
template<typename StringType, typename FuncType, typename... Args>
inline void
log_impl(StringType msg, FuncType func, Args... args)
{
boost::format fmt(msg);
using namespace boost::io;
fmt.exceptions(all_error_bits ^ (too_many_args_bit |
too_few_args_bit |
bad_format_string_bit));
log_impl(fmt, func, args...);
}
template<typename StringType, typename... Args>
inline void log_network(StringType msg, Args... args)
{
log_impl(msg, processLog_network, args...);
}
template<typename StringType, typename... Args>
inline void log_error(StringType msg, Args... args)
{
log_impl(msg, processLog_error, args...);
}
template<typename StringType, typename... Args>
inline void log_unimpl(StringType msg, Args... args)
{
log_impl(msg, processLog_unimpl, args...);
}
template<typename StringType, typename... Args>
inline void log_trace(StringType msg, Args... args)
{
log_impl(msg, processLog_trace, args...);
}
template<typename StringType, typename... Args>
inline void log_debug(StringType msg, Args... args)
{
log_impl(msg, processLog_debug, args...);
}
template<typename StringType, typename... Args>
inline void log_action(StringType msg, Args... args)
{
log_impl(msg, processLog_action, args...);
}
template<typename StringType, typename... Args>
inline void log_parse(StringType msg, Args... args)
{
log_impl(msg, processLog_parse, args...);
}
template<typename StringType, typename... Args>
inline void log_security(StringType msg, Args... args)
{
log_impl(msg, processLog_security, args...);
}
template<typename StringType, typename... Args>
inline void log_swferror(StringType msg, Args... args)
{
log_impl(msg, processLog_swferror, args...);
}
template<typename StringType, typename... Args>
inline void log_aserror(StringType msg, Args... args)
{
log_impl(msg, processLog_aserror, args...);
}
template<typename StringType, typename... Args>
inline void log_abc(StringType msg, Args... args)
{
log_impl(msg, processLog_abc, args...);
}
/// Convert a sequence of bytes to hex or ascii format.
//
/// @param bytes the array of bytes to process
/// @param length the number of bytes to read. Callers are responsible
/// for checking that length does not exceed the array size.
/// @param ascii whether to return in ascii or space-separated hex format.
/// @return a string representation of the byte sequence.
DSOEXPORT std::string hexify(const unsigned char *bytes, size_t length,
bool ascii);
// Define to 0 to completely remove parse debugging at compile-time
#ifndef VERBOSE_PARSE
#define VERBOSE_PARSE 1
#endif
// Define to 0 to completely remove action debugging at compile-time
#ifndef VERBOSE_ACTION
#define VERBOSE_ACTION 1
#endif
// Define to 0 to remove ActionScript errors verbosity at compile-time
#ifndef VERBOSE_ASCODING_ERRORS
#define VERBOSE_ASCODING_ERRORS 1
#endif
// Define to 0 this to remove invalid SWF verbosity at compile-time
#ifndef VERBOSE_MALFORMED_SWF
#define VERBOSE_MALFORMED_SWF 1
#endif
// Define to 0 this to remove Networking verbosity at compile-time
#ifndef VERBOSE_NETWORKING
#define VERBOSE_NETWORKING 1
#endif
#if VERBOSE_PARSE
#define IF_VERBOSE_PARSE(x) do { if ( LogFile::getDefaultInstance().getParserDump() ) { x; } } while (0);
#else
#define IF_VERBOSE_PARSE(x)
#endif
#if VERBOSE_ACTION
#define IF_VERBOSE_ACTION(x) do { if ( LogFile::getDefaultInstance().getActionDump() ) { x; } } while (0);
#else
#define IF_VERBOSE_ACTION(x)
#endif
#if VERBOSE_ACTION
#define IF_VERBOSE_NETWORK(x) do { if ( LogFile::getDefaultInstance().getNetwork() ) { x; } } while (0);
#else
#define IF_VERBOSE_NETWORK(x)
#endif
#if VERBOSE_ASCODING_ERRORS
// TODO: check if it's worth to check verbosity level too...
#define IF_VERBOSE_ASCODING_ERRORS(x) { if ( gnash::RcInitFile::getDefaultInstance().showASCodingErrors() ) { x; } }
#else
#define IF_VERBOSE_ASCODING_ERRORS(x)
#endif
#if VERBOSE_MALFORMED_SWF
// TODO: check if it's worth to check verbosity level too...
#define IF_VERBOSE_MALFORMED_SWF(x) { if ( gnash::RcInitFile::getDefaultInstance().showMalformedSWFErrors() ) { x; } }
#else
#define IF_VERBOSE_MALFORMED_SWF(x)
#endif
class DSOEXPORT HostFunctionReport
{
public:
// Only print function tracing messages when multiple -v
// options have been supplied.
HostFunctionReport() : _func(nullptr) {
log_debug("entering");
}
HostFunctionReport(const char* func) : _func(func) {
if (func) {
log_debug("%s enter", func);
}
else {
log_debug("No Function Name! enter");
}
}
~HostFunctionReport() {
log_debug("%s returning", _func);
}
private:
const char* _func;
};
#ifndef HAVE_FUNCTION
#ifndef HAVE_func
#define dummystr(x) # x
#define dummyestr(x) dummystr(x)
#define __FUNCTION__ __FILE__ ":" dummyestr(__LINE__)
#else
#define __FUNCTION__ __func__
#endif
#endif
#ifndef HAVE_PRETTY_FUNCTION
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif
#if defined(__cplusplus) && defined(__GNUC__)
#define GNASH_REPORT_FUNCTION \
const gnash::HostFunctionReport hfr(__PRETTY_FUNCTION__)
#define GNASH_REPORT_RETURN
#else
#define GNASH_REPORT_FUNCTION \
gnash::log_debug("entering")
#define GNASH_REPORT_RETURN \
gnash::log_debug("returning")
#endif
}
#endif // GNASH_LOG_H
// Local Variables:
// mode: C++
// indent-tabs-mode: nil
// End:
|