switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Utils / Logger / SyslogTarget.hh
1 // $Id$
2 //
3 // Copyright (C) 2008
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 //
6 // The contents of this file are subject to the Fraunhofer FOKUS Public License
7 // Version 1.0 (the "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at 
9 // http://senf.berlios.de/license.html
10 //
11 // The Fraunhofer FOKUS Public License Version 1.0 is based on, 
12 // but modifies the Mozilla Public License Version 1.1.
13 // See the full license text for the amendments.
14 //
15 // Software distributed under the License is distributed on an "AS IS" basis, 
16 // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
17 // for the specific language governing rights and limitations under the License.
18 //
19 // The Original Code is Fraunhofer FOKUS code.
20 //
21 // The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
22 // (registered association), Hansastraße 27 c, 80686 Munich, Germany.
23 // All Rights Reserved.
24 //
25 // Contributor(s):
26 //   Stefan Bund <g0dil@berlios.de>
27
28 /** \file
29     \brief SyslogTarget public header */
30
31 #ifndef HH_SENF_Utils_Logger_SyslogTarget_
32 #define HH_SENF_Utils_Logger_SyslogTarget_ 1
33
34 // Custom includes
35 #include <syslog.h>
36 #include <boost/shared_ptr.hpp>
37 #include "Target.hh"
38
39 //#include "SyslogTarget.mpp"
40 //-/////////////////////////////////////////////////////////////////////////////////////////////////
41
42 namespace senf {
43
44     namespace console { class DirectoryNode; }
45
46 namespace log {
47
48     /** \brief Log target writing to the syslog
49
50         The SyslogTarget will send all %log messages to the syslog at the given facility.
51
52         \code
53         senf::log::SyslogTarget syslog;
54
55         // Route all messages to the syslog
56         syslog.route();
57         \endcode
58
59         Valid facility values (taken from <tt>man 3 syslog</tt>):
60         \par ""
61            <tt>LOG_AUTHPRIV</tt>, <tt>LOG_CRON</tt>, <tt>LOG_DAEMON</tt>, <tt>LOG_FTP</tt>,
62            <tt>LOG_KERN</tt>, <tt>LOG_LOCAL0</tt>, <tt>LOG_LOCAL1</tt>, <tt>LOG_LOCAL2</tt>,
63            <tt>LOG_LOCAL3</tt>, <tt>LOG_LOCAL4</tt>, <tt>LOG_LOCAL5</tt>, <tt>LOG_LOCAL6</tt>,
64            <tt>LOG_LOCAL7</tt>, <tt>LOG_LPR</tt>, <tt>LOG_MAIL</tt>, <tt>LOG_NEWS</tt>,
65            <tt>LOG_SYSLOG</tt>, <tt>LOG_USER</tt>, <tt>LOG_UUCP</tt>
66
67         The default facility is <tt>LOG_USER</tt>.
68
69         The SENF log levels are mapped to syslog levels in the following way:
70
71         <table class="senf fixedcolumn">
72         <tr><td>senf::log::VERBOSE</td>   <td>\c LOG_DEBUG</td></tr>
73         <tr><td>senf::log::NOTICE</td>    <td>\c LOG_INFO</td></tr>
74         <tr><td>senf::log::MESSAGE</td>   <td>\c LOG_NOTICE</td></tr>
75         <tr><td>senf::log::IMPORTANT</td> <td>\c LOG_WARNING</td></tr>
76         <tr><td>senf::log::CRITICAL</td>  <td>\c LOG_CRIT</td></tr>
77         <tr><td>senf::log::FATAL</td>     <td>\c LOG_EMERG</td></tr>
78         </table>
79
80         \ingroup targets
81      */
82     class SyslogTarget
83         : public Target
84     {
85     public:
86         //-////////////////////////////////////////////////////////////////////////
87         ///\name Structors and default members
88         //\{
89
90         explicit SyslogTarget(int facility = LOG_USER);
91
92         //\}
93         //-////////////////////////////////////////////////////////////////////////
94
95     private:
96         void v_write(time_type timestamp, std::string const & stream,
97                      std::string const & area, unsigned level,
98                      std::string const & message);
99
100         int facility_;
101
102     public:
103         static int const LEVELMAP[8];
104
105         enum LogFacility {
106             AUTHPRIV = LOG_AUTHPRIV,
107             CRON = LOG_CRON,
108             DAEMON = LOG_DAEMON,
109             FTP = LOG_FTP,
110             KERN = LOG_KERN,
111             LOCAL0 = LOG_LOCAL0,
112             LOCAL1 = LOG_LOCAL1,
113             LOCAL2 = LOG_LOCAL2,
114             LOCAL3 = LOG_LOCAL3,
115             LOCAL4 = LOG_LOCAL4,
116             LOCAL5 = LOG_LOCAL5,
117             LOCAL6 = LOG_LOCAL6,
118             LOCAL7 = LOG_LOCAL7,
119             LPR = LOG_LPR,
120             MAIL = LOG_MAIL,
121             NEWS = LOG_NEWS,
122             SYSLOG = LOG_SYSLOG,
123             USER = LOG_USER,
124             UUCP = LOG_UUCP
125         };
126
127     private:
128         struct RegisterConsole {
129             RegisterConsole();
130             static boost::shared_ptr<console::DirectoryNode> create(
131                 LogFacility facility);
132             static RegisterConsole instance;
133         };
134     };
135
136 }}
137
138 //-/////////////////////////////////////////////////////////////////////////////////////////////////
139 #include "SyslogTarget.cci"
140 //#include "SyslogTarget.ct"
141 //#include "SyslogTarget.cti"
142 #endif
143
144 \f
145 // Local Variables:
146 // mode: c++
147 // fill-column: 100
148 // comment-column: 40
149 // c-file-style: "senf"
150 // indent-tabs-mode: nil
151 // ispell-local-dictionary: "american"
152 // compile-command: "scons -u test"
153 // End: