From cfae7b4dd30282209debec1d7680be8d974d0e46 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 22 Sep 2016 16:05:07 +0200 Subject: Added a logging facility using boost::log::trivial. --- CMakeLists.txt | 1 + liblog/CMakeLists.txt | 24 ++++++++++++++++++++++++ liblog/logging.cpp | 28 ++++++++++++++++++++++++++++ liblog/logging.hpp | 6 ++++++ node/CMakeLists.txt | 1 + 5 files changed, 60 insertions(+) create mode 100644 liblog/CMakeLists.txt create mode 100644 liblog/logging.cpp create mode 100644 liblog/logging.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0483633..0037310 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,7 @@ endif(DOXYGEN_FOUND) add_subdirectory(libcmix-crypto) add_subdirectory(libcmix) +add_subdirectory(liblog) add_subdirectory(libcmix-network) add_subdirectory(network-handler) diff --git a/liblog/CMakeLists.txt b/liblog/CMakeLists.txt new file mode 100644 index 0000000..cb4ce84 --- /dev/null +++ b/liblog/CMakeLists.txt @@ -0,0 +1,24 @@ +find_package(Boost COMPONENTS log system REQUIRED) +find_package(Threads) + +add_library(log + logging.hpp logging.cpp +) + +target_include_directories(log + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_compile_definitions(log + PUBLIC BOOST_LOG_DYN_LINK +) + +target_compile_options(log + PRIVATE -std=c++11 +) + +target_link_libraries(log + PRIVATE Boost::log + PRIVATE Boost::system + PUBLIC ${CMAKE_THREAD_LIBS_INIT} +) \ No newline at end of file diff --git a/liblog/logging.cpp b/liblog/logging.cpp new file mode 100644 index 0000000..c92247c --- /dev/null +++ b/liblog/logging.cpp @@ -0,0 +1,28 @@ + +#include "logging.hpp" + +#include +#include +#include +#include +#include +#include +#include + +void init_logging(boost::log::trivial::severity_level log_level) +{ + boost::log::add_common_attributes(); + boost::log::register_simple_formatter_factory< boost::log::trivial::severity_level, char >("Severity"); + + boost::log::add_file_log + ( + boost::log::keywords::file_name = "node%N.log", + boost::log::keywords::rotation_size = 10 * 1024 * 1024, + boost::log::keywords::format = "[%Severity%] (%TimeStamp%): %Message%" + ); + + boost::log::core::get()->set_filter + ( + boost::log::trivial::severity >= log_level + ); +} diff --git a/liblog/logging.hpp b/liblog/logging.hpp new file mode 100644 index 0000000..7a4e03e --- /dev/null +++ b/liblog/logging.hpp @@ -0,0 +1,6 @@ +#pragma once + +#include + +void init_logging(boost::log::trivial::severity_level log_level); + diff --git a/node/CMakeLists.txt b/node/CMakeLists.txt index 895cfb2..1c3b771 100644 --- a/node/CMakeLists.txt +++ b/node/CMakeLists.txt @@ -13,6 +13,7 @@ target_link_libraries(node PRIVATE Boost::boost PRIVATE Boost::program_options PRIVATE Boost::system + PRIVATE log PRIVATE cmix PRIVATE cmix-network ) -- cgit v1.2.3-70-g09d2