SyslogUDPTarget.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Utils_Logger_SyslogUDPTarget_
18 #define HH_SENF_Utils_Logger_SyslogUDPTarget_ 1
19 
20 // Custom includes
21 #include <syslog.h>
27 #include "LogFormat.hh"
28 #include "Target.hh"
29 
30 //#include "SyslogUDPTarget.mpp"
31 //-/////////////////////////////////////////////////////////////////////////////////////////////////
32 
33 namespace senf {
34 namespace log {
35 
85  : public Target, private detail::LogFormat
86  {
87  public:
88  //-////////////////////////////////////////////////////////////////////////
89  // Types
90 
91  //-////////////////////////////////////////////////////////////////////////
93  //\{
94 
95  explicit SyslogUDPTarget(INet4Address const & target, int facility = LOG_USER);
96  explicit SyslogUDPTarget(INet4SocketAddress const & target, int facility = LOG_USER);
97  explicit SyslogUDPTarget(INet6Address const & target, int facility = LOG_USER);
98  explicit SyslogUDPTarget(INet6SocketAddress const & target, int facility = LOG_USER);
99 
100  //\}
101  //-////////////////////////////////////////////////////////////////////////
102 
109 
110  bool syslog() const;
111 
114  void syslog(bool enabled=true);
115 
116  private:
117  void init();
118  void v_write(time_type timestamp, std::string const & stream,
119  std::string const & area, unsigned level,
120  std::string const & message);
121 
122  void consoleFormat(std::ostream & os);
123 
124  int facility_;
128  senf::WriteablePolicy>::policy > Handle;
129  Handle handle_;
130  bool syslogFormat_;
131 
132  public:
133  enum LogFacility {
134  AUTHPRIV = LOG_AUTHPRIV,
135  CRON = LOG_CRON,
136  DAEMON = LOG_DAEMON,
137  FTP = LOG_FTP,
138  KERN = LOG_KERN,
139  LOCAL0 = LOG_LOCAL0,
140  LOCAL1 = LOG_LOCAL1,
141  LOCAL2 = LOG_LOCAL2,
142  LOCAL3 = LOG_LOCAL3,
143  LOCAL4 = LOG_LOCAL4,
144  LOCAL5 = LOG_LOCAL5,
145  LOCAL6 = LOG_LOCAL6,
146  LOCAL7 = LOG_LOCAL7,
147  LPR = LOG_LPR,
148  MAIL = LOG_MAIL,
149  NEWS = LOG_NEWS,
150  SYSLOG = LOG_SYSLOG,
151  USER = LOG_USER,
152  UUCP = LOG_UUCP
153  };
154 
155  private:
156 
157  struct RegisterConsole {
158  RegisterConsole();
159  static boost::shared_ptr<console::DirectoryNode> create(
160  INet4SocketAddress const & target, LogFacility facility = USER);
161  static boost::shared_ptr<console::DirectoryNode> create(
162  INet4Address const & target, LogFacility facility = USER);
163  static boost::shared_ptr<console::DirectoryNode> create(
164  INet6SocketAddress const & target, LogFacility facility = USER);
165  static boost::shared_ptr<console::DirectoryNode> create(
166  INet6Address const & target, LogFacility facility = USER);
167  static RegisterConsole instance;
168  };
169  };
170 
171 }}
172 
173 //-/////////////////////////////////////////////////////////////////////////////////////////////////
174 #include "SyslogUDPTarget.cci"
175 //#include "SyslogUDPTarget.ct"
176 //#include "SyslogUDPTarget.cti"
177 #endif
178 
179 
180 // Local Variables:
181 // mode: c++
182 // fill-column: 100
183 // comment-column: 40
184 // c-file-style: "senf"
185 // indent-tabs-mode: nil
186 // ispell-local-dictionary: "american"
187 // compile-command: "scons -u test"
188 // End:
void showStream(bool flag=true)
Enable or disable output of stream field.
void showLevel(bool flag=true)
Enable or disable output of log level.
bool syslog() const
true, if using syslog format, false otherwise
void timeFormat(std::string const &format)
Set time format.
Definition: LogFormat.cc:94
Log target writing UDP syslog packets.
void showTime(bool flag=true)
Enable or disable output of time field.
LogFormat public header.
void showArea(bool flag=true)
Enable or disable output of log area.
config::time_type time_type
Definition: TimeSource.hh:31
void tag(std::string const &tag)
Set tag (log line prefix)
Logging target base class.
Definition: Target.hh:133
SyslogUDPTarget(INet4Address const &target, int facility=LOG_USER)
Target public header.