aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneodarz <neodarz@neodarz.net>2020-08-13 08:09:10 +0200
committerneodarz <neodarz@neodarz.net>2020-08-13 08:09:10 +0200
commit9acb4a5135db19d7086bb93cf5ca64f83f0806cb (patch)
tree13f65419fa2a0c58e3a26d2e281cf6ae654a6181
parent1d3775f20177bbe7c1d9afa7c170e78f24f279e4 (diff)
downloadumosapicpp-9acb4a5135db19d7086bb93cf5ca64f83f0806cb.tar.xz
umosapicpp-9acb4a5135db19d7086bb93cf5ca64f83f0806cb.zip
Use an external library for logging
This library has an asynchronous mode who can be useful for speed issues.
Diffstat (limited to '')
-rw-r--r--CMakeLists.txt7
-rw-r--r--README.md1
-rw-r--r--main.cpp19
-rw-r--r--shared.h1
4 files changed, 18 insertions, 10 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3b03a34..8cc6265 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,8 +61,11 @@ or
/usr/local/lib")
endif(NOT RESTBED_FOUND)
+if(NOT TARGET spdlog)
+ find_package(spdlog REQUIRED)
+endif()
-add_executable(umosapi main.cpp config.cpp api/umosapi.cpp db/mongo_access.cpp db/uobject.cpp api/umosapi.h config.h db/mongo_access.h db/uobject.h shared.h)
+add_executable(umosapi main.cpp config.cpp api/umosapi.cpp db/mongo_access.cpp db/uobject.cpp api/umosapi.h config.h db/mongo_access.h db/uobject.h shared.h logging.h)
set_property(TARGET umosapi PROPERTY CXX_STANDARD 17)
@@ -77,3 +80,5 @@ target_link_libraries(umosapi PUBLIC ${JSONC_LIBRARIES})
target_include_directories(umosapi PUBLIC ${RESTBED_INCLUDE_DIRS})
target_link_libraries(umosapi PUBLIC ${RESTBED_LIBRARIES})
+
+target_link_libraries(umosapi PUBLIC spdlog::spdlog)
diff --git a/README.md b/README.md
index 6c8d961..78a0a75 100644
--- a/README.md
+++ b/README.md
@@ -21,6 +21,7 @@ Install:
- json-c
- nlohmann/json
- mongocxx
+- spdlog
### Why two json lib ?
diff --git a/main.cpp b/main.cpp
index 2ca3399..41e56b6 100644
--- a/main.cpp
+++ b/main.cpp
@@ -4,7 +4,9 @@
#include <pwd.h>
#include "clara.hpp"
+
#include "shared.h"
+#include "logging.h"
#include "config.h"
#include "api/umosapi.h"
@@ -43,23 +45,22 @@ int main(int argc, char *argv[]) {
exit(1);
}
- std::cout << "INFO: Using " << std::thread::hardware_concurrency() << " cores";
- std::cout << " - " << thr << " threads" << std::endl;
- std::cout << "INFO: Listen on 0.0.0.0:" << config["port"] << std::endl;
+ spdlog::info("Using {} cores - {} threads", std::thread::hardware_concurrency(), thr);
+ spdlog::info("Listen on 0.0.0.0:{}", config["port"]);
- std::cout << "INFO: Using config file '" << config_path << "'" << std::endl;
+ spdlog::info("Using config file '{}'", config_path);
if (!std::filesystem::exists(config_path)) {
- std::cout << "ERROR: Error fatal : config file '" << config_path << "' not found" << std::endl;
- std::cout << "ERROR: config.txt is search here: ~/.config/umosapi/config.txt" << std::endl;
+ spdlog::error("Error fatal: config file '{}' not found", config_path);
+ spdlog::error("config.txt is searched here: ~/.config/umosapi.config.txt");
exit (EXIT_FAILURE);
}
load_config(config_path);
- std::cout << "Using swaggerui " << config["swaggerui"] << " path" << std::endl;
- std::cout << "INFO: No support for swagger for the moment" << std::endl;
- std::cout << "INFO: Using mongoURI " << config["mongoURI"] << std::endl;
+ spdlog::info("Using swaggerui {} path", config["swaggerui"]);
+ spdlog::warn("No support for swagger for the moment");
+ spdlog::info("Using mongoURI {}", config["mongoURI"]);
UmosapiService::Api umosapi;
umosapi.init();
diff --git a/shared.h b/shared.h
index 5ee3d78..5a485be 100644
--- a/shared.h
+++ b/shared.h
@@ -2,6 +2,7 @@
#define SHARED_H_
#include <map>
+
#include "db/mongo_access.h"
extern std::map<std::string, std::string> config;