X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=common%2Flog%2Flog.cpp;h=6b77a9c13c030d17f3076d4261d2bbce28507cd8;hb=a6f5b702bc78bee88f41480ac558e8a0b0c9f111;hp=802eb93492de3440298253e8a89100e49aa7fd4c;hpb=a75b4ede98fc2caa969f549ef72e98d078e56ba4;p=casparcg diff --git a/common/log/log.cpp b/common/log/log.cpp index 802eb9349..6b77a9c13 100644 --- a/common/log/log.cpp +++ b/common/log/log.cpp @@ -1,24 +1,23 @@ /* -* copyright (c) 2010 Sveriges Television AB +* Copyright (c) 2011 Sveriges Television AB * -* This file is part of CasparCG. +* This file is part of CasparCG (www.casparcg.com). * -* CasparCG is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. +* CasparCG is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. * -* CasparCG is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. - -* You should have received a copy of the GNU General Public License -* along with CasparCG. If not, see . +* CasparCG is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with CasparCG. If not, see . * +* Author: Robert Nagy, ronag89@gmail.com */ -// TODO: Colors in console. -// TODO: Think through filters. #include "../stdafx.h" @@ -32,7 +31,6 @@ #include "../exception/exceptions.h" #include "../utility/string.h" #include -#include #include #include @@ -66,10 +64,8 @@ #include namespace caspar { namespace log { - -using namespace boost; - -void my_formatter(std::wostream& strm, boost::log::basic_record const& rec) + +void my_formatter(std::ostream& strm, boost::log::basic_record const& rec) { namespace lambda = boost::lambda; @@ -80,15 +76,15 @@ void my_formatter(std::wostream& strm, boost::log::basic_record const& timeinfo = localtime ( &rawtime ); char buffer [80]; strftime (buffer,80, "%c", timeinfo); - strm << L"[" << buffer << L"] "; + strm << "[" << buffer << "] "; boost::log::attributes::current_thread_id::held_type thread_id; - if(boost::log::extract(L"ThreadID", rec.attribute_values(), lambda::var(thread_id) = lambda::_1)) - strm << L"[" << thread_id << L"] "; + if(boost::log::extract("ThreadID", rec.attribute_values(), lambda::var(thread_id) = lambda::_1)) + strm << "[" << thread_id << "] "; severity_level severity; - if(boost::log::extract(boost::log::sources::aux::severity_attribute_name::get(), rec.attribute_values(), lambda::var(severity) = lambda::_1)) - strm << L"[" << severity << L"] "; + if(boost::log::extract(boost::log::sources::aux::severity_attribute_name::get(), rec.attribute_values(), lambda::var(severity) = lambda::_1)) + strm << "[" << severity << "] "; strm << rec.message(); } @@ -97,38 +93,38 @@ namespace internal{ void init() { - boost::log::add_common_attributes(); - typedef boost::log::aux::add_common_attributes_constants traits_t; + boost::log::add_common_attributes(); + typedef boost::log::aux::add_common_attributes_constants traits_t; - typedef boost::log::sinks::synchronous_sink file_sink_type; + typedef boost::log::sinks::synchronous_sink file_sink_type; - typedef boost::log::sinks::asynchronous_sink stream_sink_type; + typedef boost::log::sinks::asynchronous_sink stream_sink_type; - auto stream_backend = boost::make_shared(); - stream_backend->add_stream(boost::shared_ptr(&std::wcout, boost::log::empty_deleter())); + auto stream_backend = boost::make_shared(); + stream_backend->add_stream(boost::shared_ptr(&std::cout, boost::log::empty_deleter())); stream_backend->auto_flush(true); auto stream_sink = boost::make_shared(stream_backend); -#ifdef NDEBUG - stream_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= trace); -#else - stream_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= trace); -#endif +//#ifdef NDEBUG +// stream_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); +//#else +// stream_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); +//#endif stream_sink->locked_backend()->set_formatter(&my_formatter); - boost::log::wcore::get()->add_sink(stream_sink); + boost::log::core::get()->add_sink(stream_sink); } } -void add_file_sink(const std::wstring& folder) +void add_file_sink(const ustring& folder) { - boost::log::add_common_attributes(); - typedef boost::log::aux::add_common_attributes_constants traits_t; + boost::log::add_common_attributes(); + typedef boost::log::aux::add_common_attributes_constants traits_t; - typedef boost::log::sinks::synchronous_sink file_sink_type; + typedef boost::log::sinks::synchronous_sink file_sink_type; try { @@ -136,42 +132,42 @@ void add_file_sink(const std::wstring& folder) BOOST_THROW_EXCEPTION(directory_not_found()); auto file_sink = boost::make_shared( - boost::log::keywords::file_name = (folder + L"caspar_%Y-%m-%d_%H-%M-%S.%N.log"), + boost::log::keywords::file_name = (folder + "caspar_%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::auto_flush = true, + boost::log::keywords::open_mode = std::ios::app ); file_sink->locked_backend()->set_formatter(&my_formatter); -#ifdef NDEBUG - file_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= trace); -#else - file_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= trace); -#endif - boost::log::wcore::get()->add_sink(file_sink); - - CASPAR_LOG(info) << L"Logging [info] or higher severity to " << folder << std::endl << std::endl; +//#ifdef NDEBUG +// file_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); +//#else +// file_sink->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); +//#endif + boost::log::core::get()->add_sink(file_sink); } catch(...) { - std::wcerr << L"Failed to Setup File Logging Sink" << std::endl << std::endl; + std::cerr << L"Failed to Setup File Logging Sink" << std::endl << std::endl; } } -void set_log_level(const std::wstring& lvl) +void set_log_level(const ustring& lvl) { - if(boost::iequals(lvl, L"trace")) - boost::log::wcore::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= trace); - else if(boost::iequals(lvl, L"debug")) - boost::log::wcore::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); - else if(boost::iequals(lvl, L"info")) - boost::log::wcore::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= info); - else if(boost::iequals(lvl, L"warning")) - boost::log::wcore::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= warning); - else if(boost::iequals(lvl, L"error")) - boost::log::wcore::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= error); - else if(boost::iequals(lvl, L"fatal")) - boost::log::wcore::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= fatal); + //QWE + //if(iequals(lvl, "trace")) + // boost::log::core::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= trace); + //else if(iequals(lvl, "debug")) + // boost::log::core::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= debug); + //else if(iequals(lvl, "info")) + // boost::log::core::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= info); + //else if(iequals(lvl, "warning")) + // boost::log::core::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= warning); + //else if(iequals(lvl, "error")) + // boost::log::core::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= error); + //else if(iequals(lvl, "fatal")) + // boost::log::core::get()->set_filter(boost::log::filters::attr(boost::log::sources::aux::severity_attribute_name::get()) >= fatal); } }} \ No newline at end of file