diff --git a/config.json.example b/config.json.example index b6bc1d0e..81c552e9 100644 --- a/config.json.example +++ b/config.json.example @@ -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, diff --git a/examples/simple_example/main.cc b/examples/simple_example/main.cc index a4719a70..32a180b7 100755 --- a/examples/simple_example/main.cc +++ b/examples/simple_example/main.cc @@ -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); diff --git a/lib/src/ConfigLoader.cc b/lib/src/ConfigLoader.cc index 7f7106f2..445c1903 100644 --- a/lib/src/ConfigLoader.cc +++ b/lib/src/ConfigLoader.cc @@ -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) {