/* * Copyright Andrey Semashev 2007 - 2015. * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at * http://www.boost.org/LICENSE_1_0.txt) */ /*! * \file main.cpp * \author Andrey Semashev * \date 07.11.2009 * * \brief An example of trivial logging. */ //#define BOOST_ALL_DYN_LINK 1 #define BOOST_LOG_DYN_LINK 1 #include #include #include #include #include #include int main(int argc, char* argv[]) { boost::log::add_console_log(std::clog, boost::log::keywords::format = "%TimeStamp%: [%Severity%]: %Message%"); boost::log::add_file_log("sample.log", boost::log::keywords::format = "%TimeStamp%: [%Severity%]: %Message%", boost::log::keywords::open_mode = std::ios_base::app); boost::log::add_common_attributes(); BOOST_LOG_FUNCTION(); // Trivial logging: all log records are written into a file BOOST_LOG_TRIVIAL(trace) << "A trace severity message"; BOOST_LOG_TRIVIAL(debug) << "A debug severity message"; BOOST_LOG_TRIVIAL(info) << "An info severity message"; BOOST_LOG_TRIVIAL(warning) << "A warning severity message"; BOOST_LOG_TRIVIAL(error) << "An error severity message"; BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message"; BOOST_LOG_TRIVIAL(debug) << "----------------------"; // Filtering can also be applied using namespace boost::log; core::get()->set_filter ( trivial::severity >= trivial::info ); // Now the first two lines will not pass the filter BOOST_LOG_TRIVIAL(trace) << "A trace severity message"; BOOST_LOG_TRIVIAL(debug) << "A debug severity message"; BOOST_LOG_TRIVIAL(info) << "An info severity message"; BOOST_LOG_TRIVIAL(warning) << "A warning severity message"; BOOST_LOG_TRIVIAL(error) << "An error severity message"; BOOST_LOG_TRIVIAL(fatal) << "A fatal severity message"; return 0; }