Skip to content

Commit

Permalink
Merge pull request #36 from dynatrace-oss/trace_log_level_restored
Browse files Browse the repository at this point in the history
Restored option for trace logs
  • Loading branch information
pawsten authored Nov 20, 2024
2 parents 849bd57 + 407d7d8 commit 3578c9f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions nettracersrv/nettracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ po::variables_map parseOptions(int argc, char* argv[]) {
// clang-format off
desc.add_options()
("clear_probes,c", "Clear all probes on start")
("debug,d", "Enable debug logs")
("debug,d", po::value<std::string>()->default_value("info"), "Enable debug logs")
("no_stdout_log,n", "Disable logging to stdout, print metrics data in tabular format")
("log,l", po::value<std::string>()->default_value(""), "Logger path")
("time_interval,t", po::value<unsigned>()->default_value(30), "Time interval of printing metrics data")
Expand Down Expand Up @@ -104,7 +104,7 @@ bool setUpBPFConfig(const po::variables_map& vm, bpf::bpf_subsystem& ebpf, bpf::
nettracer_config_t config{};
(void)mapsWrapper.lookupElement(configFd, &zero, &config);

config.log_level = areDebugLogsEnabled(vm) ? BPF_LOG_LEVEL_DEBUG : BPF_LOG_LEVEL_INFO;
config.log_level = loglevelFromConfig(vm) <= spdlog::level::debug ? BPF_LOG_LEVEL_DEBUG : BPF_LOG_LEVEL_INFO;

if (!mapsWrapper.updateElement(configFd, &zero, &config)) {
LOG_ERROR("Could not set up BPF config");
Expand Down
17 changes: 14 additions & 3 deletions nettracersrv/unified_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,26 @@
#include <string>
#include <utility>

spdlog::level::level_enum loglevelFromConfig(const boost::program_options::variables_map& vm) {
std::string level = vm["debug"].as<std::string>();
if (level == "debug") {
return spdlog::level::debug;
} else if (level == "trace") {
return spdlog::level::trace;
} else {
return spdlog::level::info;
}
}

bool setUpLogging(const boost::program_options::variables_map& vm) {
std::string logger_path = vm["log"].as<std::string>();
bool noStdoutLog = vm.count("no_stdout_log");
bool noFileLog = logger_path.empty();

logging::setUpLogger(logger_path, !noStdoutLog);
if (areDebugLogsEnabled(vm)) {
logging::getLogger()->set_level(spdlog::level::debug);
}
auto level = loglevelFromConfig(vm);
logging::getLogger()->set_level(level);


return noStdoutLog;
}
Expand Down
6 changes: 1 addition & 5 deletions nettracersrv/unified_log.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
#include "bpf_program/nettracer-bpf.h"
#include <boost/program_options.hpp>

inline bool areDebugLogsEnabled(const boost::program_options::variables_map& vm) {
return vm.count("debug");
}

spdlog::level::level_enum loglevelFromConfig(const boost::program_options::variables_map& vm);
bool setUpLogging(const boost::program_options::variables_map& vm);

spdlog::level::level_enum bpfLogLevelToSpdlogLevel(const bpf_log_level& level);
void unifyBPFLog(const bpf_log_event_t& evt);

0 comments on commit 3578c9f

Please sign in to comment.