log4cplus  2.0.5
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)
113  void appendLocal(const spi::InternalLoggingEvent& event);
115 #endif
116  void appendRemote(const spi::InternalLoggingEvent& event);
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_
log4cplus::helpers::Socket
This class implements client sockets (also called just "sockets").
Definition: helpers/socket.h:84
log4cplus
Definition: appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition: tstring.h:39
log4cplus::helpers::SharedObjectPtr
Definition: pointer.h:101
log4cplus::SysLogAppender::appendFunc
AppendFuncType appendFunc
Definition: syslogappender.h:125
log4cplus::SysLogAppender::connected
bool connected
Definition: syslogappender.h:131
log4cplus::SysLogAppender::remoteSyslogType
RemoteSyslogType remoteSyslogType
Definition: syslogappender.h:129
log4cplus::SysLogAppender::ctcSetConnected
virtual void ctcSetConnected()
Sets connected flag to true in ConnectorThread's client.
log4cplus::SysLogAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::SysLogAppender
Appends log events to a file.
Definition: syslogappender.h:85
log4cplus::SysLogAppender::initConnector
void initConnector()
log4cplus::SysLogAppender::ctcConnect
virtual helpers::Socket ctcConnect()
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const tstring &ident)
config.hxx
log4cplus::helpers::Properties
Definition: property.h:43
log4cplus::SysLogAppender::facility
int facility
Definition: syslogappender.h:121
socket.h
log4cplus::SysLogAppender::host
tstring host
Definition: syslogappender.h:127
connectorthread.h
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const log4cplus::helpers::Properties &properties)
log4cplus::SysLogAppender::remoteTimeFormat
static tstring const remoteTimeFormat
Definition: syslogappender.h:134
log4cplus::SysLogAppender::syslogSocket
helpers::Socket syslogSocket
Definition: syslogappender.h:130
log4cplus::LogLevel
int LogLevel
Definition: loglevel.h:48
log4cplus::SysLogAppender::ctcGetAccessMutex
virtual thread::Mutex const & ctcGetAccessMutex() const
log4cplus::SysLogAppender::port
int port
Definition: syslogappender.h:128
log4cplus::SysLogAppender::ctcGetSocket
virtual helpers::Socket & ctcGetSocket()
log4cplus::SysLogAppender::openSocket
void openSocket()
log4cplus::SysLogAppender::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::SysLogAppender::connector
helpers::SharedObjectPtr< helpers::ConnectorThread > connector
Definition: syslogappender.h:145
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition: loggingevent.h:51
log4cplus::helpers::IConnectorThreadClient
Interface implemented by users of ConnectorThread.
Definition: connectorthread.h:48
log4cplus::SysLogAppender::getSysLogLevel
virtual int getSysLogLevel(const LogLevel &ll) const
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::SysLogAppender::ident
tstring ident
Definition: syslogappender.h:120
log4cplus::SysLogAppender::~SysLogAppender
virtual ~SysLogAppender()
appender.h
log4cplus::Appender
Extend this class for implementing your own strategies for printing log statements.
Definition: appender.h:139
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const tstring &ident, const tstring &host, int port=514, const tstring &facility=tstring(), RemoteSyslogType remoteSyslogType=RSTUdp, bool ipv6=false)
log4cplus::thread::Mutex
Definition: syncprims.h:64
log4cplus::SysLogAppender::RSTUdp
@ RSTUdp
Definition: syslogappender.h:90
log4cplus::SysLogAppender::RemoteSyslogType
RemoteSyslogType
Remote syslog IP protocol type.
Definition: syslogappender.h:89