00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00026 #ifndef HH_SENF_Utils_Logger_Target_
00027 #define HH_SENF_Utils_Logger_Target_ 1
00028
00029
00030 #include <vector>
00031 #include <boost/utility.hpp>
00032 #include <senf/Utils/Exception.hh>
00033 #include <senf/Utils/Console/LazyDirectory.hh>
00034 #include "TimeSource.hh"
00035 #include "Levels.hh"
00036
00037
00038
00039
00050 namespace senf {
00051 namespace log {
00052
00053 namespace detail { class TargetRegistry; }
00054 namespace detail { class AreaBase; }
00055 namespace detail { struct LogParameters; }
00056 namespace detail { struct StreamBase; }
00057
00142 class Target : private boost::noncopyable
00143 {
00144 public:
00145
00146
00147
00153 enum action_t {
00154 ACCEPT
00155 , REJECT
00156 };
00157
00165 struct RoutingEntry
00166 {
00167 std::string stream() const;
00168 std::string area() const;
00169 unsigned level() const;
00170 action_t action() const;
00171
00172 # ifdef DOXYGEN
00173 private:
00174 # endif
00175
00176 RoutingEntry();
00177 bool operator==(RoutingEntry const & other) const;
00178
00179 private:
00180 RoutingEntry(detail::StreamBase const * stream, detail::AreaBase const * area,
00181 unsigned level, action_t action);
00182
00183 detail::StreamBase const * stream_;
00184 detail::AreaBase const * area_;
00185 unsigned level_;
00186 action_t action_;
00187
00188 friend class Target;
00189 };
00190
00191 private:
00192 typedef std::vector<RoutingEntry> RIB;
00193
00194 public:
00195 typedef RIB::const_iterator iterator;
00196 typedef RIB::size_type size_type;
00197
00198
00200
00201
00202 explicit Target(std::string const & name);
00203 virtual ~Target();
00204
00205
00206
00208
00209
00210 # ifdef DOXYGEN
00211
00212 template <class Stream, class Area, class Level> void route(
00213 action_t action = ACCEPT, int index = -1);
00214
00240 # endif
00241
00242 void route(std::string const & stream, std::string const & area = "",
00243 unsigned level = NONE::value, action_t action = ACCEPT, int index = -1);
00245
00267 # ifdef DOXYGEN
00268
00269 template <class Stream, class Area, class Level>
00270 void unroute(action_t action = ACCEPT);
00272
00287 # endif
00288
00289 void unroute(std::string const & stream, std::string const & area = "",
00290 unsigned level = NONE::value, action_t action = ACCEPT);
00292
00307 void unroute(int index=-1);
00308
00315 # ifndef DOXYGEN
00316
00317 void route(action_t action = ACCEPT, int index = -1);
00318 template <class A1>
00319 void route(action_t action = ACCEPT, int index = -1);
00320 template <class A1, class A2>
00321 void route(action_t action = ACCEPT, int index = -1);
00322 template <class A1, class A2, class A3>
00323 void route(action_t action = ACCEPT, int index = -1);
00324
00325 void unroute(action_t action = ACCEPT);
00326 template <class A1>
00327 void unroute(action_t action = ACCEPT);
00328 template <class A1, class A2>
00329 void unroute(action_t action = ACCEPT);
00330 template <class A1, class A2, class A3>
00331 void unroute(action_t action = ACCEPT);
00332
00333 # endif
00334
00335
00336
00338 struct InvalidStreamException : public senf::Exception
00339 { InvalidStreamException()
00340 : senf::Exception("senf::log::Target::InvalidStreamException") {} };
00341
00343 struct InvalidAreaException : public senf::Exception
00344 { InvalidAreaException()
00345 : senf::Exception("senf::log::Target::InvalidAreaException") {} };
00346
00347 iterator begin() const;
00348 iterator end() const;
00349
00350 RoutingEntry const & operator[](size_type i) const;
00351
00352 size_type size() const;
00353 bool empty() const;
00354
00355 void flush();
00356
00357 senf::console::ScopedDirectory<> & consoleDir();
00358
00359 private:
00360 void route(detail::StreamBase const * stream, detail::AreaBase const * area,
00361 unsigned level, action_t action, int index);
00362 void unroute(detail::StreamBase const * stream, detail::AreaBase const * area,
00363 unsigned level, action_t action);
00364
00365 void updateRoutingCache(detail::StreamBase const * stream, detail::AreaBase const * area);
00366
00367 void write(time_type timestamp, detail::StreamBase const & stream,
00368 detail::AreaBase const & area, unsigned level, std::string const & message);
00369
00370 void consoleList(std::ostream & os);
00371 void consoleRoute(int index, detail::LogParameters const & pm, action_t action);
00372 void consoleUnroute(detail::LogParameters const & pm, action_t action);
00373
00374 # ifdef DOXYGEN
00375 protected:
00376 # endif
00377
00378 virtual void v_write(time_type timestamp, std::string const & stream,
00379 std::string const & area, unsigned level,
00380 std::string const & message) = 0;
00382
00399 # ifdef DOXYGEN
00400 private:
00401 # endif
00402
00403 RIB rib_;
00404
00405 console::LazyDirectory consoleDir_;
00406
00407 friend class detail::AreaBase;
00408 friend class detail::TargetRegistry;
00409 };
00410
00414 std::ostream & operator<<(std::ostream & os, Target::action_t const & action);
00415
00416 }}
00417
00418
00419 #include "Target.cci"
00420
00421 #include "Target.cti"
00422 #endif
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433