Skip to content

Commit

Permalink
Referenced PPM_LOG_LEVEL in PpmLogger class directly instead of passi…
Browse files Browse the repository at this point in the history
…ng opt string.
  • Loading branch information
dmccoystephenson committed Oct 24, 2023
1 parent 6705ceb commit fb010fa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docker-test/ppm_no_map.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export LD_LIBRARY_PATH=/usr/local/lib

# Start the DI tool.

/cvdi-stream-build/ppm -c /ppm_data/${PPM_CONFIG_FILE} -b ${DOCKER_HOST_IP}:9092 -v ${PPM_LOG_LEVEL} -D ~/logs/
/cvdi-stream-build/ppm -c /ppm_data/${PPM_CONFIG_FILE} -b ${DOCKER_HOST_IP}:9092 -D ~/logs/
22 changes: 0 additions & 22 deletions src/ppm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,27 +243,6 @@ void PPM::print_configuration() const
}

bool PPM::configure() {

if ( optIsSet('v') ) {
if ( "TRACE" == optString('v') ) {
logger->set_level( spdlog::level::trace );
} else if ( "DEBUG" == optString('v') ) {
logger->set_level( spdlog::level::debug );
} else if ( "INFO" == optString('v') ) {
logger->set_level( spdlog::level::info );
} else if ( "WARNING" == optString('v') ) {
logger->set_level( spdlog::level::warn );
} else if ( "ERROR" == optString('v') ) {
logger->set_level( spdlog::level::err );
} else if ( "CRITICAL" == optString('v') ) {
logger->set_level( spdlog::level::critical );
} else if ( "OFF" == optString('v') ) {
logger->set_level( spdlog::level::off );
} else {
logger->warn("information logger level was configured but unreadable; using default.");
}
} // else it is already set to default.

logger->trace("starting configure()");

std::string line;
Expand Down Expand Up @@ -855,7 +834,6 @@ int main( int argc, char* argv[] )
ppm.addOption('x', "exit", "Exit consumer when last message in partition has been received.", false);
ppm.addOption('d', "debug", "debug level.", true);
ppm.addOption('m', "mapfile", "Map data file to specify the geofence.", true);
ppm.addOption('v', "log-level", "The info log level [trace,debug,info,warning,error,critical,off]", true);
ppm.addOption('D', "log-dir", "Directory for the log files.", true);
ppm.addOption('R', "log-rm", "Remove specified/default log files if they exist.", false);
ppm.addOption('i', "log", "Log file name.", true);
Expand Down
20 changes: 20 additions & 0 deletions src/ppmLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,27 @@ PpmLogger::PpmLogger(std::string logname) {
sinks.push_back(std::make_shared<spdlog::sinks::stdout_sink_mt>());
}
setLogger(std::make_shared<spdlog::logger>("log", begin(sinks), end(sinks)));

// use PPM_LOG_LEVEL environment variable to set the log level
std::string logLevelString = getEnvironmentVariable("PPM_LOG_LEVEL");
std::string lowercaseLogLevelString = toLowercase(logLevelString);
if (lowercaseLogLevelString == "trace") {
loglevel = spdlog::level::trace;
} else if (lowercaseLogLevelString == "debug") {
loglevel = spdlog::level::debug;
} else if (lowercaseLogLevelString == "info") {
loglevel = spdlog::level::info;
} else if (lowercaseLogLevelString == "warn") {
loglevel = spdlog::level::warn;
} else if (lowercaseLogLevelString == "error") {
loglevel = spdlog::level::err;
} else if (lowercaseLogLevelString == "critical") {
loglevel = spdlog::level::critical;
} else {
std::cout << "WARNING: PPM_LOG_LEVEL is not set to a valid value. Using default." << std::endl;
}
set_level( loglevel );

set_pattern("[%C%m%d %H:%M:%S.%f] [%l] %v");
}

Expand Down

0 comments on commit fb010fa

Please sign in to comment.