log4cplus  2.0.8
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 
81  : public Appender
82 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
83  , protected virtual helpers::IConnectorThreadClient
84 #endif
85  {
86  public:
89  {
91  RSTTcp
92  };
93 
94  // Ctors
95 #if defined (LOG4CPLUS_HAVE_SYSLOG_H)
96  SysLogAppender(const tstring& ident);
97 #endif
98  SysLogAppender(const tstring& ident, const tstring & host,
99  int port = 514, const tstring & facility = tstring (),
100  RemoteSyslogType remoteSyslogType = RSTUdp, bool ipv6 = false);
102 
103  // Dtor
104  virtual ~SysLogAppender();
105 
106  // Methods
107  virtual void close();
108 
109  protected:
110  virtual int getSysLogLevel(const LogLevel& ll) const;
111  virtual void append(const spi::InternalLoggingEvent& event);
112 #if defined (LOG4CPLUS_HAVE_SYSLOG_H)
115 #endif
118 
119  // Data
121  int facility;
122 
123  typedef void (SysLogAppender:: * AppendFuncType) (
125  AppendFuncType appendFunc;
126 
128  int port;
131  bool connected;
132  bool ipv6 = false;
133 
134  static tstring const remoteTimeFormat;
135 
136  void initConnector ();
137  void openSocket ();
138 
139 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
140  virtual thread::Mutex const & ctcGetAccessMutex () const;
143  virtual void ctcSetConnected ();
144 
146 #endif
147 
148  private:
149  // Disallow copying of instances of this class
151  SysLogAppender& operator=(const SysLogAppender&);
152 
153  std::string identStr;
154  tstring hostname;
155  };
156 
157 } // end namespace log4cplus
158 
159 
160 #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.
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