23 #include <boost/date_time/posix_time/posix_time.hpp> 33 : tag_ (detail::
getDefaultTag()), timeBase_ (-1), noformat_ (false), showTime_ (true),
34 showStream_ (false), showLevel_ (true), showArea_ (true)
40 : tag_ (detail::
getDefaultTag()), timeBase_ (-1), noformat_ (false), showTime_ (true),
41 showStream_ (false), showLevel_ (true), showArea_ (true)
43 namespace kw = console::kw;
44 namespace fty = console::factory;
49 .arg(
"flag",
"whether to display the time in log messages",
50 kw::default_value =
true)
51 .doc(
"Set time display in log messages. If time display is enabled, see the 'timeFormat'\n" 52 "command to set the time format.") );
54 .arg(
"flag",
"whether to display the stream in log messages",
55 kw::default_value =
true)
56 .doc(
"Set stream display in log messages.") );
58 .arg(
"flag",
"whether to display the log level in log messages",
59 kw::default_value =
true)
60 .doc(
"Set log level display in log messages.") );
62 .arg(
"flag",
"whether to display the area in log messages",
63 kw::default_value =
true)
64 .doc(
"Set area display in log messages.") );
66 .arg(
"format",
"time format")
67 .doc(
"Set time format. The time format is specified using a format string. This format\n" 68 "string follows the strftime format.\n" 70 "As additional option, the format string may be set to the empty string. In this\n" 71 "case the time will be displayed as 'second.nanosecond' value. IN this case, the\n" 72 "time is displayed relative to the first message after changing the format.") );
74 .arg(
"tag",
"log message tag prefix")
75 .doc(
"Every log message is optionally prefixed with a tag value. This value defaults to\n" 76 "the executable name and pid.") );
78 .doc(
"Show the current log message format.") );
83 if (showTime_) os <<
"showTime ";
84 if (showStream_) os <<
"showStream ";
85 if (showLevel_) os <<
"showLevel ";
86 if (showArea_) os <<
"showArea ";
87 if (showTime_ || showStream_ || showLevel_ || showArea_) os <<
"\n";
88 else os <<
"(all flags disabled)\n";
90 os <<
"timeFormat \"" << timeFormat_ <<
"\"\n";
91 os <<
"tag \"" << tag_ <<
"\"\n";
102 std::locale
const & loc (datestream_.getloc());
103 datestream_.imbue( std::locale(
104 loc,
new boost::posix_time::time_facet(format.c_str())) );
109 std::string
const & stream,
110 std::string
const & area,
118 datestream_ << std::setfill(
'0') << std::right
119 << std::setw(10) << (delta / 1000000000ll) <<
'.' 120 << std::setw(9) << (delta % 1000000000ll);
127 datestream_ << tag_ <<
": ";
129 datestream_ <<
'[' << stream <<
"] ";
131 datestream_ <<
'[' << LEVELNAMES[level] <<
"] ";
132 if (showArea_ && area !=
"senf::log::DefaultArea")
133 datestream_ <<
'[' << area <<
"] ";
135 return datestream_.str();
142 for (std::string::iterator i (s.begin()); i != s.end(); ++i)
143 if (*i <
' ' && *i !=
'\n')
149 std::stringstream ss;
150 ss << ::program_invocation_short_name <<
'[' << ::getpid() <<
']';
void quoteNonPrintable(std::string &s)
static SENF_CLOCKSERVICE_CONSTEXPR int64_type in_nanoseconds(clock_type const &v)
static abstime_type abstime(clock_type const &clock)
std::string getDefaultTag()
config::time_type time_type
NodeType & add(std::string const &name, boost::shared_ptr< NodeType > node)
static SENF_CLOCKSERVICE_CONSTEXPR clock_type nanoseconds(int64_type const &v)