How do I change the internal log priority in oat++ to PRIORITY_V?

106 Views Asked by At

How do I change the internal log priority in oat++ to PRIORITY_V?

std::shared_ptr<oatpp::base::Logger> logger = oatpp::base::Environment::getLogger();

I could not find a fucntion to change the priority.

1

There are 1 best solutions below

0
user2518618 On

As @lganzzzo comments, Oat++ does not write many logs itself, but you can control your own logs. Also, these are independent channels: you can enable verbose, and disable debug and information, for example. As far as I see in the code of the DefaultLogger, all logs are enabled by default (including Verbose).

There is an example on how to configure the logs: https://github.com/oatpp/oatpp/blob/master/test/oatpp/core/base/LoggerTest.cpp. In the following excerpt of that example, it takes the default logger and disables the Debug priority, while other priorities (including Verbose) stay enabled):

  auto logger = std::static_pointer_cast<oatpp::base::DefaultLogger>(oatpp::base::Environment::getLogger());

  OATPP_LOGV("LoggerTest", "Verbose Log")
  OATPP_LOGD("LoggerTest", "Debug Log")
  OATPP_LOGI("LoggerTest", "Info Log")
  OATPP_LOGW("LoggerTest", "Warning Log")
  OATPP_LOGE("LoggerTest", "Error Log")

  OATPP_LOGI("LoggerTest", " --- Disabling Debug Log")
  logger->disablePriority(oatpp::base::DefaultLogger::PRIORITY_D);
  OATPP_ASSERT(!logger->isLogPriorityEnabled(oatpp::base::DefaultLogger::PRIORITY_D))

  OATPP_LOGV("LoggerTest", "Verbose Log")
  OATPP_LOGD("LoggerTest", "Debug Log")     //this won't be written
  OATPP_LOGI("LoggerTest", "Info Log")
  OATPP_LOGW("LoggerTest", "Warning Log")
  OATPP_LOGE("LoggerTest", "Error Log")