[#95] Resolve Log4cplus Error complaining about no appenders on TPM2 Provisioner startup (#101)

This commit is contained in:
apldev3 2019-03-27 18:18:55 -04:00 committed by GitHub
parent 35c63efe19
commit bc717c9241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 16 deletions

View File

@ -18,7 +18,7 @@ namespace log {
class Logger { class Logger {
private: private:
static const char* const kDefaultProvisionerLoggerName; static const char* const kDefaultProvisionerLoggerName;
static const char* const PROP_FILE_LOC; static const char* const kPropFileLocation;
const log4cplus::Logger kLogger; const log4cplus::Logger kLogger;

View File

@ -17,7 +17,7 @@ using hirs::log::Logger;
using hirs::properties::Properties; using hirs::properties::Properties;
const char* const Logger::kDefaultProvisionerLoggerName = "tpm2_provisioner"; const char* const Logger::kDefaultProvisionerLoggerName = "tpm2_provisioner";
const char* const Logger::PROP_FILE_LOC = "/etc/hirs/logging.properties"; const char* const Logger::kPropFileLocation = "/etc/hirs/logging.properties";
static std::once_flag configureRootLoggerOnce; static std::once_flag configureRootLoggerOnce;
@ -36,8 +36,8 @@ Logger::Logger(const string loggerName)
void Logger::setThresholdFromLoggingProperties(log4cplus::Logger logger) { void Logger::setThresholdFromLoggingProperties(log4cplus::Logger logger) {
// if logging.properties exists, attempt to set the // if logging.properties exists, attempt to set the
// appropriate level for the given logger // appropriate level for the given logger
if (fileExists(PROP_FILE_LOC)) { if (fileExists(kPropFileLocation)) {
Properties props(PROP_FILE_LOC); Properties props(kPropFileLocation);
string loggerName = logger.getName(); string loggerName = logger.getName();
string logLevelKey = loggerName + ".level"; string logLevelKey = loggerName + ".level";
@ -45,19 +45,7 @@ void Logger::setThresholdFromLoggingProperties(log4cplus::Logger logger) {
string level = props.get(logLevelKey); string level = props.get(logLevelKey);
int l4cpLevel = log4cplus::getLogLevelManager().fromString(level); int l4cpLevel = log4cplus::getLogLevelManager().fromString(level);
if (l4cpLevel != log4cplus::NOT_SET_LOG_LEVEL) { if (l4cpLevel != log4cplus::NOT_SET_LOG_LEVEL) {
LOG4CPLUS_INFO(
logger,
LOG4CPLUS_TEXT(
"Configuring logger " + loggerName
+ " with level " + level));
logger.setLogLevel(l4cpLevel); logger.setLogLevel(l4cpLevel);
} else {
LOG4CPLUS_INFO(
logger,
LOG4CPLUS_TEXT(
"Unable to configure logger " + loggerName
+ " with level " + level
+ "; no such level found."));
} }
} }
} }