On Tue, 28 Jun 2011 18:44:57 +1000, Malcolm Smith wrote:
> 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.
Thank you, I will look into integrating this.
>
> 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
--
VH
|