QString SimpleLayout::format(const LoggingEvent &rEvent) { if (mShowLevel) return rEvent.level().toString() + QLatin1String(" - ") + rEvent.message() + Layout::endOfLine(); else return rEvent.message() + Layout::endOfLine(); }
Filter::Decision StringMatchFilter::decide(const LoggingEvent &rEvent) const { if (rEvent.message().isEmpty() || mStringToMatch.isEmpty() || rEvent.message().indexOf(mStringToMatch) < 0) return Filter::NEUTRAL; if (mAcceptOnMatch) return Filter::ACCEPT; else return Filter::DENY; }
Filter::Decision LevelRangeFilter::decide(const LoggingEvent &rEvent) const { if (rEvent.level() < mLevelMin) return Filter::DENY; if (rEvent.level() > mLevelMax) return Filter::DENY; if (mAcceptOnMatch) return Filter::ACCEPT; else return Filter::NEUTRAL; }
QSqlRecord DatabaseLayout::formatRecord(const LoggingEvent &rEvent) { QSqlField field; QSqlRecord record; if (!mTimeStamp.isEmpty()) { field.setName(mTimeStamp); field.setType(QVariant::DateTime); field.setGenerated(true); field.setValue(DateTime::fromMSecsSinceEpoch(rEvent.timeStamp())); record.append(field); } if (!mLoggerName.isEmpty()) { field.setName(mLoggerName); field.setType(QVariant::String); field.setGenerated(true); field.setValue(rEvent.loggerName()); record.append(field); } if (!mThreadName.isEmpty()) { field.setName(mThreadName); field.setType(QVariant::String); field.setGenerated(true); field.setValue(rEvent.threadName()); record.append(field); } if (!mLevel.isEmpty()) { field.setName(mLevel); field.setType(QVariant::String); field.setGenerated(true); field.setValue(rEvent.level().toString()); record.append(field); } if (!mMessage.isEmpty()) { field.setName(mMessage); field.setType(QVariant::String); field.setGenerated(true); field.setValue(rEvent.message()); record.append(field); } return record; }
Filter::Decision LevelMatchFilter::decide(const LoggingEvent &rEvent) const { if (mLevelToMatch == Level::NULL_INT || rEvent.level() != mLevelToMatch) return Filter::NEUTRAL; if (mAcceptOnMatch) return Filter::ACCEPT; else return Filter::DENY; }
QString BasicPatternConverter::convert(const LoggingEvent &rLoggingEvent) const { switch (mType) { case MESSAGE_CONVERTER: return rLoggingEvent.message(); break; case NDC_CONVERTER: return rLoggingEvent.ndc(); break; case LEVEL_CONVERTER: return rLoggingEvent.level().toString(); break; case THREAD_CONVERTER: return rLoggingEvent.threadName(); break; default: Q_ASSERT_X(false, "BasicPatternConverter::convert()", "Unkown type constant"); return QString(); } }
QString LoggerPatternConverter::convert(const LoggingEvent &rLoggingEvent) const { if (!rLoggingEvent.logger()) return QString(); QString name = rLoggingEvent.logger()->name(); if (mPrecision <= 0 || (name.isEmpty())) return name; const QString separator(QLatin1String("::")); int i = mPrecision; int begin = name.length(); while ((i > 0) && (begin >= 0)) { begin = name.lastIndexOf(separator, begin - name.length() - 1); i--; } if (begin < 0) begin = 0; else begin += 2; return name.mid(begin); }
QString DatabaseLayout::format(const LoggingEvent &rEvent) { QString result; if (!mTimeStamp.isEmpty()) { result.append(mTimeStamp); result.append(":"); result.append(DateTime::fromMSecsSinceEpoch(rEvent.timeStamp()).toString("dd.MM.yyyy hh:mm")); } if (!mThreadName.isEmpty()) { result.append(mThreadName); result.append(":"); result.append(mThreadName); result.append("; "); } if (!mLevel.isEmpty()) { result.append(mLevel); result.append(":"); result.append(mLevel); result.append("; "); } if (!mLoggerName.isEmpty()) { result.append(mLoggerName); result.append(":"); result.append(mLoggerName); result.append("; "); } if (!mMessage.isEmpty()) { result.append(mMessage); result.append(":"); result.append(mMessage); result.append("; "); } return result; }
void BinaryWriterAppender::append(const LoggingEvent &rEvent) { // Q_ASSERT_X(, "WriterAppender::append()", "Lock must be held by caller"); if (const BinaryLoggingEvent *binEvent = dynamic_cast<const BinaryLoggingEvent *>(&rEvent)) *mpWriter << binEvent->binaryMessage(); else { if (Layout *l = layout()) { if (BinaryLayout *bl = qobject_cast<BinaryLayout*>(l)) *mpWriter << bl->binaryFormat(*binEvent); else *mpWriter << l->format(rEvent); } else *mpWriter << rEvent.message(); } if (handleIoErrors()) return; }
void AppenderSkeleton::doAppend(const LoggingEvent &rEvent) { // The mutex serialises concurrent access from multiple threads. // - e.g. two threads using the same logger // - e.g. two threads using different logger with the same appender // // A call from the same thread will pass the mutex (QMutex::Recursive) // and get to the recursion guard. The recursion guard blocks recursive // invocation and prevents a possible endless loop. // - e.g. an appender logs an error with a logger that uses it QMutexLocker locker(&mObjectGuard); if (mAppendRecursionGuard) return; RecursionGuardLocker recursion_locker(&mAppendRecursionGuard); if (!checkEntryConditions()) return; if (!isAsSevereAsThreshold(rEvent.level())) return; Filter *p_filter = mpHeadFilter; while(p_filter) { Filter::Decision decision = p_filter->decide(rEvent); if (decision == Filter::ACCEPT) break; else if (decision == Filter::DENY) return; else p_filter = p_filter->next(); } append(rEvent); }
QString MDCPatternConverter::convert(const LoggingEvent &rLoggingEvent) const { return rLoggingEvent.mdc().value(mKey); };
QString DatePatternConverter::convert(const LoggingEvent &rLoggingEvent) const { return DateTime::fromMilliSeconds(rLoggingEvent.timeStamp()).toString(mFormat); }
/* virtual */ void av::logging::ConsoleAppender::doAppend(LoggingEvent& event) { std::clog << event.getFormattedString() << std::endl; }
/* virtual */ void av::logging::StreamAppender::doAppend(LoggingEvent& event) { mStream << event.getFormattedString() << std::endl; }