Utils/Logger: Reorganize source code
[senf.git] / Utils / Logger / Target.hh
1 // $Id$
2 //
3 // Copyright (C) 2007 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief Target public header */
25
26 #ifndef HH_Target_
27 #define HH_Target_ 1
28
29 // Custom includes
30 #include "../singleton.hh"
31 #include "StreamRegistry.hh"
32 #include "AreaRegistry.hh"
33
34 //#include "Target.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38 namespace log {
39
40     /** \brief Logging target base class
41
42         All enabled log messages are eventually routed to one or more logging targets. It is the
43         responsibility of the logging target to write the log messages somewhere: onto the console,
44         to a file, to mail them to the administrator or whatever. To this end, the logging target is
45         passed the log message and a complete set of logging parameters (\e stream, \e area and \e
46         level).
47       */
48     class Target
49         : public senf::singleton<Target>
50     {
51     public:
52         ///////////////////////////////////////////////////////////////////////////
53         // Types
54
55         ///////////////////////////////////////////////////////////////////////////
56         ///\name Structors and default members
57         ///@{
58
59         virtual ~Target();
60
61         // default default constructor
62         // default copy constructor
63         // default copy assignment
64         // default destructor
65
66         // no conversion constructors
67
68         ///@}
69
70     protected:
71
72     private:
73
74         void route(detail::StreamBase const * stream, detail::AreaBase const * area, 
75                    unsigned level);
76         void unroute(detail::StreamBase const * stream, detail::AreaBase const * area, 
77                      unsigned level);
78
79         void updateAreaCache(detail::AreaBase const & area, detail::StreamBase const * stream,
80                              unsigned level);
81
82         void write(detail::StreamBase const & stream, detail::AreaBase const & area, 
83                    unsigned level, std::string const & message);
84         
85         virtual void v_write(std::string const & stream, std::string const & area, unsigned level,
86                              std::string const & message) = 0;
87
88         struct RoutingEntry 
89         {
90             RoutingEntry(detail::StreamBase const * stream_, detail::AreaBase const * area_, 
91                          unsigned level_)
92                 : stream(stream_), area(area_), level(level_) {}
93             RoutingEntry() 
94                 : stream(0), area(0), level(0) {}
95
96             bool operator==(RoutingEntry const & other) 
97                 { return stream == other.stream && area == other.area && level == other.level; }
98
99             detail::StreamBase const * stream;
100             detail::AreaBase const * area;
101             unsigned level;
102         };
103
104         typedef std::vector<RoutingEntry> RIB;
105
106         RIB rib_;
107     };
108
109 }}
110
111 ///////////////////////////////hh.e////////////////////////////////////////
112 #include "Target.cci"
113 //#include "Target.ct"
114 //#include "Target.cti"
115 #endif
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // fill-column: 100
121 // comment-column: 40
122 // c-file-style: "senf"
123 // indent-tabs-mode: nil
124 // ispell-local-dictionary: "american"
125 // compile-command: "scons -u test"
126 // End: