Coverage Report

Created: 2026-05-30 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/include/log4cxx/net/syslogappender.h
Line
Count
Source
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( LOG4CXX_APPEND_FORMAL_PARAMETERS ) override;
77
78
#if LOG4CXX_ABI_VERSION <= 15
79
    /**
80
    \copybrief AppenderSkeleton::activateOptions()
81
82
    No action is performed in this implementation.
83
    */
84
    void activateOptions(helpers::Pool& p) override;
85
#endif
86
    /**
87
    \copybrief AppenderSkeleton::setOption()
88
89
    Supported options | Supported values | Default value |
90
    -------------- | ---------------- | --------------- |
91
    SysLogHost |  (\ref sysLogAddress "1") | - |
92
    Facility | (\ref facility "2") | - |
93
    MaxMessageLength | {int} | 1024 |
94
95
    \anchor sysLogAddress (1) A valid internet address, optionally with the port number as a suffix after a ':'.
96
97
    \anchor facility (2) One of kern,user,mail,daemon,auth,syslog,lpr,news,uucp,cron,ftp,local0,local1,local2,local3,local4,local5,local6,local7
98
99
    \sa AppenderSkeleton::setOption()
100
    */
101
    void setOption(const LogString& option, const LogString& value) override;
102
103
    /**
104
    The SyslogAppender requires a layout. Hence, this method returns
105
    <code>true</code>.
106
    */
107
    bool requiresLayout() const override
108
0
    {
109
0
      return true;
110
0
    }
111
112
    /**
113
    The <b>SyslogHost</b> option is the name of the the syslog host
114
    where log output should go.
115
    <b>WARNING</b> If the SyslogHost is not set, then this appender
116
    will fail.
117
    */
118
    void setSyslogHost(const LogString& syslogHost);
119
120
    /**
121
    Returns the value of the <b>SyslogHost</b> option.
122
    */
123
    const LogString& getSyslogHost() const;
124
125
    /**
126
    Set the syslog facility. This is the <b>Facility</b> option.
127
128
    <p>The <code>facilityName</code> parameter must be one of the
129
    strings KERN, USER, MAIL, DAEMON, AUTH, SYSLOG, LPR, NEWS, UUCP,
130
    CRON, AUTHPRIV, FTP, LOCAL0, LOCAL1, LOCAL2, LOCAL3, LOCAL4,
131
    LOCAL5, LOCAL6, LOCAL7. Case is unimportant.
132
    */
133
    void setFacility(const LogString& facilityName);
134
135
    /**
136
    Returns the value of the <b>Facility</b> option.
137
    */
138
    LogString getFacility() const;
139
140
    /**
141
    If the <b>FacilityPrinting</b> option is set to true, the printed
142
    message will include the facility name of the application. It is
143
    <em>false</em> by default.
144
    */
145
    void setFacilityPrinting(bool facilityPrinting1);
146
147
    /**
148
    Returns the value of the <b>FacilityPrinting</b> option.
149
    */
150
    bool getFacilityPrinting() const;
151
152
    void setMaxMessageLength(int maxMessageLength1);
153
154
    int getMaxMessageLength() const;
155
156
  protected:
157
    void initSyslogFacilityStr();
158
159
  private:
160
    struct SyslogAppenderPriv;
161
    SyslogAppender(const SyslogAppender&);
162
    SyslogAppender& operator=(const SyslogAppender&);
163
}; // class SyslogAppender
164
LOG4CXX_PTR_DEF(SyslogAppender);
165
} // namespace net
166
} // namespace log4cxx
167
168
#endif // _LOG4CXX_NET_SYSLOG_APPENDER_H
169