syslogappender.h
Go to the documentation of this file.
// -*- C++ -*-
// Module: Log4CPLUS
// File: syslogappender.h
// Created: 6/2001
// Author: Tad E. Smith
//
//
// Copyright 2001-2017 Tad E. Smith
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef LOG4CPLUS_SYSLOG_APPENDER_HEADER_
#define LOG4CPLUS_SYSLOG_APPENDER_HEADER_
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#include <log4cplus/appender.h>
#include <log4cplus/helpers/socket.h>
#include <log4cplus/helpers/connectorthread.h>
namespace log4cplus
{
class LOG4CPLUS_EXPORT SysLogAppender
: public Appender
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
, protected virtual helpers::IConnectorThreadClient
#endif
{
public:
enum RemoteSyslogType
{
RSTUdp,
RSTTcp
};
// Ctors
#if defined (LOG4CPLUS_HAVE_SYSLOG_H)
SysLogAppender(const tstring& ident);
#endif
SysLogAppender(const tstring& ident, const tstring & host,
int port = 514, const tstring & facility = tstring (),
RemoteSyslogType remoteSyslogType = RSTUdp, bool ipv6 = false);
SysLogAppender(const tstring& ident, const tstring & host,
int port, const tstring & facility,
RemoteSyslogType remoteSyslogType, bool ipv6, bool fqdn);
SysLogAppender(const log4cplus::helpers::Properties & properties);
// Dtor
virtual ~SysLogAppender();
// Methods
virtual void close();
protected:
virtual int getSysLogLevel(const LogLevel& ll) const;
virtual void append(const spi::InternalLoggingEvent& event);
#if defined (LOG4CPLUS_HAVE_SYSLOG_H)
void appendLocal(const spi::InternalLoggingEvent& event);
#endif
void appendRemote(const spi::InternalLoggingEvent& event);
// Data
tstring ident;
int facility;
typedef void (SysLogAppender:: * AppendFuncType) (
const spi::InternalLoggingEvent&);
AppendFuncType appendFunc;
tstring host;
int port;
RemoteSyslogType remoteSyslogType;
helpers::Socket syslogSocket;
bool connected;
bool ipv6 = false;
static tstring const remoteTimeFormat;
void initConnector ();
void openSocket ();
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
virtual thread::Mutex const & ctcGetAccessMutex () const;
virtual helpers::Socket & ctcGetSocket ();
virtual helpers::Socket ctcConnect ();
virtual void ctcSetConnected ();
helpers::SharedObjectPtr<helpers::ConnectorThread> connector;
#endif
private:
// Disallow copying of instances of this class
SysLogAppender(const SysLogAppender&);
SysLogAppender& operator=(const SysLogAppender&);
std::string identStr;
tstring hostname;
};
} // end namespace log4cplus
#endif // LOG4CPLUS_SYSLOG_APPENDER_HEADER_
appender.h
log4cplus::Appender::Appender
Appender()
log4cplus::SysLogAppender::ctcSetConnected
virtual void ctcSetConnected()
Sets connected flag to true in ConnectorThread's client.
log4cplus::SysLogAppender::appendFunc
AppendFuncType appendFunc
Definition syslogappender.h:132
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const log4cplus::helpers::Properties &properties)
log4cplus::SysLogAppender::ident
tstring ident
Definition syslogappender.h:127
log4cplus::SysLogAppender::RemoteSyslogType
RemoteSyslogType
Remote syslog IP protocol type.
Definition syslogappender.h:93
log4cplus::SysLogAppender::RSTTcp
@ RSTTcp
Definition syslogappender.h:95
log4cplus::SysLogAppender::RSTUdp
@ RSTUdp
Definition syslogappender.h:94
log4cplus::SysLogAppender::~SysLogAppender
virtual ~SysLogAppender()
log4cplus::SysLogAppender::initConnector
void initConnector()
log4cplus::SysLogAppender::appendLocal
void appendLocal(const spi::InternalLoggingEvent &event)
Local syslog (served by syslog()) worker function.
log4cplus::SysLogAppender::connected
bool connected
Definition syslogappender.h:138
log4cplus::SysLogAppender::facility
int facility
Definition syslogappender.h:128
log4cplus::SysLogAppender::appendRemote
void appendRemote(const spi::InternalLoggingEvent &event)
Remote syslog worker function.
log4cplus::SysLogAppender::port
int port
Definition syslogappender.h:135
log4cplus::SysLogAppender::getSysLogLevel
virtual int getSysLogLevel(const LogLevel &ll) const
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const tstring &ident)
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const tstring &ident, const tstring &host, int port=514, const tstring &facility=tstring(), RemoteSyslogType remoteSyslogType=RSTUdp, bool ipv6=false)
log4cplus::SysLogAppender::ctcConnect
virtual helpers::Socket ctcConnect()
log4cplus::SysLogAppender::remoteTimeFormat
static tstring const remoteTimeFormat
Definition syslogappender.h:141
log4cplus::SysLogAppender::host
tstring host
Definition syslogappender.h:134
log4cplus::SysLogAppender::syslogSocket
helpers::Socket syslogSocket
Definition syslogappender.h:137
log4cplus::SysLogAppender::openSocket
void openSocket()
log4cplus::SysLogAppender::AppendFuncType
void(SysLogAppender::* AppendFuncType)(const spi::InternalLoggingEvent &)
Definition syslogappender.h:130
log4cplus::SysLogAppender::remoteSyslogType
RemoteSyslogType remoteSyslogType
Definition syslogappender.h:136
log4cplus::SysLogAppender::close
virtual void close()
Release any resources allocated within the appender such as file handles, network connections,...
log4cplus::SysLogAppender::ipv6
bool ipv6
Definition syslogappender.h:139
log4cplus::SysLogAppender::append
virtual void append(const spi::InternalLoggingEvent &event)
Subclasses of Appender should implement this method to perform actual logging.
log4cplus::SysLogAppender::SysLogAppender
SysLogAppender(const tstring &ident, const tstring &host, int port, const tstring &facility, RemoteSyslogType remoteSyslogType, bool ipv6, bool fqdn)
log4cplus::SysLogAppender::ctcGetAccessMutex
virtual thread::Mutex const & ctcGetAccessMutex() const
log4cplus::SysLogAppender::ctcGetSocket
virtual helpers::Socket & ctcGetSocket()
log4cplus::SysLogAppender::connector
helpers::SharedObjectPtr< helpers::ConnectorThread > connector
Definition syslogappender.h:152
log4cplus::helpers::IConnectorThreadClient
Interface implemented by users of ConnectorThread.
Definition connectorthread.h:48
log4cplus::helpers::Properties
Definition property.h:43
log4cplus::helpers::SharedObjectPtr
Definition pointer.h:101
log4cplus::helpers::Socket
This class implements client sockets (also called just "sockets").
Definition helpers/socket.h:84
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
log4cplus::thread::Mutex
Definition syncprims.h:83
config.hxx
connectorthread.h
socket.h
log4cplus
Definition appender.h:46
log4cplus::tstring
std::basic_string< tchar > tstring
Definition tstring.h:39
log4cplus::LogLevel
int LogLevel
Defines the minimum set of priorities recognized by the system, that is FATAL_LOG_LEVEL,...
Definition loglevel.h:48
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141