log4cplus  2.1.0
syslogappender.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Module: Log4CPLUS
3 // File: syslogappender.h
4 // Created: 6/2001
5 // Author: Tad E. Smith
6 //
7 //
8 // Copyright 2001-2017 Tad E. Smith
9 //
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
13 //
14 // http://www.apache.org/licenses/LICENSE-2.0
15 //
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 
24 #ifndef LOG4CPLUS_SYSLOG_APPENDER_HEADER_
25 #define LOG4CPLUS_SYSLOG_APPENDER_HEADER_
26 
27 #include <log4cplus/config.hxx>
28 
29 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
30 #pragma once
31 #endif
32 
33 #include <log4cplus/appender.h>
36 
37 
38 namespace log4cplus
39 {
40 
85  : public Appender
86 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
87  , protected virtual helpers::IConnectorThreadClient
88 #endif
89  {
90  public:
93  {
95  RSTTcp
96  };
97 
98  // Ctors
99 #if defined (LOG4CPLUS_HAVE_SYSLOG_H)
100  SysLogAppender(const tstring& ident);
101 #endif
102  SysLogAppender(const tstring& ident, const tstring & host,
103  int port = 514, const tstring & facility = tstring (),
104  RemoteSyslogType remoteSyslogType = RSTUdp, bool ipv6 = false);
105  SysLogAppender(const tstring& ident, const tstring & host,
106  int port, const tstring & facility,
107  RemoteSyslogType remoteSyslogType, bool ipv6, bool fqdn);
109 
110  // Dtor
111  virtual ~SysLogAppender();
112 
113  // Methods
114  virtual void close();
115 
116  protected:
117  virtual int getSysLogLevel(const LogLevel& ll) const;
118  virtual void append(const spi::InternalLoggingEvent& event);
119 #if defined (LOG4CPLUS_HAVE_SYSLOG_H)
122 #endif
125 
126  // Data
128  int facility;
129 
130  typedef void (SysLogAppender:: * AppendFuncType) (
132  AppendFuncType appendFunc;
133 
135  int port;
138  bool connected;
139  bool ipv6 = false;
140 
141  static tstring const remoteTimeFormat;
142 
143  void initConnector ();
144  void openSocket ();
145 
146 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
147  virtual thread::Mutex const & ctcGetAccessMutex () const;
150  virtual void ctcSetConnected ();
151 
153 #endif
154 
155  private:
156  // Disallow copying of instances of this class
158  SysLogAppender& operator=(const SysLogAppender&);
159 
160  std::string identStr;
161  tstring hostname;
162  };
163 
164 } // end namespace log4cplus
165 
166 
167 #endif // LOG4CPLUS_SYSLOG_APPENDER_HEADER_
Extend this class for implementing your own strategies for printing log statements.
Definition: appender.h:139
Appends log events to a file.
virtual void ctcSetConnected()
Sets connected flag to true in ConnectorThread's client.
virtual thread::Mutex const & ctcGetAccessMutex() const
SysLogAppender(const log4cplus::helpers::Properties &properties)
RemoteSyslogType
Remote syslog IP protocol type.
void appendLocal(const spi::InternalLoggingEvent &event)
Local syslog (served by syslog()) worker function.
void appendRemote(const spi::InternalLoggingEvent &event)
Remote syslog worker function.
virtual int getSysLogLevel(const LogLevel &ll) const
SysLogAppender(const tstring &ident)
SysLogAppender(const tstring &ident, const tstring &host, int port=514, const tstring &facility=tstring(), RemoteSyslogType remoteSyslogType=RSTUdp, bool ipv6=false)
virtual helpers::Socket ctcConnect()
static tstring const remoteTimeFormat
helpers::Socket syslogSocket
RemoteSyslogType remoteSyslogType
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
SysLogAppender(const tstring &ident, const tstring &host, int port, const tstring &facility, RemoteSyslogType remoteSyslogType, bool ipv6, bool fqdn)
virtual helpers::Socket & ctcGetSocket()
helpers::SharedObjectPtr< helpers::ConnectorThread > connector
Interface implemented by users of ConnectorThread.
This class implements client sockets (also called just "sockets").
The internal representation of logging events.
Definition: loggingevent.h:51
std::basic_string< tchar > tstring
Definition: tstring.h:39
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition: loglevel.h:48
#define LOG4CPLUS_EXPORT
Definition: win32.h:141