From c796e46bc5abbd955595635766fa3d5a49bcee06 Mon Sep 17 00:00:00 2001 From: Helge Norberg Date: Wed, 16 Dec 2015 15:02:51 +0100 Subject: [PATCH] Separated call trace to separate log file calltrace.log --- common/log.cpp | 9 +++++---- common/log.h | 4 +++- shell/main.cpp | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/log.cpp b/common/log.cpp index d9e5ac898..78957b60a 100644 --- a/common/log.cpp +++ b/common/log.cpp @@ -152,7 +152,7 @@ void init() auto stream_sink = boost::make_shared(stream_backend); // Never log calltrace to console. The terminal is too slow, so the log queue will build up faster than consumed. - stream_sink->set_filter(boost::log::expressions::attr("Channel") != log_category::call); + stream_sink->set_filter(category != log_category::call); bool print_all_characters = false; stream_sink->set_formatter(boost::bind(&my_formatter, print_all_characters, _1, _2)); @@ -162,17 +162,17 @@ void init() } -void add_file_sink(const std::wstring& folder) +void add_file_sink(const std::wstring& file, const boost::log::filter& filter) { typedef boost::log::sinks::synchronous_sink file_sink_type; try { - if (!boost::filesystem::is_directory(folder)) + if (!boost::filesystem::is_directory(boost::filesystem::path(file).parent_path())) CASPAR_THROW_EXCEPTION(directory_not_found()); auto file_sink = boost::make_shared( - boost::log::keywords::file_name = (folder + L"caspar_%Y-%m-%d.log"), + boost::log::keywords::file_name = (file + L"_%Y-%m-%d.log"), boost::log::keywords::time_based_rotation = boost::log::sinks::file::rotation_at_time_point(0, 0, 0), boost::log::keywords::auto_flush = true, boost::log::keywords::open_mode = std::ios::app @@ -181,6 +181,7 @@ void add_file_sink(const std::wstring& folder) bool print_all_characters = true; file_sink->set_formatter(boost::bind(&my_formatter, print_all_characters, _1, _2)); + file_sink->set_filter(filter); boost::log::core::get()->add_sink(file_sink); } catch (...) diff --git a/common/log.h b/common/log.h index e786a8b84..a4415c60f 100644 --- a/common/log.h +++ b/common/log.h @@ -26,6 +26,7 @@ #include "thread_info.h" #include +#include #include #include #include @@ -63,7 +64,7 @@ inline std::basic_string replace_nonprintable_copy(std::basic_string add_preformatted_line_sink(std::function formatted_line_sink); enum class log_category @@ -72,6 +73,7 @@ enum class log_category call, communication }; +BOOST_LOG_ATTRIBUTE_KEYWORD(category, "Channel", ::caspar::log::log_category) typedef boost::log::sources::wseverity_channel_logger_mt caspar_logger; diff --git a/shell/main.cpp b/shell/main.cpp index ffac2a4cd..2d957f21f 100644 --- a/shell/main.cpp +++ b/shell/main.cpp @@ -304,7 +304,8 @@ int main(int argc, char** argv) wait_for_remote_debugging(); // Start logging to file. - log::add_file_sink(env::log_folder()); + log::add_file_sink(env::log_folder() + L"caspar", caspar::log::category != caspar::log::log_category::call); + log::add_file_sink(env::log_folder() + L"calltrace", caspar::log::category == caspar::log::log_category::call); std::wcout << L"Logging [info] or higher severity to " << env::log_folder() << std::endl << std::endl; // Setup console window. -- 2.39.2