diff options
Diffstat (limited to 'liblog')
| -rw-r--r-- | liblog/CMakeLists.txt | 24 | ||||
| -rw-r--r-- | liblog/logging.cpp | 28 | ||||
| -rw-r--r-- | liblog/logging.hpp | 6 |
3 files changed, 58 insertions, 0 deletions
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); + |
