Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

SyslogUDPTarget.hh

Go to the documentation of this file.
00001 // $Id: SyslogUDPTarget.hh 1772 2011-03-10 12:45:21Z tho $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Utils_Logger_SyslogUDPTarget_
00027 #define HH_SENF_Utils_Logger_SyslogUDPTarget_ 1
00028 
00029 // Custom includes
00030 #include <syslog.h>
00031 #include "LogFormat.hh"
00032 #include "Target.hh"
00033 #include <senf/Socket/Protocols/INet/INetAddressing.hh>
00034 #include <senf/Socket/ClientSocketHandle.hh>
00035 #include <senf/Socket/FramingPolicy.hh>
00036 #include <senf/Socket/ReadWritePolicy.hh>
00037 #include <senf/Socket/CommunicationPolicy.hh>
00038 
00039 //#include "SyslogUDPTarget.mpp"
00040 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00041 
00042 namespace senf {
00043 namespace log {
00044 
00093     class SyslogUDPTarget
00094         : public Target, private detail::LogFormat
00095     {
00096     public:
00097         //-////////////////////////////////////////////////////////////////////////
00098         // Types
00099 
00100         //-////////////////////////////////////////////////////////////////////////
00102         //\{
00103 
00104         explicit SyslogUDPTarget(INet4Address const & target, int facility = LOG_USER);
00105         explicit SyslogUDPTarget(INet4SocketAddress const & target, int facility = LOG_USER);
00106         explicit SyslogUDPTarget(INet6Address const & target, int facility = LOG_USER);
00107         explicit SyslogUDPTarget(INet6SocketAddress const & target, int facility = LOG_USER);
00108 
00109         //\}
00110         //-////////////////////////////////////////////////////////////////////////
00111 
00112         using detail::LogFormat::showTime;
00113         using detail::LogFormat::showStream;
00114         using detail::LogFormat::showLevel;
00115         using detail::LogFormat::showArea;
00116         using detail::LogFormat::timeFormat;
00117         using detail::LogFormat::tag;
00118 
00119         bool syslog() const;            
00120 
00123         void syslog(bool enabled=true); 
00124 
00125     private:
00126         void init();
00127         void v_write(time_type timestamp, std::string const & stream,
00128                      std::string const & area, unsigned level,
00129                      std::string const & message);
00130 
00131         void consoleFormat(std::ostream & os);
00132 
00133         int facility_;
00134         typedef senf::ClientSocketHandle< senf::MakeSocketPolicy<
00135             senf::DatagramFramingPolicy,
00136             senf::ConnectedCommunicationPolicy,
00137             senf::WriteablePolicy>::policy > Handle;
00138         Handle handle_;
00139         bool syslogFormat_;
00140 
00141     public:
00142         enum LogFacility {
00143             AUTHPRIV = LOG_AUTHPRIV,
00144             CRON = LOG_CRON,
00145             DAEMON = LOG_DAEMON,
00146             FTP = LOG_FTP,
00147             KERN = LOG_KERN,
00148             LOCAL0 = LOG_LOCAL0,
00149             LOCAL1 = LOG_LOCAL1,
00150             LOCAL2 = LOG_LOCAL2,
00151             LOCAL3 = LOG_LOCAL3,
00152             LOCAL4 = LOG_LOCAL4,
00153             LOCAL5 = LOG_LOCAL5,
00154             LOCAL6 = LOG_LOCAL6,
00155             LOCAL7 = LOG_LOCAL7,
00156             LPR = LOG_LPR,
00157             MAIL = LOG_MAIL,
00158             NEWS = LOG_NEWS,
00159             SYSLOG = LOG_SYSLOG,
00160             USER = LOG_USER,
00161             UUCP = LOG_UUCP
00162         };
00163 
00164     private:
00165 
00166         struct RegisterConsole {
00167             RegisterConsole();
00168             static boost::shared_ptr<console::DirectoryNode> create(
00169                 INet4SocketAddress const & target, LogFacility facility = USER);
00170             static boost::shared_ptr<console::DirectoryNode> create(
00171                 INet4Address const & target, LogFacility facility = USER);
00172             static boost::shared_ptr<console::DirectoryNode> create(
00173                 INet6SocketAddress const & target, LogFacility facility = USER);
00174             static boost::shared_ptr<console::DirectoryNode> create(
00175                 INet6Address const & target, LogFacility facility = USER);
00176             static RegisterConsole instance;
00177         };
00178     };
00179 
00180 }}
00181 
00182 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00183 #include "SyslogUDPTarget.cci"
00184 //#include "SyslogUDPTarget.ct"
00185 //#include "SyslogUDPTarget.cti"
00186 #endif
00187 
00188 
00189 // Local Variables:
00190 // mode: c++
00191 // fill-column: 100
00192 // comment-column: 40
00193 // c-file-style: "senf"
00194 // indent-tabs-mode: nil
00195 // ispell-local-dictionary: "american"
00196 // compile-command: "scons -u test"
00197 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research