19 #ifdef LOG4CPP_HAVE_SSTREAM 30 #ifdef LOG4CPP_HAVE_INT64_T 31 #ifdef LOG4CPP_HAVE_STDINT_H 33 #endif // LOG4CPP_HAVE_STDINT_H 35 #ifdef LOG4CPP_MISSING_INT64_OSTREAM_OP 44 ::sprintf(buf,
"%I64d", i);
47 #endif // LOG4CPP_MISSING_INT64_OSTREAM_OP 48 #endif // LOG4CPP_HAVE_INT64_T 67 if (specifier ==
"") {
70 #ifdef LOG4CPP_HAVE_SSTREAM 71 std::istringstream s(specifier);
73 std::istrstream s(specifier.c_str());
80 if (_precision == -1) {
81 out <<
event.categoryName;
83 std::string::size_type begin = std::string::npos;
84 for(
int i = 0; i < _precision; i++) {
85 begin =
event.categoryName.rfind(
'.', begin - 2);
86 if (begin == std::string::npos) {
92 out <<
event.categoryName.substr(begin);
102 out <<
event.message;
120 out <<
event.threadName;
136 if ((timeFormat ==
"") || (timeFormat ==
"ISO8601")) {
137 timeFormat = FORMAT_ISO8601;
138 }
else if (timeFormat ==
"ABSOLUTE") {
139 timeFormat = FORMAT_ABSOLUTE;
140 }
else if (timeFormat ==
"DATE") {
141 timeFormat = FORMAT_DATE;
144 std::string::size_type pos = timeFormat.find(
"%l");
145 if (pos == std::string::npos) {
148 std::string::size_type pos = timeFormat.find(
"%L");
149 if (pos == std::string::npos) {
150 _printMillis =
false;
151 _printMicros =
false;
152 _timeFormat1 = timeFormat;
154 _printMillis =
false;
156 _timeFormat1 = timeFormat.substr(0, pos);
157 _timeFormat2 = timeFormat.substr(pos + 2);
162 _printMicros =
false;
163 _timeFormat1 = timeFormat.substr(0, pos);
164 _timeFormat2 = timeFormat.substr(pos + 2);
169 struct std::tm currentTime;
170 std::time_t t =
event.timeStamp.getSeconds();
173 std::string timeFormat;
176 formatStream << _timeFormat1
177 << std::setw(3) << std::setfill(
'0')
178 <<
event.timeStamp.getMilliSeconds()
180 timeFormat = formatStream.
str();
181 }
else if (_printMicros) {
183 formatStream << _timeFormat1
184 << std::setw(6) << std::setfill(
'0')
185 <<
event.timeStamp.getMicroSeconds()
187 timeFormat = formatStream.
str();
189 timeFormat = _timeFormat1;
191 std::strftime(formatted,
sizeof(formatted), timeFormat.c_str(), ¤tTime);
208 out <<
event.timeStamp.getSeconds();
214 #ifdef LOG4CPP_HAVE_INT64_T 215 int64_t t =
event.timeStamp.getSeconds() -
218 t +=
event.timeStamp.getMilliSeconds() -
223 double t =
event.timeStamp.getSeconds() -
226 t +=
event.timeStamp.getMilliSeconds() -
229 out << std::setiosflags(std::ios::fixed)
230 << std::setprecision(0) << t;
237 size_t minWidth,
size_t maxWidth,
bool alignLeft) :
238 _component(component) ,
241 _alignLeft(alignLeft) {
250 _component->append(s, event);
251 std::string msg = s.
str();
252 if (_maxWidth > 0 && _maxWidth < msg.length()) {
253 msg.erase(_maxWidth);
255 size_t fillCount = _minWidth - msg.length();
256 if (_minWidth > msg.length()) {
258 out << msg << std::string(fillCount,
' ');
260 out << std::string(fillCount,
' ') << msg;
281 setConversionPattern(DEFAULT_CONVERSION_PATTERN);
287 clearConversionPattern();
291 for(ComponentVector::const_iterator i = _components.begin();
292 i != _components.end(); ++i) {
296 _conversionPattern =
"";
300 #ifdef LOG4CPP_HAVE_SSTREAM 301 std::istringstream conversionStream(conversionPattern);
303 std::istrstream conversionStream(conversionPattern.c_str());
311 clearConversionPattern();
312 while (conversionStream.get(ch)) {
317 conversionStream.get(ch2);
318 if ((ch2 ==
'-') || ((ch2 >=
'0') && (ch2 <=
'9'))) {
319 conversionStream.putback(ch2);
320 conversionStream >> minWidth;
321 conversionStream.get(ch2);
324 conversionStream >> maxWidth;
326 conversionStream.putback(ch2);
329 if (!conversionStream.get(ch)) {
331 msg <<
"unterminated conversion specifier in '" << conversionPattern <<
"' at index " << conversionStream.tellg();
334 std::string specPostfix =
"";
338 if (conversionStream.get(ch2)) {
340 while(conversionStream.get(ch2) && (ch2 !=
'}'))
343 conversionStream.putback(ch2);
357 endline << std::endl;
358 literal += endline.
str();
387 msg <<
"unknown conversion specifier '" << ch <<
"' in '" << conversionPattern <<
"' at index " << conversionStream.tellg();
391 if (!literal.empty()) {
395 if ((minWidth != 0) || (maxWidth != 0)) {
397 minWidth = maxWidth = 0;
399 _components.push_back(component);
406 if (!literal.empty()) {
410 _conversionPattern = conversionPattern;
414 return _conversionPattern;
420 for(ComponentVector::const_iterator i = _components.begin();
421 i != _components.end(); ++i) {
422 (*i)->append(message, event);
425 return message.
str();
434 if (pattern.empty() || pattern ==
"default")
437 if (pattern ==
"simple")
443 if (pattern ==
"basic")
449 if (pattern ==
"ttcc")
optional_params_validator optional(const char *param, T &value) const
int getMilliSeconds() const
virtual void clearConversionPattern()
ostream & operator<<(ostream &os, const width &w)
static const char * DEFAULT_CONVERSION_PATTERN
virtual void append(std::ostringstream &out, const LoggingEvent &event)
CategoryNameComponent(std::string specifier)
void localtime(const ::time_t *time,::tm *t)
static const char *const FORMAT_DATE
virtual std::string format(const LoggingEvent &event)
virtual void append(std::ostringstream &out, const LoggingEvent &event)
virtual void setConversionPattern(const std::string &conversionPattern)
static const TimeStamp & getStartTime()
virtual void append(std::ostringstream &out, const LoggingEvent &event)
virtual void append(std::ostringstream &out, const LoggingEvent &event)
static const char *const FORMAT_ISO8601
static const char * SIMPLE_CONVERSION_PATTERN
virtual void append(std::ostringstream &out, const LoggingEvent &event)
StringLiteralComponent(const std::string &literal)
static const char * BASIC_CONVERSION_PATTERN
static const char * TTCC_CONVERSION_PATTERN
virtual void append(std::ostringstream &out, const LoggingEvent &event)
virtual void append(std::ostringstream &out, const LoggingEvent &event)
virtual std::string getConversionPattern() const
virtual void append(std::ostringstream &out, const LoggingEvent &event)
static const char *const FORMAT_ABSOLUTE
details::parameter_validator get_for(const char *tag) const
std::auto_ptr< Layout > create_pattern_layout(const FactoryParams ¶ms)
virtual void append(std::ostringstream &out, const LoggingEvent &event)
static const std::string & getPriorityName(int priority)
virtual void append(std::ostringstream &out, const LoggingEvent &event)
TimeStampComponent(std::string timeFormat)