mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00

These are non-functional changes. * accounting * activation * actual * added * addresult * aggregable * aligned * alternatively * ambiguous * analysis * analyzer * anticlimactic * apparently * application * appropriate * arithmetic * assignment * assigns * associated * authentication * authoritative * barrier * boundary * broccoli * buffering * caching * called * canonicalized * capturing * certificates * ciphersuite * columns * communication * comparison * comparisons * compilation * component * concatenating * concatenation * connection * convenience * correctly * corresponding * could * counting * data * declared * decryption * defining * dependent * deprecated * detached * dictionary * directional * directly * directory * discarding * disconnecting * distinguishes * documentation * elsewhere * emitted * empty * endianness * endpoint * enumerator * essentially * evaluated * everything * exactly * execute * explicit * expressions * facilitates * fiddling * filesystem * flag * flagged * for * fragments * guarantee * guaranteed * happen * happening * hemisphere * identifier * identifies * identify * implementation * implemented * implementing * including * inconsistency * indeterminate * indices * individual * information * initial * initialization * initialize * initialized * initializes * instantiate * instantiated * instantiates * interface * internal * interpreted * interpreter * into * it * iterators * length * likely * log * longer * mainly * mark * maximum * message * minimum * module * must * name * namespace * necessary * nonexistent * not * notifications * notifier * number * objects * occurred * operations * original * otherwise * output * overridden * override * overriding * overwriting * ownership * parameters * particular * payload * persistent * potential * precision * preexisting * preservation * preserved * primarily * probably * procedure * proceed * process * processed * processes * processing * propagate * propagated * prototype * provides * publishing * purposes * queue * reached * reason * reassem * reassemble * reassembler * recommend * record * reduction * reference * regularly * representation * request * reserved * retrieve * returning * separate * should * shouldn't * significant * signing * simplified * simultaneously * single * somebody * sources * specific * specification * specified * specifies * specify * statement * subdirectories * succeeded * successful * successfully * supplied * synchronization * tag * temporarily * terminating * that * the * transmitted * true * truncated * try * understand * unescaped * unforwarding * unknown * unknowndata * unspecified * update * usually * which * wildcard Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
131 lines
3.5 KiB
C++
131 lines
3.5 KiB
C++
// A logger for (selective) debugging output. Only compiled in if DEBUG is
|
|
// defined.
|
|
|
|
#pragma once
|
|
|
|
#ifdef DEBUG
|
|
|
|
#include "zeek/zeek-config.h"
|
|
|
|
#include <stdio.h>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
#include "zeek/util.h"
|
|
|
|
#define DBG_LOG(stream, args...) \
|
|
if ( ::zeek::detail::debug_logger.IsEnabled(stream) ) \
|
|
::zeek::detail::debug_logger.Log(stream, args)
|
|
#define DBG_LOG_VERBOSE(stream, args...) \
|
|
if ( ::zeek::detail::debug_logger.IsVerbose() && \
|
|
::zeek::detail::debug_logger.IsEnabled(stream) ) \
|
|
::zeek::detail::debug_logger.Log(stream, args)
|
|
#define DBG_PUSH(stream) ::zeek::detail::debug_logger.PushIndent(stream)
|
|
#define DBG_POP(stream) ::zeek::detail::debug_logger.PopIndent(stream)
|
|
|
|
#define PLUGIN_DBG_LOG(plugin, args...) ::zeek::detail::debug_logger.Log(plugin, args)
|
|
|
|
namespace zeek
|
|
{
|
|
|
|
namespace plugin
|
|
{
|
|
class Plugin;
|
|
}
|
|
|
|
// To add a new debugging stream, add a constant here as well as
|
|
// an entry to DebugLogger::streams in DebugLogger.cc.
|
|
|
|
enum DebugStream
|
|
{
|
|
DBG_SERIAL, // Serialization
|
|
DBG_RULES, // Signature matching
|
|
DBG_STRING, // String code
|
|
DBG_NOTIFIERS, // Notifiers
|
|
DBG_MAINLOOP, // Main IOSource loop
|
|
DBG_ANALYZER, // Analyzer framework
|
|
DBG_PACKET_ANALYSIS, // Packet analysis
|
|
DBG_FILE_ANALYSIS, // File analysis
|
|
DBG_TM, // Time-machine packet input via Broccoli
|
|
DBG_LOGGING, // Logging streams
|
|
DBG_INPUT, // Input streams
|
|
DBG_THREADING, // Threading system
|
|
DBG_PLUGINS, // Plugin system
|
|
DBG_ZEEKYGEN, // Zeekygen
|
|
DBG_PKTIO, // Packet sources and dumpers.
|
|
DBG_BROKER, // Broker communication
|
|
DBG_SCRIPTS, // Script initialization
|
|
DBG_SUPERVISOR, // Process supervisor
|
|
DBG_HASHKEY, // HashKey buffers
|
|
|
|
NUM_DBGS // Has to be last
|
|
};
|
|
|
|
namespace detail
|
|
{
|
|
|
|
class DebugLogger
|
|
{
|
|
public:
|
|
// Output goes to stderr per default.
|
|
DebugLogger();
|
|
~DebugLogger();
|
|
|
|
void OpenDebugLog(const char* filename = 0);
|
|
|
|
void Log(DebugStream stream, const char* fmt, ...) __attribute__((format(printf, 3, 4)));
|
|
void Log(const plugin::Plugin& plugin, const char* fmt, ...)
|
|
__attribute__((format(printf, 3, 4)));
|
|
|
|
void PushIndent(DebugStream stream) { ++streams[int(stream)].indent; }
|
|
void PopIndent(DebugStream stream) { --streams[int(stream)].indent; }
|
|
|
|
void EnableStream(DebugStream stream) { streams[int(stream)].enabled = true; }
|
|
void DisableStream(DebugStream stream) { streams[int(stream)].enabled = false; }
|
|
|
|
// Takes comma-separated list of stream prefixes.
|
|
void EnableStreams(const char* streams);
|
|
|
|
// Check the enabled streams for invalid ones.
|
|
bool CheckStreams(const std::set<std::string>& plugin_names);
|
|
|
|
bool IsEnabled(DebugStream stream) const { return streams[int(stream)].enabled; }
|
|
|
|
void SetVerbose(bool arg_verbose) { verbose = arg_verbose; }
|
|
bool IsVerbose() const { return verbose; }
|
|
|
|
void ShowStreamsHelp();
|
|
|
|
private:
|
|
FILE* file;
|
|
bool verbose;
|
|
|
|
struct Stream
|
|
{
|
|
const char* prefix;
|
|
int indent;
|
|
bool enabled;
|
|
};
|
|
|
|
std::set<std::string> enabled_streams;
|
|
|
|
static Stream streams[NUM_DBGS];
|
|
|
|
const std::string PluginStreamName(const std::string& plugin_name)
|
|
{
|
|
return "plugin-" + util::strreplace(plugin_name, "::", "-");
|
|
}
|
|
};
|
|
|
|
extern DebugLogger debug_logger;
|
|
|
|
} // namespace detail
|
|
} // namespace zeek
|
|
|
|
#else
|
|
#define DBG_LOG(args...)
|
|
#define DBG_LOG_VERBOSE(args...)
|
|
#define DBG_PUSH(stream)
|
|
#define DBG_POP(stream)
|
|
#define PLUGIN_DBG_LOG(plugin, args...)
|
|
#endif
|