X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.cc;h=068631c7df3e5cbbd7d4778d33c7441f422437f2;hb=5bf459d443ab7cef04116bc0cb95e1af0178334f;hp=aee4d6e802ac9299a248de2eef350d6e8c6de379;hpb=f73fa16ed5abdce272ac77f8b8b9ef2b9922c266;p=senf.git diff --git a/Utils/Logger/Target.cc b/Utils/Logger/Target.cc index aee4d6e..068631c 100644 --- a/Utils/Logger/Target.cc +++ b/Utils/Logger/Target.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Copyright (C) 2007 +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund // // This program is free software; you can redistribute it and/or modify @@ -45,8 +45,8 @@ prefix_ senf::log::Target::Target() prefix_ senf::log::Target::~Target() { while( ! rib_.empty()) { - // This is terribly slow but simplifies the area cache handling and removing a target should - // be quite seldom + // This is slow but simplifies the area cache handling and removing a target should be + // relatively seldom RIB::reverse_iterator i (rib_.rbegin()); unroute(i->stream_, i->area_, i->level_, i->action_); } @@ -85,6 +85,8 @@ prefix_ void senf::log::Target::unroute(std::string const & stream, std::string prefix_ void senf::log::Target::unroute(int index) { + if (rib_.empty()) + return; RIB::iterator i; if (index < 0) { if (RIB::size_type(-index) >= rib_.size()) @@ -110,6 +112,17 @@ prefix_ void senf::log::Target::unroute(int index) updateRoutingCache(entry.stream_, entry.area_); } +prefix_ void senf::log::Target::flush() +{ + RIB old; + rib_.swap(old); + RIB::const_iterator i (old.begin()); + RIB::const_iterator const i_end (old.end()); + for (; i != i_end; ++i) + if (i->action_ == ACCEPT) + updateRoutingCache(i->stream_, i->area_); +} + //////////////////////////////////////// // private members @@ -141,10 +154,10 @@ prefix_ void senf::log::Target::route(detail::StreamBase const * stream, } prefix_ void senf::log::Target::unroute(detail::StreamBase const * stream, - detail::AreaBase const * area, unsigned level, + detail::AreaBase const * area, unsigned level, action_t action) { - RIB::iterator i = std::find(rib_.begin(), rib_.end(), + RIB::iterator i = std::find(rib_.begin(), rib_.end(), RoutingEntry(stream, area, level, action)); if (i != rib_.end()) unroute(std::distance(rib_.begin(), i)); @@ -174,7 +187,7 @@ prefix_ void senf::log::Target::updateRoutingCache(detail::StreamBase const * st if ( (! i->stream_ || i->stream_ == stream) && (! i->area_ || i->area_ == area) && i->action_ == ACCEPT ) { - unsigned l (i->level_ == NONE::value ? i->stream_->defaultRuntimeLimit() : i->level_); + unsigned l (i->level_ == NONE::value ? stream->defaultRuntimeLimit() : i->level_); if (l < limit) limit = l; } @@ -184,7 +197,7 @@ prefix_ void senf::log::Target::updateRoutingCache(detail::StreamBase const * st area->updateRoutingCache(*this, *stream, limit); } -prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp, +prefix_ void senf::log::Target::write(time_type timestamp, detail::StreamBase const & stream, detail::AreaBase const & area, unsigned level, std::string const & message) @@ -194,7 +207,7 @@ prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp, for (; i != i_end; ++i) if ( (! i->stream_ || i->stream_ == &stream) && (! i->area_ || i->area_ == &area) && - (i->level_ == NONE::value ? i->stream_->defaultRuntimeLimit() : i->level_) <= level ) { + (i->level_ == NONE::value ? stream.defaultRuntimeLimit() : i->level_) <= level ) { if (i->action_ == ACCEPT) v_write(timestamp, stream.v_name(), area.v_name(), level, message); return; @@ -206,35 +219,33 @@ prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp, prefix_ void senf::log::detail::TargetRegistry::write(StreamBase const & stream, AreaBase const & area, unsigned level, - std::string msg) + std::string const & msg) { - if (fallbackRouting_) - static_cast(ConsoleTarget::instance()).v_write( - (*timeSource_)(), stream.v_name(), area.v_name(), level, msg ); + if (fallbackRouting_) { + if (level >= stream.defaultRuntimeLimit()) + static_cast(ConsoleTarget::instance()).v_write( + TimeSource::now(), stream.v_name(), area.v_name(), level, msg ); + } else - area.write( (*timeSource_)(), stream, level, msg ); + area.write( TimeSource::now(), stream, level, msg ); } - -/////////////////////////////////////////////////////////////////////////// -// senf::log::TimeSource - -prefix_ senf::log::TimeSource::~TimeSource() -{} - /////////////////////////////////////////////////////////////////////////// -// senf::log::SystemTimeSource +// namespace members -prefix_ boost::posix_time::ptime senf::log::SystemTimeSource::operator()() - const +prefix_ std::ostream & senf::log::operator<<(std::ostream & os, senf::log::Target::action_t const & action) { - return boost::posix_time::microsec_clock::universal_time(); + if( action == Target::ACCEPT) os << "ACCEPT"; + else if( action == Target::REJECT) os << "REJECT"; + else os << "unknown action"; + return os; } + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Target.mpp" - + // Local Variables: // mode: c++ // fill-column: 100