Coverage Report

Created: 2025-11-11 06:59

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/propertiespatternconverter.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/logstring.h>
19
#include <log4cxx/pattern/propertiespatternconverter.h>
20
#include <log4cxx/spi/loggingevent.h>
21
#include <log4cxx/spi/location/locationinfo.h>
22
#include <log4cxx/private/patternconverter_priv.h>
23
24
#include <iterator>
25
26
using namespace LOG4CXX_NS;
27
using namespace LOG4CXX_NS::pattern;
28
using namespace LOG4CXX_NS::spi;
29
using namespace LOG4CXX_NS::helpers;
30
31
1.50k
#define priv static_cast<PropertiesPatternConverterPrivate*>(m_priv.get())
32
33
struct PropertiesPatternConverter::PropertiesPatternConverterPrivate : public PatternConverterPrivate
34
{
35
  PropertiesPatternConverterPrivate( const LogString& name, const LogString& style, const LogString& propertyName ) :
36
3.94k
    PatternConverterPrivate( name, style ),
37
3.94k
    option(propertyName) {}
log4cxx::pattern::PropertiesPatternConverter::PropertiesPatternConverterPrivate::PropertiesPatternConverterPrivate(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
36
2.26k
    PatternConverterPrivate( name, style ),
37
2.26k
    option(propertyName) {}
log4cxx::pattern::PropertiesPatternConverter::PropertiesPatternConverterPrivate::PropertiesPatternConverterPrivate(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
36
1.67k
    PatternConverterPrivate( name, style ),
37
1.67k
    option(propertyName) {}
38
39
  /**
40
   * Name of property to output.
41
   */
42
  const LogString option;
43
};
44
45
IMPLEMENT_LOG4CXX_OBJECT(PropertiesPatternConverter)
46
47
PropertiesPatternConverter::PropertiesPatternConverter(const LogString& name1,
48
  const LogString& propertyName) :
49
3.94k
  LoggingEventPatternConverter(
50
3.94k
    std::make_unique<PropertiesPatternConverterPrivate>(name1, LOG4CXX_STR("property"), propertyName))
51
3.94k
{
52
3.94k
}
Unexecuted instantiation: log4cxx::pattern::PropertiesPatternConverter::PropertiesPatternConverter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
log4cxx::pattern::PropertiesPatternConverter::PropertiesPatternConverter(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)
Line
Count
Source
49
2.26k
  LoggingEventPatternConverter(
50
2.26k
    std::make_unique<PropertiesPatternConverterPrivate>(name1, LOG4CXX_STR("property"), propertyName))
51
2.26k
{
52
2.26k
}
Unexecuted instantiation: log4cxx::pattern::PropertiesPatternConverter::PropertiesPatternConverter(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
log4cxx::pattern::PropertiesPatternConverter::PropertiesPatternConverter(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&)
Line
Count
Source
49
1.67k
  LoggingEventPatternConverter(
50
1.67k
    std::make_unique<PropertiesPatternConverterPrivate>(name1, LOG4CXX_STR("property"), propertyName))
51
1.67k
{
52
1.67k
}
53
54
PatternConverterPtr PropertiesPatternConverter::newInstance(
55
  const std::vector<LogString>& options)
56
3.57k
{
57
3.57k
  if (options.size() == 0)
58
828
  {
59
828
    static WideLife<PatternConverterPtr> def = std::make_shared<PropertiesPatternConverter>(
60
828
        LOG4CXX_STR("Properties"), LOG4CXX_STR(""));
61
828
    return def;
62
828
  }
63
64
2.75k
  LogString converterName(LOG4CXX_STR("Property{"));
65
2.75k
  converterName.append(options[0]);
66
2.75k
  converterName.append(LOG4CXX_STR("}"));
67
2.75k
  return std::make_shared<PropertiesPatternConverter>(converterName, options[0]);
68
3.57k
}
log4cxx::pattern::PropertiesPatternConverter::newInstance(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&)
Line
Count
Source
56
2.33k
{
57
2.33k
  if (options.size() == 0)
58
502
  {
59
502
    static WideLife<PatternConverterPtr> def = std::make_shared<PropertiesPatternConverter>(
60
502
        LOG4CXX_STR("Properties"), LOG4CXX_STR(""));
61
502
    return def;
62
502
  }
63
64
1.83k
  LogString converterName(LOG4CXX_STR("Property{"));
65
1.83k
  converterName.append(options[0]);
66
1.83k
  converterName.append(LOG4CXX_STR("}"));
67
1.83k
  return std::make_shared<PropertiesPatternConverter>(converterName, options[0]);
68
2.33k
}
log4cxx::pattern::PropertiesPatternConverter::newInstance(std::__1::vector<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >, std::__1::allocator<std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > > > const&)
Line
Count
Source
56
1.24k
{
57
1.24k
  if (options.size() == 0)
58
326
  {
59
326
    static WideLife<PatternConverterPtr> def = std::make_shared<PropertiesPatternConverter>(
60
326
        LOG4CXX_STR("Properties"), LOG4CXX_STR(""));
61
326
    return def;
62
326
  }
63
64
920
  LogString converterName(LOG4CXX_STR("Property{"));
65
920
  converterName.append(options[0]);
66
920
  converterName.append(LOG4CXX_STR("}"));
67
920
  return std::make_shared<PropertiesPatternConverter>(converterName, options[0]);
68
1.24k
}
69
70
void PropertiesPatternConverter::format(
71
  const LoggingEventPtr& event,
72
  LogString& toAppendTo,
73
  Pool& /* p */) const
74
1.19k
{
75
1.19k
  if (priv->option.length() == 0)
76
874
  {
77
874
    toAppendTo.append(1, (logchar) 0x7B /* '{' */);
78
79
874
    for (auto const& item : event->getMDCKeySet())
80
0
    {
81
0
      toAppendTo.append(1, (logchar) 0x7B /* '{' */);
82
0
      toAppendTo.append(item);
83
0
      toAppendTo.append(1, (logchar) 0x2C /* ',' */);
84
0
      event->getMDC(item, toAppendTo);
85
0
      toAppendTo.append(1, (logchar) 0x7D /* '}' */);
86
0
    }
87
88
874
    toAppendTo.append(1, (logchar) 0x7D /* '}' */);
89
90
874
  }
91
317
  else
92
317
  {
93
317
    event->getMDC(priv->option, toAppendTo);
94
317
  }
95
1.19k
}
log4cxx::pattern::PropertiesPatternConverter::format(std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, log4cxx::helpers::Pool&) const
Line
Count
Source
74
434
{
75
434
  if (priv->option.length() == 0)
76
276
  {
77
276
    toAppendTo.append(1, (logchar) 0x7B /* '{' */);
78
79
276
    for (auto const& item : event->getMDCKeySet())
80
0
    {
81
0
      toAppendTo.append(1, (logchar) 0x7B /* '{' */);
82
0
      toAppendTo.append(item);
83
0
      toAppendTo.append(1, (logchar) 0x2C /* ',' */);
84
0
      event->getMDC(item, toAppendTo);
85
0
      toAppendTo.append(1, (logchar) 0x7D /* '}' */);
86
0
    }
87
88
276
    toAppendTo.append(1, (logchar) 0x7D /* '}' */);
89
90
276
  }
91
158
  else
92
158
  {
93
158
    event->getMDC(priv->option, toAppendTo);
94
158
  }
95
434
}
log4cxx::pattern::PropertiesPatternConverter::format(std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, log4cxx::helpers::Pool&) const
Line
Count
Source
74
757
{
75
757
  if (priv->option.length() == 0)
76
598
  {
77
598
    toAppendTo.append(1, (logchar) 0x7B /* '{' */);
78
79
598
    for (auto const& item : event->getMDCKeySet())
80
0
    {
81
0
      toAppendTo.append(1, (logchar) 0x7B /* '{' */);
82
0
      toAppendTo.append(item);
83
0
      toAppendTo.append(1, (logchar) 0x2C /* ',' */);
84
0
      event->getMDC(item, toAppendTo);
85
0
      toAppendTo.append(1, (logchar) 0x7D /* '}' */);
86
0
    }
87
88
598
    toAppendTo.append(1, (logchar) 0x7D /* '}' */);
89
90
598
  }
91
159
  else
92
159
  {
93
159
    event->getMDC(priv->option, toAppendTo);
94
159
  }
95
757
}
96