[Log4cplus-devel] Implementing %r in PatternLayout
Logging Framework for C++
Brought to you by:
wilx
|
From: Malcolm S. <Mal...@Pr...> - 2011-06-28 08:45:33
|
I've made the following modification for my needs (I need the %r option
supported). I hope this (or something like it) can be added in a future
release.
PatternLayout.cpp
==============
// might want to use a new global - using this for now since it is
always initialized
namespace log4cplus
{
extern helpers::Time TTCCLayout_time_base;
}
class RelativeTimeConverter : public PatternConverter {
public:
RelativeTimeConverter(const FormattingInfo& info,
const log4cplus::tstring& pattern);
virtual log4cplus::tstring convert(const InternalLoggingEvent&
event);
private:
log4cplus::tstring format;
};
////////////////////////////////////////////////
// RelativeTimeConverter methods:
////////////////////////////////////////////////
log4cplus::pattern::RelativeTimeConverter::RelativeTimeConverter
(const FormattingInfo&
info,
const
log4cplus::tstring& pattern)
: PatternConverter(info),
format(pattern)
{
}
log4cplus::tstring
log4cplus::pattern::RelativeTimeConverter::convert
(const InternalLoggingEvent&
event)
{
log4cplus::helpers::Time const rel_time = event.getTimestamp () -
log4cplus::TTCCLayout_time_base;
return rel_time.getFormattedTime(format, true);
}
// in void
log4cplus::pattern::PatternParser::finalizeConverter(log4cplus::tchar c)
case LOG4CPLUS_TEXT('r'):
{
log4cplus::tstring dOpt = extractOption();
if(dOpt.empty ()) {
dOpt = LOG4CPLUS_TEXT("%H:%M:%S:%q");
}
pc = new RelativeTimeConverter(formattingInfo, dOpt);
}
break;
Mal
|