change default config value
This commit is contained in:
parent
efd7bdb54e
commit
ed61b702f6
|
@ -46,6 +46,8 @@ int main(int argc, char* argv[]) {
|
||||||
config.set_num_db_conn((int)config_obj["conn-num"].as_int64());
|
config.set_num_db_conn((int)config_obj["conn-num"].as_int64());
|
||||||
if (config_obj.contains("conn-str"))
|
if (config_obj.contains("conn-str"))
|
||||||
config.set_db_conn_str(config_obj["conn-str"].as_string().c_str());
|
config.set_db_conn_str(config_obj["conn-str"].as_string().c_str());
|
||||||
|
if (config_obj.contains("log-dir"))
|
||||||
|
config.set_log_path(std::string{ config_obj["log-dir"].as_string() });
|
||||||
if (!config_obj.contains("template_root")) {
|
if (!config_obj.contains("template_root")) {
|
||||||
std::cerr << "`template_root` must be specified" << std::endl;
|
std::cerr << "`template_root` must be specified" << std::endl;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
@ -460,6 +460,7 @@ namespace bserv {
|
||||||
ws_routes_{ std::move(ws_routes) } {
|
ws_routes_{ std::move(ws_routes) } {
|
||||||
init_logging(config);
|
init_logging(config);
|
||||||
|
|
||||||
|
if (config.get_db_conn_str() != "") {
|
||||||
// database connection
|
// database connection
|
||||||
try {
|
try {
|
||||||
db_conn_mgr_ = std::make_shared<
|
db_conn_mgr_ = std::make_shared<
|
||||||
|
@ -469,6 +470,7 @@ namespace bserv {
|
||||||
lgfatal << "db connection initialization failed: " << e.what() << std::endl;
|
lgfatal << "db connection initialization failed: " << e.what() << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
session_mgr_ = std::make_shared<memory_session_manager>();
|
session_mgr_ = std::make_shared<memory_session_manager>();
|
||||||
|
|
||||||
std::shared_ptr<server_resources> resources_ptr = std::make_shared<server_resources>();
|
std::shared_ptr<server_resources> resources_ptr = std::make_shared<server_resources>();
|
||||||
|
|
|
@ -19,10 +19,12 @@ namespace bserv {
|
||||||
const int EXPIRY_TIME = 30; // seconds
|
const int EXPIRY_TIME = 30; // seconds
|
||||||
|
|
||||||
const std::size_t LOG_ROTATION_SIZE = 8 * 1024 * 1024;
|
const std::size_t LOG_ROTATION_SIZE = 8 * 1024 * 1024;
|
||||||
const std::string LOG_PATH = "./log/" + NAME;
|
//const std::string LOG_PATH = "./log/" + NAME;
|
||||||
|
const std::string LOG_PATH = "";
|
||||||
|
|
||||||
const int NUM_DB_CONN = 10;
|
const int NUM_DB_CONN = 10;
|
||||||
const std::string DB_CONN_STR = "dbname=bserv";
|
//const std::string DB_CONN_STR = "dbname=bserv";
|
||||||
|
const std::string DB_CONN_STR = "";
|
||||||
|
|
||||||
#define decl_field(type, name, default_value) \
|
#define decl_field(type, name, default_value) \
|
||||||
private: \
|
private: \
|
||||||
|
|
|
@ -31,8 +31,14 @@ namespace bserv {
|
||||||
|
|
||||||
// this function should be called before logging is used
|
// this function should be called before logging is used
|
||||||
inline void init_logging(const server_config& config) {
|
inline void init_logging(const server_config& config) {
|
||||||
|
if (config.get_log_path() != "") {
|
||||||
|
std::string filename = config.get_log_path();
|
||||||
|
if (!filename.ends_with('/')) {
|
||||||
|
filename += '/';
|
||||||
|
}
|
||||||
|
filename += config.get_name();
|
||||||
logging::add_file_log(
|
logging::add_file_log(
|
||||||
keywords::file_name = config.get_log_path() + "_%Y%m%d_%H-%M-%S.%N.log",
|
keywords::file_name = filename + "_%Y%m%d_%H-%M-%S.%N.log",
|
||||||
keywords::rotation_size = config.get_log_rotation_size(),
|
keywords::rotation_size = config.get_log_rotation_size(),
|
||||||
keywords::format = "[%Severity%][%TimeStamp%][%ThreadID%]: %Message%"
|
keywords::format = "[%Severity%][%TimeStamp%][%ThreadID%]: %Message%"
|
||||||
);
|
);
|
||||||
|
@ -40,6 +46,7 @@ namespace bserv {
|
||||||
// write to console as well
|
// write to console as well
|
||||||
logging::add_console_log(std::cout);
|
logging::add_console_log(std::cout);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
logging::core::get()->set_filter(
|
logging::core::get()->set_filter(
|
||||||
#if defined(_MSC_VER) && defined(_DEBUG)
|
#if defined(_MSC_VER) && defined(_DEBUG)
|
||||||
logging::trivial::severity >= logging::trivial::trace
|
logging::trivial::severity >= logging::trivial::trace
|
||||||
|
|
|
@ -4,5 +4,6 @@
|
||||||
"conn-num": 4,
|
"conn-num": 4,
|
||||||
"conn-str": "postgresql://[username]:[password]@[url]:[port]/[db]",
|
"conn-str": "postgresql://[username]:[password]@[url]:[port]/[db]",
|
||||||
"static_root": "../../templates/statics",
|
"static_root": "../../templates/statics",
|
||||||
"template_root": "../../templates"
|
"template_root": "../../templates",
|
||||||
|
"log-dir": "./log"
|
||||||
}
|
}
|
|
@ -4,5 +4,6 @@
|
||||||
"conn-num": 4,
|
"conn-num": 4,
|
||||||
"conn-str": "postgresql://[username]:[password]@[url]:[port]/[db]",
|
"conn-str": "postgresql://[username]:[password]@[url]:[port]/[db]",
|
||||||
"static_root": "../../../templates/statics",
|
"static_root": "../../../templates/statics",
|
||||||
"template_root": "../../../templates"
|
"template_root": "../../../templates",
|
||||||
|
"log-dir": "./log"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue