15 Nisan 2017 Cumartesi

log expressions format

Örnek
Şöyle yaparız.
typedef sinks::synchronous_sink< sinks::text_file_backend > file_sink;
boost::shared_ptr< file_sink > sink = ...;
...
sink->set_formatter(
  expr::format("[%1%]<%2%> : %3%") %
    expr::attr< boost::posix_time::ptime >("TimeStamp") % //1
    expr::attr< severity_level >("Severity") % //2
    expr::smessage //3
);

Örnek
Şöyle yaparız.
add_file_log(
  ...,
  keywords::format =
    exp::format("[%1%] [%2%] [%3%] [%4%] %5%")
      % exp::max_size_decor< char >(30) //1
[exp::stream << std::setw(30) <<
  exp::format_date_time< boost::posix_time::ptime >(
  "TimeStamp", "%Y-%m-%d %H:%M:%S.%f") ]
      % exp::max_size_decor< char >(10) //2
[exp::stream << std::setw(10) << exp::attr<unsigned int>("ThreadID") ]
      % exp::max_size_decor< char >(20) //3
 [exp::stream << std::setw(20) << exp::attr<string>("Scope") ]
      % exp::max_size_decor< char >(5) //4
[exp::stream << std::setw(5) << trivial::severity ]
      % exp::smessage //5
);

Hiç yorum yok:

Yorum Gönder