X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Utils%2FLogger%2FTarget.cc;h=11142a7c841c371155e02f27696019b849ca8cd5;hb=f6f670f2dbc82b77db29df6cd452f2b351b9662a;hp=651671e84c93c8d3f2c35151ec41fad107d40cfc;hpb=9ff976ea47b175355a1f7ef4d05f14edb98a82e4;p=senf.git diff --git a/Utils/Logger/Target.cc b/Utils/Logger/Target.cc index 651671e..11142a7 100644 --- a/Utils/Logger/Target.cc +++ b/Utils/Logger/Target.cc @@ -35,24 +35,84 @@ /////////////////////////////////////////////////////////////////////////// // senf::log::Target +prefix_ senf::log::Target::Target() +{ + TargetRegistry::instance().registerTarget(this); +} + 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 + RIB::reverse_iterator i (rib_.rbegin()); + unroute(i->stream, i->area, i->level, i->action); + } + TargetRegistry::instance().unregisterTarget(this); +} + +prefix_ void senf::log::Target::updateRoutingCache(detail::StreamBase const * stream, + detail::AreaBase const * area) +{ + if (! stream) { + StreamRegistry::Registry::iterator i (StreamRegistry::instance().registry_.begin()); + StreamRegistry::Registry::iterator const i_end (StreamRegistry::instance().registry_.end()); + for (; i != i_end ; ++i) + updateRoutingCache(i->second, area); + return; + } + if (! area) { + AreaRegistry::Registry::iterator i (AreaRegistry::instance().registry_.begin()); + AreaRegistry::Registry::iterator const i_end (AreaRegistry::instance().registry_.end()); + for (; i != i_end ; ++i) + updateRoutingCache(stream, i->second); + return; + } + unsigned limit (DISABLED::value); + RIB::iterator i (rib_.begin()); + RIB::iterator const i_end (rib_.end()); + for(; i != i_end; ++i) + 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); + if (l < limit) + limit = l; + } + if (limit == DISABLED::value) + area->removeRoutingCache(*this, *stream); + else + area->updateRoutingCache(*this, *stream, limit); +} -prefix_ void senf::log::Target::write(detail::StreamBase const & stream, - detail::AreaBase const & area, - unsigned level, std::string const & message) +prefix_ void senf::log::Target::write(boost::posix_time::ptime timestamp, + detail::StreamBase const & stream, + detail::AreaBase const & area, unsigned level, + std::string const & message) { RIB::iterator i (rib_.begin()); RIB::iterator const i_end (rib_.end()); for (; i != i_end; ++i) - if ( ( ! i->stream || i->stream == &stream ) && - ( ! i->area || i->area == &area ) && - i->level <= level ) { - v_write(stream.v_name(), area.v_name(), level, message); + if ( (! i->stream || i->stream == &stream) && + (! i->area || i->area == &area) && + (i->level == NONE::value ? i->stream->defaultRuntimeLimit() : i->level) <= level ) { + if (i->action == ACCEPT) + v_write(timestamp, stream.v_name(), area.v_name(), level, message); return; } } +/////////////////////////////////////////////////////////////////////////// +// senf::log::TargetRegistry + +prefix_ void senf::log::TargetRegistry::write(detail::StreamBase const & stream, + detail::AreaBase const & area, unsigned level, + std::string msg) +{ + boost::posix_time::ptime timestamp (boost::posix_time::microsec_clock::universal_time()); + area.write(timestamp, stream, level, msg); +} + ///////////////////////////////cc.e//////////////////////////////////////// #undef prefix_ //#include "Target.mpp"