X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.cc;h=068631c7df3e5cbbd7d4778d33c7441f422437f2;hb=5bf459d443ab7cef04116bc0cb95e1af0178334f;hp=3c32f95b597296b3bf6f3b9e74d1125e7455e324;hpb=044a1bfb46ce16c3daac307b8c684604b43dd4cf;p=senf.git diff --git a/Utils/Logger/Target.cc b/Utils/Logger/Target.cc index 3c32f95..068631c 100644 --- a/Utils/Logger/Target.cc +++ b/Utils/Logger/Target.cc @@ -1,8 +1,8 @@ // $Id$ // -// Copyright (C) 2007 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) +// 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 @@ -28,6 +28,7 @@ // Custom includes #include +#include "ConsoleTarget.hh" //#include "Target.mpp" #define prefix_ @@ -44,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_); } @@ -84,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()) @@ -109,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 @@ -135,13 +149,15 @@ prefix_ void senf::log::Target::route(detail::StreamBase const * stream, rib_.insert(i, RoutingEntry(stream, area, level, action)); if (action == ACCEPT) updateRoutingCache(stream, area); + // This disables the initial fallback routing + detail::TargetRegistry::instance().routed(); } 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)); @@ -171,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; } @@ -181,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) @@ -191,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; @@ -199,21 +215,37 @@ prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp, } /////////////////////////////////////////////////////////////////////////// -// senf::log::TargetRegistry +// senf::log::detail::TargetRegistry prefix_ void senf::log::detail::TargetRegistry::write(StreamBase const & stream, AreaBase const & area, unsigned level, - std::string msg) + std::string const & msg) { - boost::posix_time::ptime timestamp (boost::posix_time::microsec_clock::universal_time()); - area.write(timestamp, stream, 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::now(), stream, level, msg ); } +/////////////////////////////////////////////////////////////////////////// +// namespace members + +prefix_ std::ostream & senf::log::operator<<(std::ostream & os, senf::log::Target::action_t const & action) +{ + 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