Skip to content

Commit

Permalink
Fix some boost log formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Love committed Oct 14, 2018
1 parent 40bff2d commit 6ab55e4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Dependencies:
* https://github.com/fmtlib/fmt

## boost::log
Dependencies: boost
Dependencies:
* boost - drags in multiple boost libraries (log, log_setup, thread, system, atomic, chrono, date_time, filesystem, regex)
15 changes: 14 additions & 1 deletion boost_console/console.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
Expand All @@ -12,6 +13,7 @@ namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;
using namespace logging::trivial;

#include <thread>
Expand Down Expand Up @@ -122,7 +124,18 @@ int main(int argc, char **argv)
}

logging::add_console_log(std::cout,
keywords::format = "%TimeStamp%|%Severity%|%Message%"
//keywords::format = "%TimeStamp%|%Severity%|%Message%"
keywords::format =
(
expr::stream
<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp","%Y-%m-%d %H:%M%S.%f")
<< "|"
<< expr::attr<boost::log::attributes::current_thread_id::value_type >("ThreadID")
<< "|"
<< logging::trivial::severity
<< "|"
<< expr::smessage
)
);

logging::core::get()->set_filter(
Expand Down
16 changes: 14 additions & 2 deletions boost_file/file.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/support/date_time.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
Expand All @@ -12,6 +13,7 @@ namespace logging = boost::log;
namespace src = boost::log::sources;
namespace sinks = boost::log::sinks;
namespace keywords = boost::log::keywords;
namespace expr = boost::log::expressions;
using namespace logging::trivial;

#include <thread>
Expand Down Expand Up @@ -132,8 +134,18 @@ int main(int argc, char **argv)
logging::add_file_log(
keywords::file_name = logFile,
keywords::rotation_size = size,
keywords::format = "%TimeStamp%|%Severity%|%Message%"
);
//keywords::format = "%TimeStamp%|%Severity%|%Message%"
keywords::format =
(
expr::stream
<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp","%Y-%m-%d %H:%M%S.%f")
<< "|"
<< expr::attr<boost::log::attributes::current_thread_id::value_type >("ThreadID")
<< "|"
<< logging::trivial::severity
<< "|"
<< expr::smessage
) );

logging::core::get()->set_filter(
logging::trivial::severity >= logLevel
Expand Down

0 comments on commit 6ab55e4

Please sign in to comment.