mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Make debug stream names use "-", and handle "_" transparently
This looks consistent, and doesn't break any existing uses with underscores.
This commit is contained in:
parent
7563af4906
commit
b1e0e26484
3 changed files with 21 additions and 6 deletions
|
@ -16,7 +16,7 @@ namespace zeek::detail {
|
||||||
// Same order here as in DebugStream.
|
// Same order here as in DebugStream.
|
||||||
DebugLogger::Stream DebugLogger::streams[NUM_DBGS] =
|
DebugLogger::Stream DebugLogger::streams[NUM_DBGS] =
|
||||||
{{"serial", 0, false}, {"rules", 0, false}, {"string", 0, false}, {"notifiers", 0, false},
|
{{"serial", 0, false}, {"rules", 0, false}, {"string", 0, false}, {"notifiers", 0, false},
|
||||||
{"main-loop", 0, false}, {"dpd", 0, false}, {"packet_analysis", 0, false}, {"file_analysis", 0, false},
|
{"main-loop", 0, false}, {"dpd", 0, false}, {"packet-analysis", 0, false}, {"file-analysis", 0, false},
|
||||||
{"tm", 0, false}, {"logging", 0, false}, {"input", 0, false}, {"threading", 0, false},
|
{"tm", 0, false}, {"logging", 0, false}, {"input", 0, false}, {"threading", 0, false},
|
||||||
{"plugins", 0, false}, {"zeekygen", 0, false}, {"pktio", 0, false}, {"broker", 0, false},
|
{"plugins", 0, false}, {"zeekygen", 0, false}, {"pktio", 0, false}, {"broker", 0, false},
|
||||||
{"scripts", 0, false}, {"supervisor", 0, false}, {"hashkey", 0, false}, {"spicy", 0, false}};
|
{"scripts", 0, false}, {"supervisor", 0, false}, {"hashkey", 0, false}, {"spicy", 0, false}};
|
||||||
|
@ -81,7 +81,10 @@ void DebugLogger::EnableStreams(const char* s) {
|
||||||
char* tok = strtok(tmp, ",");
|
char* tok = strtok(tmp, ",");
|
||||||
|
|
||||||
while ( tok ) {
|
while ( tok ) {
|
||||||
std::string ltok{util::strtolower(tok)};
|
// This maps "_" to "-" for backward compatibility and ease of use: we
|
||||||
|
// used to have underscores in some stream names, and several plugins
|
||||||
|
// do as well.
|
||||||
|
std::string ltok{util::strreplace(util::strtolower(tok), "_", "-")};
|
||||||
|
|
||||||
if ( strcasecmp("all", tok) == 0 ) {
|
if ( strcasecmp("all", tok) == 0 ) {
|
||||||
for ( int i = 0; i < NUM_DBGS; ++i ) {
|
for ( int i = 0; i < NUM_DBGS; ++i ) {
|
||||||
|
@ -114,7 +117,7 @@ void DebugLogger::EnableStreams(const char* s) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for ( i = 0; i < NUM_DBGS; ++i ) {
|
for ( i = 0; i < NUM_DBGS; ++i ) {
|
||||||
if ( strcasecmp(streams[i].prefix, tok) == 0 ) {
|
if ( ltok == streams[i].prefix ) {
|
||||||
streams[i].enabled = true;
|
streams[i].enabled = true;
|
||||||
enabled_streams.insert(ltok);
|
enabled_streams.insert(ltok);
|
||||||
goto next;
|
goto next;
|
||||||
|
@ -189,6 +192,12 @@ void DebugLogger::Log(const plugin::Plugin& plugin, const char* fmt, ...) {
|
||||||
fflush(file);
|
fflush(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string DebugLogger::PluginStreamName(const std::string& plugin_name) const {
|
||||||
|
std::string res{util::strreplace(plugin_name, "::", "-")};
|
||||||
|
res = util::strreplace(res, "_", "-");
|
||||||
|
return "plugin-" + util::strtolower(res);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace zeek::detail
|
} // namespace zeek::detail
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -108,9 +108,9 @@ private:
|
||||||
|
|
||||||
static Stream streams[NUM_DBGS];
|
static Stream streams[NUM_DBGS];
|
||||||
|
|
||||||
const std::string PluginStreamName(const std::string& plugin_name) {
|
// Canonical rendering of a plugin's name. This is lower-cased,
|
||||||
return "plugin-" + util::strtolower(util::strreplace(plugin_name, "::", "-"));
|
// with "::" and "_" both becoming "-".
|
||||||
}
|
const std::string PluginStreamName(const std::string& plugin_name) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern DebugLogger debug_logger;
|
extern DebugLogger debug_logger;
|
||||||
|
|
|
@ -2,7 +2,13 @@
|
||||||
# @TEST-REQUIRES: test "$($BUILD/zeek-config --build_type)" = "debug"
|
# @TEST-REQUIRES: test "$($BUILD/zeek-config --build_type)" = "debug"
|
||||||
|
|
||||||
# @TEST-EXEC: zeek -B plugin-Zeek-HTTP -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
# @TEST-EXEC: zeek -B plugin-Zeek-HTTP -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
|
||||||
|
# Variations on case that should all work:
|
||||||
# @TEST-EXEC: zeek -B PLUGIN-zeek-http -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
# @TEST-EXEC: zeek -B PLUGIN-zeek-http -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
# @TEST-EXEC: zeek -B plugin-zeek-TCP_PKT -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
# @TEST-EXEC: zeek -B plugin-zeek-tcp-pkt -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
|
||||||
|
# A plugin that really does not exist:
|
||||||
# @TEST-EXEC-FAIL: zeek -B plugin-notaplugin -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
# @TEST-EXEC-FAIL: zeek -B plugin-notaplugin -e 'event zeek_init() { print "zeek_init"; }' 2>zeek.stderr
|
||||||
|
|
||||||
# @TEST-EXEC: btest-diff zeek.stderr
|
# @TEST-EXEC: btest-diff zeek.stderr
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue