Beispiel #1
0
    void init(const fs::path &rErrEvtPath, const fs::path &rStatusPath) {
        // register common attributes - ThreadID, LineID, TimeStamp etc.
        logging::add_common_attributes();

        // Construct the sink for the "event_log" channel
        typedef sinks::synchronous_sink<sinks::text_ostream_backend> text_sink;
        auto sink = boost::make_shared<text_sink>();
        sink->locked_backend()->auto_flush(true);
        sink->locked_backend()->add_stream(boost::make_shared<std::ofstream>(rErrEvtPath.c_str()));
        sink->set_formatter(expr::format("%1% [%2%] tid[%3%] %4%") %
                            expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%H:%M:%S.%f") %
                            logging::trivial::severity % expr::attr<attrs::current_thread_id::value_type>("ThreadID") %
                            expr::smessage);
        sink->set_filter(expr::attr<std::string>("Channel") == "event");
        logging::core::get()->add_sink(sink);

        // Construct the sink for the "status_log" channel
        sink = boost::make_shared<text_sink>();
        sink->locked_backend()->auto_flush(true);
        sink->locked_backend()->add_stream(boost::make_shared<std::ofstream>(rStatusPath.c_str()));
        sink->set_formatter(expr::format("%1% [%2%] tid[%3%] %4%") %
                            expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%H:%M:%S.%f") %
                            logging::trivial::severity % expr::attr<attrs::current_thread_id::value_type>("ThreadID") %
                            expr::smessage);
        sink->set_filter(expr::attr<std::string>("Channel") == "status");
        logging::core::get()->add_sink(sink);
    }
Beispiel #2
0
void init()
{	
	boost::log::add_common_attributes<wchar_t>();
	typedef boost::log::aux::add_common_attributes_constants<wchar_t> traits_t;

	typedef boost::log::sinks::synchronous_sink<boost::log::sinks::wtext_file_backend> file_sink_type;

	typedef boost::log::sinks::asynchronous_sink<boost::log::sinks::wtext_ostream_backend> stream_sink_type;

	auto stream_backend = boost::make_shared<boost::log::sinks::wtext_ostream_backend>();
	stream_backend->add_stream(boost::shared_ptr<std::wostream>(&std::wcout, boost::log::empty_deleter()));
	stream_backend->auto_flush(true);

	auto stream_sink = boost::make_shared<stream_sink_type>(stream_backend);
	
//#ifdef NDEBUG
//	stream_sink->set_filter(boost::log::filters::attr<severity_level>(boost::log::sources::aux::severity_attribute_name<wchar_t>::get()) >= debug);
//#else
//	stream_sink->set_filter(boost::log::filters::attr<severity_level>(boost::log::sources::aux::severity_attribute_name<wchar_t>::get()) >= debug);
//#endif

	stream_sink->locked_backend()->set_formatter(&my_formatter);

	boost::log::wcore::get()->add_sink(stream_sink);
}
Beispiel #3
0
BOOST_LOG_GLOBAL_LOGGER_INIT(__logger, bl::sources::severity_logger_mt)
{
    bl::sources::severity_logger_mt<boost::log::trivial::severity_level> logger;
    logger.add_attribute("TimeStamp", bl::attributes::local_clock());

    using text_sink = bl::sinks::asynchronous_sink<bl::sinks::text_ostream_backend>;
    auto consoleSink = boost::make_shared<text_sink>();
    consoleSink->locked_backend()->add_stream(boost::shared_ptr<std::ostream>(&std::cout, boost::null_deleter()));
    consoleSink->set_filter(severity >= boost::log::trivial::severity_level::warning);

    using file_sink = bl::sinks::asynchronous_sink<bl::sinks::text_file_backend>;
    auto logfileSink = boost::make_shared<file_sink>();
    
    {
        auto logfileBackend = logfileSink->locked_backend();
        logfileBackend->set_time_based_rotation(bl::sinks::file::rotation_at_time_point(0, 0, 0));
        logfileBackend->set_file_name_pattern("Logs\\ashbot_%Y%m%d.log");
        logfileBackend->auto_flush();
        logfileBackend->set_file_collector(
            bl::sinks::file::make_collector(bl::keywords::target = "Logs\\Archive")
        );
    }

    namespace expr = bl::expressions;

    bl::formatter fmt = expr::stream
        << format_date_time(timestamp, "%Y-%m-%d %H:%M:%S.%f")
        << " [" << boost::log::trivial::severity << "] "
        << expr::smessage;
    logfileSink->set_formatter(fmt);

    bl::core::get()->add_sink(consoleSink);
    bl::core::get()->add_sink(logfileSink);

    return logger;
}