id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 11686,boost::posix_time::ptime custom facet doesn't work with BOOST_LOG_TRIVIAL,anonymous,Andrey Semashev,"Here's my program, I expect BOOST_LOG_TRIVIAL to print HH:MM:SS value. cout.imblue does it correctly. Not sure why std::ostream& operator<<(std::ostream& os, const boost::posix_time::ptime& o) is never called for BOOST_LOG_TRIVIAL << ptime Is this a bug in library? #include #include #include #include #include namespace logging = boost::log; namespace pt = boost::posix_time; class my_ptime_facet : public std::locale::facet { public: enum option{ use_hhmmss //,.... }; static std::locale::id id; my_ptime_facet(option o=use_hhmmss): facet(0), _option(o) { }; option get_option() const {return _option;}; protected: option _option; }; std::locale::id my_ptime_facet::id; //Facet family unique id std::ostream& operator<<(std::ostream& os, const boost::posix_time::ptime& o) { std::locale const& l = os.getloc(); if( std::has_facet(l) ){ my_ptime_facet const& f = std::use_facet(l); switch(f.get_option()){ case my_ptime_facet::use_hhmmss: os << o.time_of_day().hours() << "":"" << o.time_of_day().minutes() << "":"" << o.time_of_day().seconds() ; break; } return os; } return os; } int main() { logging::add_common_attributes(); boost::posix_time::ptime t1(boost::posix_time::time_from_string(""2014-11-23 23:59:59.117"")); std::locale custom_locale ( std::locale(), new my_ptime_facet(my_ptime_facet::use_hhmmss) ); auto sink = logging::add_console_log(std::cout); sink->imbue(custom_locale); std::cout.imbue(custom_locale); std::cout<< t1 <