7 Mart 2017 Salı

log basic_formatter_factory

Tanımlama
Şöyle yaparız.
class ServerityFormatterFactory : public
  logging::basic_formatter_factory<char_t, logging::trivial::severity_level> {
  ...
};
Kullanmak için şöyle yaparız.
logging::register_formatter_factory(
  logging::aux::default_attribute_names::severity().string(),
   boost::make_shared<ServerityFormatterFactory>()
);
create_formatter metodu
Elimizde bir formatter olsun
class SeverityLevelFormatter {
private:
  mutable boost::format format_;

public:
  SeverityLevelFormatter(const std::string& format) : format_(format) {
  }

  void operator() (logging::formatting_ostream& strm,
    const logging::value_ref<logging::trivial::severity_level>& value) const {
    strm << boost::format(format_) % to_string(value.get());
  }
};
Şöyle yaparız.
formatter_type create_formatter(const logging::attribute_name& name,
                                const args_map& args) {
  auto it = args.find(L"format");
  if (it != args.end()) {
    return boost::phoenix::bind(SeverityLevelFormatter(it->second),
       expr::stream, expr::attr<logging::trivial::severity_level>(name));
  }
  else {
    return expr::stream << expr::attr<logging::trivial::severity_level>(name);
  }
}

Hiç yorum yok:

Yorum Gönder