Add 'log_level' config option

This commit is contained in:
antao 2018-10-06 10:15:46 +08:00
parent 0a0cb2cb76
commit 900cc62306
3 changed files with 22 additions and 2 deletions

View File

@ -59,7 +59,10 @@
"logfile_base_name":"",
//log_size_limit:100000000 bytes by default,
//When the log file size reaches "log_size_limit", the log file will be switched.
"log_size_limit":100000000
"log_size_limit":100000000,
//log_level:"DEBUG" by default,options:"TRACE","DEBUG","INFO","WARN"
//The TRACE level is only valid when built in DEBUG mode.
"log_level":"DEBUG"
},
//run_as_daemon:false by default
"run_as_daemon":false,

View File

@ -108,7 +108,7 @@ int main()
// drogon::HttpAppFramework::instance().addListener("0.0.0.0",4431,true);
//#endif
drogon::HttpAppFramework::instance().setThreadNum(4);
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
// trantor::Logger::setLogLevel(trantor::Logger::TRACE);
//class function
drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle1/{1}/{2}/?p3={3}&p4={4}",&A::handle);
drogon::HttpAppFramework::registerHttpApiMethod("/api/v1/handle11/{1}/{2}/?p3={3}&p4={4}",&A::staticHandle);

View File

@ -63,6 +63,23 @@ static void loadLogSetting(const Json::Value &log)
auto logSize=log.get("log_size_limit",100000000).asUInt64();
HttpAppFramework::instance().setLogPath(logPath,baseName,logSize);
}
auto logLevel=log.get("log_level","DEBUG").asString();
if(logLevel=="TRACE")
{
trantor::Logger::setLogLevel(trantor::Logger::TRACE);
}
else if(logLevel=="DEBUG")
{
trantor::Logger::setLogLevel(trantor::Logger::DEBUG);
}
else if(logLevel=="INFO")
{
trantor::Logger::setLogLevel(trantor::Logger::INFO);
}
else if(logLevel=="WARN")
{
trantor::Logger::setLogLevel(trantor::Logger::WARN);
}
}
static void loadApp(const Json::Value &app)
{