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/cpp/xmlsocketappender.cpp
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
#include <log4cxx/net/xmlsocketappender.h>
19
#include <log4cxx/helpers/loglog.h>
20
#include <log4cxx/xml/xmllayout.h>
21
#include <log4cxx/private/socketappenderskeleton_priv.h>
22
23
using namespace LOG4CXX_NS;
24
using namespace LOG4CXX_NS::net;
25
26
#if LOG4CXX_ABI_VERSION <= 15
27
struct XMLSocketAppender::XMLSocketAppenderPriv : public SocketAppenderSkeletonPriv
28
{
29
  XMLSocketAppenderPriv(int defaultPort, int reconnectionDelay) :
30
0
    SocketAppenderSkeletonPriv(defaultPort, reconnectionDelay) {}
31
32
  XMLSocketAppenderPriv(helpers::InetAddressPtr address, int defaultPort, int reconnectionDelay) :
33
0
    SocketAppenderSkeletonPriv( address, defaultPort, reconnectionDelay ) {}
34
35
  XMLSocketAppenderPriv(const LogString& host, int port, int delay) :
36
0
    SocketAppenderSkeletonPriv( host, port, delay ) {}
37
38
  LOG4CXX_NS::helpers::WriterPtr unused_writer;
39
40
};
41
#endif
42
43
IMPLEMENT_LOG4CXX_OBJECT(XMLSocketAppender)
44
45
0
#define _priv static_cast<SocketAppenderSkeletonPriv*>(m_priv.get())
46
47
// The default port number of remote logging server (4560)
48
int XMLSocketAppender::DEFAULT_PORT                 = 4560;
49
50
// The default reconnection delay (30000 milliseconds or 30 seconds).
51
int XMLSocketAppender::DEFAULT_RECONNECTION_DELAY   = 30000;
52
53
#if LOG4CXX_ABI_VERSION <= 15
54
const int XMLSocketAppender::MAX_EVENT_LEN          = 1024;
55
#endif
56
57
XMLSocketAppender::XMLSocketAppender()
58
0
  : SocketAppenderSkeleton(std::make_unique<SocketAppenderSkeletonPriv>(DEFAULT_PORT, DEFAULT_RECONNECTION_DELAY))
59
0
{
60
0
  _priv->layout = std::make_shared<xml::XMLLayout>();
61
0
}
Unexecuted instantiation: log4cxx::net::XMLSocketAppender::XMLSocketAppender()
Unexecuted instantiation: log4cxx::net::XMLSocketAppender::XMLSocketAppender()
62
63
#if LOG4CXX_ABI_VERSION <= 15
64
XMLSocketAppender::XMLSocketAppender(helpers::InetAddressPtr address1, int port1)
65
#else
66
XMLSocketAppender::XMLSocketAppender(const helpers::InetAddressPtr& address1, int port1)
67
#endif
68
0
  : SocketAppenderSkeleton(std::make_unique<SocketAppenderSkeletonPriv>(address1, port1, DEFAULT_RECONNECTION_DELAY))
69
0
{
70
0
  _priv->layout = std::make_shared<xml::XMLLayout>();
71
0
  activateOptions();
72
0
}
Unexecuted instantiation: log4cxx::net::XMLSocketAppender::XMLSocketAppender(std::__1::shared_ptr<log4cxx::helpers::InetAddress>, int)
Unexecuted instantiation: log4cxx::net::XMLSocketAppender::XMLSocketAppender(std::__1::shared_ptr<log4cxx::helpers::InetAddress>, int)
73
74
XMLSocketAppender::XMLSocketAppender(const LogString& host, int port1)
75
0
  : SocketAppenderSkeleton(std::make_unique<SocketAppenderSkeletonPriv>(host, port1, DEFAULT_RECONNECTION_DELAY))
76
0
{
77
0
  _priv->layout = std::make_shared<xml::XMLLayout>();
78
0
  activateOptions();
79
0
}
Unexecuted instantiation: log4cxx::net::XMLSocketAppender::XMLSocketAppender(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
Unexecuted instantiation: log4cxx::net::XMLSocketAppender::XMLSocketAppender(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)
80
81
XMLSocketAppender::~XMLSocketAppender()
82
0
{
83
0
}
84
85
86
int XMLSocketAppender::getDefaultDelay() const
87
0
{
88
0
  return DEFAULT_RECONNECTION_DELAY;
89
0
}
90
91
int XMLSocketAppender::getDefaultPort() const
92
0
{
93
0
  return DEFAULT_PORT;
94
0
}
95
96
#if LOG4CXX_ABI_VERSION <= 15
97
void XMLSocketAppender::setSocket(LOG4CXX_NS::helpers::SocketPtr& socket, helpers::Pool& p)
98
0
{
99
0
  static auto silenceABIchecker = std::make_unique<XMLSocketAppenderPriv>(DEFAULT_PORT, DEFAULT_RECONNECTION_DELAY);
100
0
  _priv->setOutputSink(socket);
101
0
}
102
103
104
void XMLSocketAppender::cleanUp(helpers::Pool& p)
105
0
{
106
0
  _priv->close();
107
0
}
108
#endif
109
110
void XMLSocketAppender::append( LOG4CXX_APPEND_FORMAL_PARAMETERS )
111
0
{
112
0
  if (_priv->outputSink)
113
0
  {
114
0
    LogString output;
115
0
    _priv->layout->format(output, event);
116
117
0
    try
118
0
    {
119
0
      _priv->outputSink->write(output);
120
0
      _priv->outputSink->flush();
121
0
    }
122
0
    catch (std::exception& e)
123
0
    {
124
0
      _priv->outputSink.reset();
125
0
      helpers::LogLog::warn(LOG4CXX_STR("Detected problem with connection: "), e);
126
127
0
      if (getReconnectionDelay() > 0)
128
0
      {
129
0
        _priv->fireConnector();
130
0
      }
131
0
    }
132
0
  }
133
0
}
134
135
136
137