Coverage Report

Created: 2025-07-01 06:08

/src/logging-log4cxx/src/main/cpp/propertiespatternconverter.cpp
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
#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
0
#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
0
    PatternConverterPrivate( name, style ),
37
0
    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
0
  LoggingEventPatternConverter(
50
0
    std::make_unique<PropertiesPatternConverterPrivate>(name1, LOG4CXX_STR("property"), propertyName))
51
0
{
52
0
}
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&)
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&)
53
54
PatternConverterPtr PropertiesPatternConverter::newInstance(
55
  const std::vector<LogString>& options)
56
0
{
57
0
  if (options.size() == 0)
58
0
  {
59
0
    static WideLife<PatternConverterPtr> def = std::make_shared<PropertiesPatternConverter>(
60
0
        LOG4CXX_STR("Properties"), LOG4CXX_STR(""));
61
0
    return def;
62
0
  }
63
64
0
  LogString converterName(LOG4CXX_STR("Property{"));
65
0
  converterName.append(options[0]);
66
0
  converterName.append(LOG4CXX_STR("}"));
67
0
  return std::make_shared<PropertiesPatternConverter>(converterName, options[0]);
68
0
}
69
70
void PropertiesPatternConverter::format(
71
  const LoggingEventPtr& event,
72
  LogString& toAppendTo,
73
  Pool& /* p */) const
74
0
{
75
0
  if (priv->option.length() == 0)
76
0
  {
77
0
    toAppendTo.append(1, (logchar) 0x7B /* '{' */);
78
79
0
    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
0
    toAppendTo.append(1, (logchar) 0x7D /* '}' */);
89
90
0
  }
91
0
  else
92
0
  {
93
0
    event->getMDC(priv->option, toAppendTo);
94
0
  }
95
0
}
96