Coverage Report

Created: 2025-08-24 06:21

/src/logging-log4cxx/src/main/include/log4cxx/net/syslogappender.h
Line
Count
Source (jump to first uncovered line)
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
namespace LOG4CXX_NS
25
{
26
namespace net
27
{
28
/**
29
 * Use SyslogAppender to send log messages to a remote syslog daemon.
30
 *
31
 * Note that by default, this appender will split up messages that are
32
 * more than 1024 bytes long, for compatability with BSD syslog(see
33
 * RFC 3164).  Modern syslog implementations(e.g. syslog-ng) can accept
34
 * messages much larger, and may have a default of 8k.  You may modify
35
 * the default size of the messages by setting the MaxMessageLength option.
36
 *
37
 * When the message is too large for the current MaxMessageLength,
38
 * the packet number and total # will be appended to the end of the
39
 * message like this: (5/10)
40
 */
41
class LOG4CXX_EXPORT SyslogAppender : public AppenderSkeleton
42
{
43
  public:
44
    DECLARE_LOG4CXX_OBJECT(SyslogAppender)
45
0
    BEGIN_LOG4CXX_CAST_MAP()
46
0
    LOG4CXX_CAST_ENTRY(SyslogAppender)
47
0
    LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton)
48
0
    END_LOG4CXX_CAST_MAP()
49
50
51
52
    SyslogAppender();
53
    SyslogAppender(const LayoutPtr& layout, int syslogFacility);
54
    SyslogAppender(const LayoutPtr& layout,
55
      const LogString& syslogHost, int syslogFacility);
56
    ~SyslogAppender();
57
    /** Release any resources held by this SyslogAppender.*/
58
    void close() override;
59
60
    /**
61
    Returns the specified syslog facility as a lower-case String,
62
    e.g. "kern", "user", etc.
63
    */
64
    static LogString getFacilityString(int syslogFacility);
65
66
    /**
67
    Returns the integer value corresponding to the named syslog
68
    facility, or -1 if it couldn't be recognized.
69
    @param facilityName one of the strings KERN, USER, MAIL, DAEMON,
70
    AUTH, SYSLOG, LPR, NEWS, UUCP, CRON, AUTHPRIV, FTP, LOCAL0,
71
    LOCAL1, LOCAL2, LOCAL3, LOCAL4, LOCAL5, LOCAL6, LOCAL7.
72
    The matching is case-insensitive.
73
    */
74
    static int getFacility(const LogString& facilityName);
75
76
    void append(const spi::LoggingEventPtr& event, helpers::Pool& p) override;
77
78
    /**
79
    \copybrief AppenderSkeleton::activateOptions()
80
81
    No action is performed in this implementation.
82
    */
83
    void activateOptions(helpers::Pool& p) override;
84
85
    /**
86
    \copybrief AppenderSkeleton::setOption()
87
88
    Supported options | Supported values | Default value |
89
    -------------- | ---------------- | --------------- |
90
    SysLogHost |  (\ref sysLogAddress "1") | - |
91
    Facility | (\ref facility "2") | - |
92
    MaxMessageLength | {int} | 1024 |
93
94
    \anchor sysLogAddress (1) A valid internet address, optionally with the port number as a suffix after a ':'.
95
96
    \anchor facility (2) One of kern,user,mail,daemon,auth,syslog,lpr,news,uucp,cron,ftp,local0,local1,local2,local3,local4,local5,local6,local7
97
98
    \sa AppenderSkeleton::setOption()
99
    */
100
    void setOption(const LogString& option, const LogString& value) override;
101
102
    /**
103
    The SyslogAppender requires a layout. Hence, this method returns
104
    <code>true</code>.
105
    */
106
    bool requiresLayout() const override
107
0
    {
108
0
      return true;
109
0
    }
110
111
    /**
112
    The <b>SyslogHost</b> option is the name of the the syslog host
113
    where log output should go.
114
    <b>WARNING</b> If the SyslogHost is not set, then this appender
115
    will fail.
116
    */
117
    void setSyslogHost(const LogString& syslogHost);
118
119
    /**
120
    Returns the value of the <b>SyslogHost</b> option.
121
    */
122
    const LogString& getSyslogHost() const;
123
124
    /**
125
    Set the syslog facility. This is the <b>Facility</b> option.
126
127
    <p>The <code>facilityName</code> parameter must be one of the
128
    strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP,
129
    CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4,
130
    LOCAL5, LOCAL6, LOCAL7. Case is unimportant.
131
    */
132
    void setFacility(const LogString& facilityName);
133
134
    /**
135
    Returns the value of the <b>Facility</b> option.
136
    */
137
    LogString getFacility() const;
138
139
    /**
140
    If the <b>FacilityPrinting</b> option is set to true, the printed
141
    message will include the facility name of the application. It is
142
    <em>false</em> by default.
143
    */
144
    void setFacilityPrinting(bool facilityPrinting1);
145
146
    /**
147
    Returns the value of the <b>FacilityPrinting</b> option.
148
    */
149
    bool getFacilityPrinting() const;
150
151
    void setMaxMessageLength(int maxMessageLength1);
152
153
    int getMaxMessageLength() const;
154
155
  protected:
156
    void initSyslogFacilityStr();
157
158
  private:
159
    struct SyslogAppenderPriv;
160
    SyslogAppender(const SyslogAppender&);
161
    SyslogAppender& operator=(const SyslogAppender&);
162
}; // class SyslogAppender
163
LOG4CXX_PTR_DEF(SyslogAppender);
164
} // namespace net
165
} // namespace log4cxx
166
167
#endif // _LOG4CXX_NET_SYSLOG_APPENDER_H
168