Skip to content

Commit

Permalink
Sort streams in "-B help" output, and match case-insensitively throug…
Browse files Browse the repository at this point in the history
…hout

Matching of plugins' debug streams was still case-sensitive. Also contains some
minor output tweaks.

It'd be nice to only list plugin debug streams actually _used_ by plugins. I
didn't see a quick way to do that so that's for another time.
  • Loading branch information
ckreibich committed Nov 15, 2024
1 parent b4ddf73 commit f32869a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 20 additions & 11 deletions src/DebugLogger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,30 @@ void DebugLogger::OpenDebugLog(const char* filename) {
}

void DebugLogger::ShowStreamsHelp() {
fprintf(stderr, "\n");
fprintf(stderr, "Enable debug output into debug.log with -B <streams>.\n");
fprintf(stderr, "<streams> is a comma-separated list of streams to enable.\n");
fprintf(stderr, "<streams> is a case-insensitive, comma-separated list of streams to enable:\n");
fprintf(stderr, "\n");
fprintf(stderr, "Available streams:\n");

for ( int i = 0; i < NUM_DBGS; ++i )
fprintf(stderr, " %s\n", streams[i].prefix);
std::vector<std::string> prefixes;

for ( const auto& stream : streams )
prefixes.emplace_back(stream.prefix);
std::sort(prefixes.begin(), prefixes.end());

for ( const auto& prefix : prefixes )
fprintf(stderr, " %s\n", prefix.c_str());

fprintf(stderr, "\n");
fprintf(stderr, "Every plugin (see -N) also has its own debug stream:\n");
fprintf(stderr, "\n");
fprintf(stderr,
" plugin-<plugin-name> (replace '::' in name with '-'; e.g., '-B "
"plugin-Zeek-Netmap')\n");
"plugin-Zeek-JavaScript')\n");
fprintf(stderr, "\n");
fprintf(stderr, "Pseudo streams:\n");
fprintf(stderr, "\n");
fprintf(stderr, "Pseudo streams\n");
fprintf(stderr, " verbose Increase verbosity.\n");
fprintf(stderr, " all Enable all streams at maximum verbosity.\n");
fprintf(stderr, " all Enable all built-in streams at maximum verbosity.\n");
fprintf(stderr, "\n");
}

Expand All @@ -79,6 +86,8 @@ void DebugLogger::EnableStreams(const char* s) {
char* tok = strtok(tmp, ",");

while ( tok ) {
std::string ltok{util::strtolower(tok)};

if ( strcasecmp("all", tok) == 0 ) {
for ( int i = 0; i < NUM_DBGS; ++i ) {
streams[i].enabled = true;
Expand All @@ -99,10 +108,10 @@ void DebugLogger::EnableStreams(const char* s) {
exit(0);
}

if ( util::starts_with(tok, "plugin-") ) {
if ( util::starts_with(ltok, "plugin-") ) {
// Cannot verify this at this time, plugins may not
// have been loaded.
enabled_streams.insert(tok);
enabled_streams.insert(ltok);
goto next;
}

Expand All @@ -111,7 +120,7 @@ void DebugLogger::EnableStreams(const char* s) {
for ( i = 0; i < NUM_DBGS; ++i ) {
if ( strcasecmp(streams[i].prefix, tok) == 0 ) {
streams[i].enabled = true;
enabled_streams.insert(tok);
enabled_streams.insert(ltok);
goto next;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/DebugLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class DebugLogger {
static Stream streams[NUM_DBGS];

const std::string PluginStreamName(const std::string& plugin_name) {
return "plugin-" + util::strreplace(plugin_name, "::", "-");
return "plugin-" + util::strtolower(util::strreplace(plugin_name, "::", "-"));
}
};

Expand Down

0 comments on commit f32869a

Please sign in to comment.