diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-22 16:05:07 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-09-22 16:05:07 +0200 |
| commit | cfae7b4dd30282209debec1d7680be8d974d0e46 (patch) | |
| tree | c8e64797f0cdf74bff367b057826f81b512db624 | |
| parent | f77ce5a0226014c811a46d8ab1ba8c9164768ed3 (diff) | |
| download | cmix-cfae7b4dd30282209debec1d7680be8d974d0e46.tar.gz cmix-cfae7b4dd30282209debec1d7680be8d974d0e46.tar.bz2 cmix-cfae7b4dd30282209debec1d7680be8d974d0e46.zip | |
Added a logging facility using boost::log::trivial.
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | liblog/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | liblog/logging.cpp | 28 | ||||
| -rw-r--r-- | liblog/logging.hpp | 6 | ||||
| -rw-r--r-- | node/CMakeLists.txt | 1 |
5 files changed, 60 insertions, 0 deletions
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 <boost/log/core.hpp> +#include <boost/log/expressions.hpp> +#include <boost/log/sinks/text_file_backend.hpp> +#include <boost/log/utility/setup/file.hpp> +#include <boost/log/utility/setup/common_attributes.hpp> +#include <boost/log/sources/severity_logger.hpp> +#include <boost/log/sources/record_ostream.hpp> + +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 <boost/log/trivial.hpp> + +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 ) |
