Apache log4cxx  Version 0.11.0
syslogappender.h
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _LOG4CXX_NET_SYSLOG_APPENDER_H
19 #define _LOG4CXX_NET_SYSLOG_APPENDER_H
20 
21 #include <log4cxx/appenderskeleton.h>
22 #include <log4cxx/helpers/syslogwriter.h>
23 
24 #if defined(_MSC_VER)
25  #pragma warning ( push )
26  #pragma warning ( disable: 4251 )
27 #endif
28 
29 namespace log4cxx
30 {
31 namespace net
32 {
34 class LOG4CXX_EXPORT SyslogAppender : public AppenderSkeleton
35 {
36  public:
37  DECLARE_LOG4CXX_OBJECT(SyslogAppender)
38  BEGIN_LOG4CXX_CAST_MAP()
39  LOG4CXX_CAST_ENTRY(SyslogAppender)
40  LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
41  END_LOG4CXX_CAST_MAP()
42 
43 
44 
46  SyslogAppender(const LayoutPtr& layout, int syslogFacility);
47  SyslogAppender(const LayoutPtr& layout,
48  const LogString& syslogHost, int syslogFacility);
49  ~SyslogAppender();
51  void close();
52 
57  static LogString getFacilityString(int syslogFacility);
58 
67  static int getFacility(const LogString& facilityName);
68 
69  void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p);
70 
75  void activateOptions(log4cxx::helpers::Pool& p);
76  void setOption(const LogString& option, const LogString& value);
77 
82  virtual bool requiresLayout() const
83  {
84  return true;
85  }
86 
93  void setSyslogHost(const LogString& syslogHost);
94 
98  inline const LogString& getSyslogHost() const
99  {
100  return syslogHost;
101  }
102 
111  void setFacility(const LogString& facilityName);
112 
116  inline LogString getFacility() const
117  {
118  return getFacilityString(syslogFacility);
119  }
120 
126  inline void setFacilityPrinting(bool facilityPrinting1)
127  {
128  this->facilityPrinting = facilityPrinting1;
129  }
130 
134  inline bool getFacilityPrinting() const
135  {
136  return facilityPrinting;
137  }
138 
139  protected:
140  void initSyslogFacilityStr();
141 
142  int syslogFacility; // Have LOG_USER as default
143  LogString facilityStr;
144  bool facilityPrinting;
146  LogString syslogHost;
147  int syslogHostPort;
148  private:
150  SyslogAppender& operator=(const SyslogAppender&);
151 }; // class SyslogAppender
152 LOG4CXX_PTR_DEF(SyslogAppender);
153 } // namespace net
154 } // namespace log4cxx
155 
156 #if defined(_MSC_VER)
157  #pragma warning (pop)
158 #endif
159 
160 #endif // _LOG4CXX_NET_SYSLOG_APPENDER_H
161 
const LogString & getSyslogHost() const
Returns the value of the SyslogHost option.
Definition: syslogappender.h:98
Implementation base class for all appenders.
Definition: appenderskeleton.h:45
SyslogWriter is a wrapper around the DatagramSocket class it writes text to the specified host on the...
Definition: syslogwriter.h:39
void setFacilityPrinting(bool facilityPrinting1)
If the FacilityPrinting option is set to true, the printed message will include the facility name of ...
Definition: syslogappender.h:126
bool getFacilityPrinting() const
Returns the value of the FacilityPrinting option.
Definition: syslogappender.h:134
Definition: pool.h:32
Use SyslogAppender to send log messages to a remote syslog daemon.
Definition: syslogappender.h:34
LogString getFacility() const
Returns the value of the Facility option.
Definition: syslogappender.h:116
virtual bool requiresLayout() const
The SyslogAppender requires a layout.
Definition: syslogappender.h:82
Definition: appender.h:33