Coverage Report

Created: 2025-12-14 06:19

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/logging-log4cxx/src/main/cpp/jsonlayout.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/jsonlayout.h>
20
#include <log4cxx/spi/loggingevent.h>
21
#include <log4cxx/level.h>
22
#include <log4cxx/helpers/optionconverter.h>
23
#include <log4cxx/helpers/cacheddateformat.h>
24
#include <log4cxx/helpers/simpledateformat.h>
25
#include <log4cxx/helpers/stringhelper.h>
26
#include <log4cxx/helpers/transcoder.h>
27
28
#include <string.h>
29
30
using namespace LOG4CXX_NS;
31
using namespace LOG4CXX_NS::helpers;
32
using namespace LOG4CXX_NS::spi;
33
34
IMPLEMENT_LOG4CXX_OBJECT(JSONLayout)
35
36
struct JSONLayout::JSONLayoutPrivate
37
{
38
  JSONLayoutPrivate() :
39
4.16k
    locationInfo(false),
40
4.16k
    prettyPrint(false),
41
4.16k
    ppIndentL1(LOG4CXX_STR("  ")),
42
4.16k
    ppIndentL2(LOG4CXX_STR("    ")),
43
4.16k
    expectedPatternLength(100),
44
4.16k
    threadInfo(false) {}
45
46
  // Print no location info by default
47
  bool locationInfo; //= false
48
  bool prettyPrint; //= false
49
50
  pattern::CachedDateFormat dateFormat
51
    { std::make_shared<helpers::SimpleDateFormat>(LOG4CXX_STR("yyyy-MM-dd HH:mm:ss,SSS"))
52
    , pattern::CachedDateFormat::getMaximumCacheValidity(LOG4CXX_STR("yyyy-MM-dd HH:mm:ss,SSS"))
53
    };
54
55
  LogString ppIndentL1;
56
  LogString ppIndentL2;
57
58
  // Expected length of a formatted event excluding the message text
59
  size_t expectedPatternLength;
60
61
  // Thread info is not included by default
62
  bool threadInfo; //= false
63
};
64
65
JSONLayout::JSONLayout() :
66
4.16k
  m_priv(std::make_unique<JSONLayoutPrivate>())
67
4.16k
{
68
4.16k
}
Unexecuted instantiation: log4cxx::JSONLayout::JSONLayout()
log4cxx::JSONLayout::JSONLayout()
Line
Count
Source
66
4.16k
  m_priv(std::make_unique<JSONLayoutPrivate>())
67
4.16k
{
68
4.16k
}
69
70
4.16k
JSONLayout::~JSONLayout(){}
71
72
void JSONLayout::setLocationInfo(bool locationInfoFlag)
73
2.60k
{
74
2.60k
  m_priv->locationInfo = locationInfoFlag;
75
2.60k
}
76
77
bool JSONLayout::getLocationInfo() const
78
0
{
79
0
  return m_priv->locationInfo;
80
0
}
81
82
void JSONLayout::setPrettyPrint(bool prettyPrintFlag)
83
2.13k
{
84
2.13k
  m_priv->prettyPrint = prettyPrintFlag;
85
2.13k
}
86
87
bool JSONLayout::getPrettyPrint() const
88
0
{
89
0
  return m_priv->prettyPrint;
90
0
}
91
92
void JSONLayout::setThreadInfo(bool newValue)
93
2.38k
{
94
2.38k
  m_priv->threadInfo = newValue;
95
2.38k
}
96
97
bool JSONLayout::getThreadInfo() const
98
0
{
99
0
  return m_priv->threadInfo;
100
0
}
101
102
LogString JSONLayout::getContentType() const
103
0
{
104
0
  return LOG4CXX_STR("application/json");
105
0
}
106
107
void JSONLayout::activateOptions(helpers::Pool& /* p */)
108
0
{
109
0
  m_priv->expectedPatternLength = getFormattedEventCharacterCount() * 2;
110
0
}
111
112
void JSONLayout::setOption(const LogString& option, const LogString& value)
113
7.13k
{
114
7.13k
  if (StringHelper::equalsIgnoreCase(option,
115
7.13k
      LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("locationinfo")))
116
2.60k
  {
117
2.60k
    setLocationInfo(OptionConverter::toBoolean(value, false));
118
2.60k
  }
119
4.52k
  else if (StringHelper::equalsIgnoreCase(option,
120
4.52k
      LOG4CXX_STR("THREADINFO"), LOG4CXX_STR("threadinfo")))
121
2.38k
  {
122
2.38k
    setThreadInfo(OptionConverter::toBoolean(value, false));
123
2.38k
  }
124
2.13k
  else if (StringHelper::equalsIgnoreCase(option,
125
2.13k
      LOG4CXX_STR("PRETTYPRINT"), LOG4CXX_STR("prettyprint")))
126
2.13k
  {
127
2.13k
    setPrettyPrint(OptionConverter::toBoolean(value, false));
128
2.13k
  }
129
7.13k
}
log4cxx::JSONLayout::setOption(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
113
3.12k
{
114
3.12k
  if (StringHelper::equalsIgnoreCase(option,
115
3.12k
      LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("locationinfo")))
116
1.12k
  {
117
1.12k
    setLocationInfo(OptionConverter::toBoolean(value, false));
118
1.12k
  }
119
1.99k
  else if (StringHelper::equalsIgnoreCase(option,
120
1.99k
      LOG4CXX_STR("THREADINFO"), LOG4CXX_STR("threadinfo")))
121
1.04k
  {
122
1.04k
    setThreadInfo(OptionConverter::toBoolean(value, false));
123
1.04k
  }
124
953
  else if (StringHelper::equalsIgnoreCase(option,
125
953
      LOG4CXX_STR("PRETTYPRINT"), LOG4CXX_STR("prettyprint")))
126
953
  {
127
953
    setPrettyPrint(OptionConverter::toBoolean(value, false));
128
953
  }
129
3.12k
}
log4cxx::JSONLayout::setOption(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
113
4.01k
{
114
4.01k
  if (StringHelper::equalsIgnoreCase(option,
115
4.01k
      LOG4CXX_STR("LOCATIONINFO"), LOG4CXX_STR("locationinfo")))
116
1.47k
  {
117
1.47k
    setLocationInfo(OptionConverter::toBoolean(value, false));
118
1.47k
  }
119
2.53k
  else if (StringHelper::equalsIgnoreCase(option,
120
2.53k
      LOG4CXX_STR("THREADINFO"), LOG4CXX_STR("threadinfo")))
121
1.34k
  {
122
1.34k
    setThreadInfo(OptionConverter::toBoolean(value, false));
123
1.34k
  }
124
1.18k
  else if (StringHelper::equalsIgnoreCase(option,
125
1.18k
      LOG4CXX_STR("PRETTYPRINT"), LOG4CXX_STR("prettyprint")))
126
1.18k
  {
127
1.18k
    setPrettyPrint(OptionConverter::toBoolean(value, false));
128
1.18k
  }
129
4.01k
}
130
131
void JSONLayout::format(LogString& output,
132
  const spi::LoggingEventPtr& event,
133
  Pool& p) const
134
4.16k
{
135
4.16k
  auto& lsMsg = event->getRenderedMessage();
136
4.16k
  output.reserve(m_priv->expectedPatternLength + lsMsg.size());
137
4.16k
  output.append(LOG4CXX_STR("{"));
138
4.16k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
139
140
4.16k
  if (m_priv->prettyPrint)
141
2.13k
  {
142
2.13k
    output.append(m_priv->ppIndentL1);
143
2.13k
  }
144
145
4.16k
  output.append(LOG4CXX_STR("\"timestamp\": \""));
146
4.16k
  m_priv->dateFormat.format(output, event->getTimeStamp(), p);
147
4.16k
  output.append(LOG4CXX_STR("\","));
148
4.16k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
149
150
4.16k
  if (m_priv->threadInfo)
151
2.38k
  {
152
2.38k
    if (m_priv->prettyPrint)
153
1.55k
    {
154
1.55k
      output.append(m_priv->ppIndentL1);
155
1.55k
    }
156
2.38k
    appendQuotedEscapedString(output, LOG4CXX_STR("thread"));
157
2.38k
    output.append(LOG4CXX_STR(": "));
158
2.38k
    appendQuotedEscapedString(output, event->getThreadName());
159
2.38k
    output.append(LOG4CXX_STR(","));
160
2.38k
    output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
161
2.38k
  }
162
163
4.16k
  if (m_priv->prettyPrint)
164
2.13k
  {
165
2.13k
    output.append(m_priv->ppIndentL1);
166
2.13k
  }
167
168
4.16k
  output.append(LOG4CXX_STR("\"level\": "));
169
4.16k
  LogString level;
170
4.16k
  event->getLevel()->toString(level);
171
4.16k
  appendQuotedEscapedString(output, level);
172
4.16k
  output.append(LOG4CXX_STR(","));
173
4.16k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
174
175
4.16k
  if (m_priv->prettyPrint)
176
2.13k
  {
177
2.13k
    output.append(m_priv->ppIndentL1);
178
2.13k
  }
179
180
4.16k
  output.append(LOG4CXX_STR("\"logger\": "));
181
4.16k
  appendQuotedEscapedString(output, event->getLoggerName());
182
4.16k
  output.append(LOG4CXX_STR(","));
183
4.16k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
184
185
4.16k
  if (m_priv->prettyPrint)
186
2.13k
  {
187
2.13k
    output.append(m_priv->ppIndentL1);
188
2.13k
  }
189
190
4.16k
  output.append(LOG4CXX_STR("\"message\": "));
191
4.16k
  appendQuotedEscapedString(output, lsMsg);
192
193
4.16k
  appendSerializedMDC(output, event);
194
4.16k
  appendSerializedNDC(output, event);
195
196
4.16k
  if (m_priv->locationInfo)
197
2.60k
  {
198
2.60k
    output.append(LOG4CXX_STR(","));
199
2.60k
    output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
200
2.60k
    appendSerializedLocationInfo(output, event, p);
201
2.60k
  }
202
203
4.16k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
204
4.16k
  output.append(LOG4CXX_STR("}"));
205
4.16k
  output.append(LOG4CXX_EOL);
206
4.16k
}
log4cxx::JSONLayout::format(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, log4cxx::helpers::Pool&) const
Line
Count
Source
134
1.70k
{
135
1.70k
  auto& lsMsg = event->getRenderedMessage();
136
1.70k
  output.reserve(m_priv->expectedPatternLength + lsMsg.size());
137
1.70k
  output.append(LOG4CXX_STR("{"));
138
1.70k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
139
140
1.70k
  if (m_priv->prettyPrint)
141
953
  {
142
953
    output.append(m_priv->ppIndentL1);
143
953
  }
144
145
1.70k
  output.append(LOG4CXX_STR("\"timestamp\": \""));
146
1.70k
  m_priv->dateFormat.format(output, event->getTimeStamp(), p);
147
1.70k
  output.append(LOG4CXX_STR("\","));
148
1.70k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
149
150
1.70k
  if (m_priv->threadInfo)
151
1.04k
  {
152
1.04k
    if (m_priv->prettyPrint)
153
721
    {
154
721
      output.append(m_priv->ppIndentL1);
155
721
    }
156
1.04k
    appendQuotedEscapedString(output, LOG4CXX_STR("thread"));
157
1.04k
    output.append(LOG4CXX_STR(": "));
158
1.04k
    appendQuotedEscapedString(output, event->getThreadName());
159
1.04k
    output.append(LOG4CXX_STR(","));
160
1.04k
    output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
161
1.04k
  }
162
163
1.70k
  if (m_priv->prettyPrint)
164
953
  {
165
953
    output.append(m_priv->ppIndentL1);
166
953
  }
167
168
1.70k
  output.append(LOG4CXX_STR("\"level\": "));
169
1.70k
  LogString level;
170
1.70k
  event->getLevel()->toString(level);
171
1.70k
  appendQuotedEscapedString(output, level);
172
1.70k
  output.append(LOG4CXX_STR(","));
173
1.70k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
174
175
1.70k
  if (m_priv->prettyPrint)
176
953
  {
177
953
    output.append(m_priv->ppIndentL1);
178
953
  }
179
180
1.70k
  output.append(LOG4CXX_STR("\"logger\": "));
181
1.70k
  appendQuotedEscapedString(output, event->getLoggerName());
182
1.70k
  output.append(LOG4CXX_STR(","));
183
1.70k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
184
185
1.70k
  if (m_priv->prettyPrint)
186
953
  {
187
953
    output.append(m_priv->ppIndentL1);
188
953
  }
189
190
1.70k
  output.append(LOG4CXX_STR("\"message\": "));
191
1.70k
  appendQuotedEscapedString(output, lsMsg);
192
193
1.70k
  appendSerializedMDC(output, event);
194
1.70k
  appendSerializedNDC(output, event);
195
196
1.70k
  if (m_priv->locationInfo)
197
1.12k
  {
198
1.12k
    output.append(LOG4CXX_STR(","));
199
1.12k
    output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
200
1.12k
    appendSerializedLocationInfo(output, event, p);
201
1.12k
  }
202
203
1.70k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
204
1.70k
  output.append(LOG4CXX_STR("}"));
205
1.70k
  output.append(LOG4CXX_EOL);
206
1.70k
}
log4cxx::JSONLayout::format(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, log4cxx::helpers::Pool&) const
Line
Count
Source
134
2.45k
{
135
2.45k
  auto& lsMsg = event->getRenderedMessage();
136
2.45k
  output.reserve(m_priv->expectedPatternLength + lsMsg.size());
137
2.45k
  output.append(LOG4CXX_STR("{"));
138
2.45k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
139
140
2.45k
  if (m_priv->prettyPrint)
141
1.18k
  {
142
1.18k
    output.append(m_priv->ppIndentL1);
143
1.18k
  }
144
145
2.45k
  output.append(LOG4CXX_STR("\"timestamp\": \""));
146
2.45k
  m_priv->dateFormat.format(output, event->getTimeStamp(), p);
147
2.45k
  output.append(LOG4CXX_STR("\","));
148
2.45k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
149
150
2.45k
  if (m_priv->threadInfo)
151
1.34k
  {
152
1.34k
    if (m_priv->prettyPrint)
153
834
    {
154
834
      output.append(m_priv->ppIndentL1);
155
834
    }
156
1.34k
    appendQuotedEscapedString(output, LOG4CXX_STR("thread"));
157
1.34k
    output.append(LOG4CXX_STR(": "));
158
1.34k
    appendQuotedEscapedString(output, event->getThreadName());
159
1.34k
    output.append(LOG4CXX_STR(","));
160
1.34k
    output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
161
1.34k
  }
162
163
2.45k
  if (m_priv->prettyPrint)
164
1.18k
  {
165
1.18k
    output.append(m_priv->ppIndentL1);
166
1.18k
  }
167
168
2.45k
  output.append(LOG4CXX_STR("\"level\": "));
169
2.45k
  LogString level;
170
2.45k
  event->getLevel()->toString(level);
171
2.45k
  appendQuotedEscapedString(output, level);
172
2.45k
  output.append(LOG4CXX_STR(","));
173
2.45k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
174
175
2.45k
  if (m_priv->prettyPrint)
176
1.18k
  {
177
1.18k
    output.append(m_priv->ppIndentL1);
178
1.18k
  }
179
180
2.45k
  output.append(LOG4CXX_STR("\"logger\": "));
181
2.45k
  appendQuotedEscapedString(output, event->getLoggerName());
182
2.45k
  output.append(LOG4CXX_STR(","));
183
2.45k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
184
185
2.45k
  if (m_priv->prettyPrint)
186
1.18k
  {
187
1.18k
    output.append(m_priv->ppIndentL1);
188
1.18k
  }
189
190
2.45k
  output.append(LOG4CXX_STR("\"message\": "));
191
2.45k
  appendQuotedEscapedString(output, lsMsg);
192
193
2.45k
  appendSerializedMDC(output, event);
194
2.45k
  appendSerializedNDC(output, event);
195
196
2.45k
  if (m_priv->locationInfo)
197
1.47k
  {
198
1.47k
    output.append(LOG4CXX_STR(","));
199
1.47k
    output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
200
1.47k
    appendSerializedLocationInfo(output, event, p);
201
1.47k
  }
202
203
2.45k
  output.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
204
2.45k
  output.append(LOG4CXX_STR("}"));
205
2.45k
  output.append(LOG4CXX_EOL);
206
2.45k
}
207
208
void JSONLayout::appendQuotedEscapedString(LogString& buf,
209
  const LogString& input) const
210
64.7k
{
211
64.7k
  appendItem(input, buf);
212
64.7k
}
log4cxx::JSONLayout::appendQuotedEscapedString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const
Line
Count
Source
210
27.2k
{
211
27.2k
  appendItem(input, buf);
212
27.2k
}
log4cxx::JSONLayout::appendQuotedEscapedString(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> > const&) const
Line
Count
Source
210
37.5k
{
211
37.5k
  appendItem(input, buf);
212
37.5k
}
213
214
void JSONLayout::appendItem(const LogString& input, LogString& buf)
215
64.7k
{
216
64.7k
  auto toHexDigit = [](int ch) -> int
217
4.68M
  {
218
4.68M
    return (10 <= ch ? (0x61 - 10) : 0x30) + ch;
219
4.68M
  };
jsonlayout.cpp:log4cxx::JSONLayout::appendItem(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> >&)::$_0::operator()(int) const
Line
Count
Source
217
1.85M
  {
218
1.85M
    return (10 <= ch ? (0x61 - 10) : 0x30) + ch;
219
1.85M
  };
jsonlayout.cpp:log4cxx::JSONLayout::appendItem(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> >&)::$_0::operator()(int) const
Line
Count
Source
217
2.82M
  {
218
2.82M
    return (10 <= ch ? (0x61 - 10) : 0x30) + ch;
219
2.82M
  };
220
  /* add leading quote */
221
64.7k
  buf.push_back(0x22);
222
223
64.7k
  size_t start = 0;
224
64.7k
  size_t index = 0;
225
226
64.7k
  for (int ch : input)
227
2.09M
  {
228
2.09M
    if (0x22 == ch || 0x5c == ch)
229
16.8k
      ;
230
2.07M
    else if (0x20 <= ch)
231
774k
    {
232
774k
      ++index;
233
774k
      continue;
234
774k
    }
235
1.31M
    if (start < index)
236
49.3k
    {
237
49.3k
      buf.append(input, start, index - start);
238
49.3k
    }
239
240
1.31M
    switch (ch)
241
1.31M
    {
242
14.3k
      case 0x08:
243
        /* \b backspace */
244
14.3k
        buf.push_back(0x5c);
245
14.3k
        buf.push_back('b');
246
14.3k
        break;
247
248
14.0k
      case 0x09:
249
        /* \t tab */
250
14.0k
        buf.push_back(0x5c);
251
14.0k
        buf.push_back('t');
252
14.0k
        break;
253
254
34.3k
      case 0x0a:
255
        /* \n newline */
256
34.3k
        buf.push_back(0x5c);
257
34.3k
        buf.push_back('n');
258
34.3k
        break;
259
260
40.6k
      case 0x0c:
261
        /* \f form feed */
262
40.6k
        buf.push_back(0x5c);
263
40.6k
        buf.push_back('f');
264
40.6k
        break;
265
266
25.7k
      case 0x0d:
267
        /* \r carriage return */
268
25.7k
        buf.push_back(0x5c);
269
25.7k
        buf.push_back('r');
270
25.7k
        break;
271
272
6.50k
      case 0x22:
273
        /* \" double quote */
274
6.50k
        buf.push_back(0x5c);
275
6.50k
        buf.push_back(0x22);
276
6.50k
        break;
277
278
10.3k
      case 0x5c:
279
        /* \\ backslash */
280
10.3k
        buf.push_back(0x5c);
281
10.3k
        buf.push_back(0x5c);
282
10.3k
        break;
283
284
1.17M
      default:
285
1.17M
        buf.push_back(0x5c);
286
1.17M
        buf.push_back(0x75); // 'u'
287
1.17M
        buf.push_back(toHexDigit((ch & 0xF000) >> 12));
288
1.17M
        buf.push_back(toHexDigit((ch & 0xF00) >> 8));
289
1.17M
        buf.push_back(toHexDigit((ch & 0xF0) >> 4));
290
1.17M
        buf.push_back(toHexDigit(ch & 0xF));
291
1.17M
        break;
292
1.31M
    }
293
1.31M
    start = ++index;
294
1.31M
  }
295
296
64.7k
  if (start < input.size())
297
39.5k
  {
298
39.5k
    buf.append(input, start, input.size() - start);
299
39.5k
  }
300
301
  /* add trailing quote */
302
64.7k
  buf.push_back(0x22);
303
64.7k
}
log4cxx::JSONLayout::appendItem(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> >&)
Line
Count
Source
215
27.2k
{
216
27.2k
  auto toHexDigit = [](int ch) -> int
217
27.2k
  {
218
27.2k
    return (10 <= ch ? (0x61 - 10) : 0x30) + ch;
219
27.2k
  };
220
  /* add leading quote */
221
27.2k
  buf.push_back(0x22);
222
223
27.2k
  size_t start = 0;
224
27.2k
  size_t index = 0;
225
226
27.2k
  for (int ch : input)
227
783k
  {
228
783k
    if (0x22 == ch || 0x5c == ch)
229
7.99k
      ;
230
775k
    else if (0x20 <= ch)
231
277k
    {
232
277k
      ++index;
233
277k
      continue;
234
277k
    }
235
506k
    if (start < index)
236
18.7k
    {
237
18.7k
      buf.append(input, start, index - start);
238
18.7k
    }
239
240
506k
    switch (ch)
241
506k
    {
242
1.96k
      case 0x08:
243
        /* \b backspace */
244
1.96k
        buf.push_back(0x5c);
245
1.96k
        buf.push_back('b');
246
1.96k
        break;
247
248
4.69k
      case 0x09:
249
        /* \t tab */
250
4.69k
        buf.push_back(0x5c);
251
4.69k
        buf.push_back('t');
252
4.69k
        break;
253
254
24.4k
      case 0x0a:
255
        /* \n newline */
256
24.4k
        buf.push_back(0x5c);
257
24.4k
        buf.push_back('n');
258
24.4k
        break;
259
260
1.13k
      case 0x0c:
261
        /* \f form feed */
262
1.13k
        buf.push_back(0x5c);
263
1.13k
        buf.push_back('f');
264
1.13k
        break;
265
266
2.11k
      case 0x0d:
267
        /* \r carriage return */
268
2.11k
        buf.push_back(0x5c);
269
2.11k
        buf.push_back('r');
270
2.11k
        break;
271
272
3.42k
      case 0x22:
273
        /* \" double quote */
274
3.42k
        buf.push_back(0x5c);
275
3.42k
        buf.push_back(0x22);
276
3.42k
        break;
277
278
4.56k
      case 0x5c:
279
        /* \\ backslash */
280
4.56k
        buf.push_back(0x5c);
281
4.56k
        buf.push_back(0x5c);
282
4.56k
        break;
283
284
464k
      default:
285
464k
        buf.push_back(0x5c);
286
464k
        buf.push_back(0x75); // 'u'
287
464k
        buf.push_back(toHexDigit((ch & 0xF000) >> 12));
288
464k
        buf.push_back(toHexDigit((ch & 0xF00) >> 8));
289
464k
        buf.push_back(toHexDigit((ch & 0xF0) >> 4));
290
464k
        buf.push_back(toHexDigit(ch & 0xF));
291
464k
        break;
292
506k
    }
293
506k
    start = ++index;
294
506k
  }
295
296
27.2k
  if (start < input.size())
297
16.6k
  {
298
16.6k
    buf.append(input, start, input.size() - start);
299
16.6k
  }
300
301
  /* add trailing quote */
302
27.2k
  buf.push_back(0x22);
303
27.2k
}
log4cxx::JSONLayout::appendItem(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> >&)
Line
Count
Source
215
37.5k
{
216
37.5k
  auto toHexDigit = [](int ch) -> int
217
37.5k
  {
218
37.5k
    return (10 <= ch ? (0x61 - 10) : 0x30) + ch;
219
37.5k
  };
220
  /* add leading quote */
221
37.5k
  buf.push_back(0x22);
222
223
37.5k
  size_t start = 0;
224
37.5k
  size_t index = 0;
225
226
37.5k
  for (int ch : input)
227
1.30M
  {
228
1.30M
    if (0x22 == ch || 0x5c == ch)
229
8.89k
      ;
230
1.29M
    else if (0x20 <= ch)
231
496k
    {
232
496k
      ++index;
233
496k
      continue;
234
496k
    }
235
810k
    if (start < index)
236
30.5k
    {
237
30.5k
      buf.append(input, start, index - start);
238
30.5k
    }
239
240
810k
    switch (ch)
241
810k
    {
242
12.3k
      case 0x08:
243
        /* \b backspace */
244
12.3k
        buf.push_back(0x5c);
245
12.3k
        buf.push_back('b');
246
12.3k
        break;
247
248
9.40k
      case 0x09:
249
        /* \t tab */
250
9.40k
        buf.push_back(0x5c);
251
9.40k
        buf.push_back('t');
252
9.40k
        break;
253
254
9.88k
      case 0x0a:
255
        /* \n newline */
256
9.88k
        buf.push_back(0x5c);
257
9.88k
        buf.push_back('n');
258
9.88k
        break;
259
260
39.5k
      case 0x0c:
261
        /* \f form feed */
262
39.5k
        buf.push_back(0x5c);
263
39.5k
        buf.push_back('f');
264
39.5k
        break;
265
266
23.6k
      case 0x0d:
267
        /* \r carriage return */
268
23.6k
        buf.push_back(0x5c);
269
23.6k
        buf.push_back('r');
270
23.6k
        break;
271
272
3.08k
      case 0x22:
273
        /* \" double quote */
274
3.08k
        buf.push_back(0x5c);
275
3.08k
        buf.push_back(0x22);
276
3.08k
        break;
277
278
5.80k
      case 0x5c:
279
        /* \\ backslash */
280
5.80k
        buf.push_back(0x5c);
281
5.80k
        buf.push_back(0x5c);
282
5.80k
        break;
283
284
706k
      default:
285
706k
        buf.push_back(0x5c);
286
706k
        buf.push_back(0x75); // 'u'
287
706k
        buf.push_back(toHexDigit((ch & 0xF000) >> 12));
288
706k
        buf.push_back(toHexDigit((ch & 0xF00) >> 8));
289
706k
        buf.push_back(toHexDigit((ch & 0xF0) >> 4));
290
706k
        buf.push_back(toHexDigit(ch & 0xF));
291
706k
        break;
292
810k
    }
293
810k
    start = ++index;
294
810k
  }
295
296
37.5k
  if (start < input.size())
297
22.8k
  {
298
22.8k
    buf.append(input, start, input.size() - start);
299
22.8k
  }
300
301
  /* add trailing quote */
302
37.5k
  buf.push_back(0x22);
303
37.5k
}
304
305
void JSONLayout::appendSerializedMDC(LogString& buf,
306
  const LoggingEventPtr& event) const
307
4.16k
{
308
4.16k
  LoggingEvent::KeySet keys = event->getMDCKeySet();
309
310
4.16k
  if (keys.empty())
311
0
  {
312
0
    return;
313
0
  }
314
315
4.16k
  buf.append(LOG4CXX_STR(","));
316
4.16k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
317
318
4.16k
  if (m_priv->prettyPrint)
319
2.13k
  {
320
2.13k
    buf.append(m_priv->ppIndentL1);
321
2.13k
  }
322
323
4.16k
  appendQuotedEscapedString(buf, LOG4CXX_STR("context_map"));
324
4.16k
  buf.append(LOG4CXX_STR(": {"));
325
4.16k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
326
327
4.16k
  for (LoggingEvent::KeySet::iterator it = keys.begin();
328
9.96k
    it != keys.end(); ++it)
329
5.79k
  {
330
5.79k
    if (m_priv->prettyPrint)
331
3.17k
    {
332
3.17k
      buf.append(m_priv->ppIndentL2);
333
3.17k
    }
334
335
5.79k
    appendQuotedEscapedString(buf, *it);
336
5.79k
    buf.append(LOG4CXX_STR(": "));
337
5.79k
    LogString value;
338
5.79k
    event->getMDC(*it, value);
339
5.79k
    appendQuotedEscapedString(buf, value);
340
341
    /* if this isn't the last k:v pair, we need a comma */
342
5.79k
    if (it + 1 != keys.end())
343
1.63k
    {
344
1.63k
      buf.append(LOG4CXX_STR(","));
345
1.63k
      buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
346
1.63k
    }
347
4.16k
    else
348
4.16k
    {
349
4.16k
      buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
350
4.16k
    }
351
5.79k
  }
352
353
4.16k
  if (m_priv->prettyPrint)
354
2.13k
  {
355
2.13k
    buf.append(m_priv->ppIndentL1);
356
2.13k
  }
357
358
4.16k
  buf.append(LOG4CXX_STR("}"));
359
4.16k
}
log4cxx::JSONLayout::appendSerializedMDC(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&) const
Line
Count
Source
307
1.70k
{
308
1.70k
  LoggingEvent::KeySet keys = event->getMDCKeySet();
309
310
1.70k
  if (keys.empty())
311
0
  {
312
0
    return;
313
0
  }
314
315
1.70k
  buf.append(LOG4CXX_STR(","));
316
1.70k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
317
318
1.70k
  if (m_priv->prettyPrint)
319
953
  {
320
953
    buf.append(m_priv->ppIndentL1);
321
953
  }
322
323
1.70k
  appendQuotedEscapedString(buf, LOG4CXX_STR("context_map"));
324
1.70k
  buf.append(LOG4CXX_STR(": {"));
325
1.70k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
326
327
1.70k
  for (LoggingEvent::KeySet::iterator it = keys.begin();
328
4.09k
    it != keys.end(); ++it)
329
2.38k
  {
330
2.38k
    if (m_priv->prettyPrint)
331
1.43k
    {
332
1.43k
      buf.append(m_priv->ppIndentL2);
333
1.43k
    }
334
335
2.38k
    appendQuotedEscapedString(buf, *it);
336
2.38k
    buf.append(LOG4CXX_STR(": "));
337
2.38k
    LogString value;
338
2.38k
    event->getMDC(*it, value);
339
2.38k
    appendQuotedEscapedString(buf, value);
340
341
    /* if this isn't the last k:v pair, we need a comma */
342
2.38k
    if (it + 1 != keys.end())
343
676
    {
344
676
      buf.append(LOG4CXX_STR(","));
345
676
      buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
346
676
    }
347
1.70k
    else
348
1.70k
    {
349
1.70k
      buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
350
1.70k
    }
351
2.38k
  }
352
353
1.70k
  if (m_priv->prettyPrint)
354
953
  {
355
953
    buf.append(m_priv->ppIndentL1);
356
953
  }
357
358
1.70k
  buf.append(LOG4CXX_STR("}"));
359
1.70k
}
log4cxx::JSONLayout::appendSerializedMDC(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&) const
Line
Count
Source
307
2.45k
{
308
2.45k
  LoggingEvent::KeySet keys = event->getMDCKeySet();
309
310
2.45k
  if (keys.empty())
311
0
  {
312
0
    return;
313
0
  }
314
315
2.45k
  buf.append(LOG4CXX_STR(","));
316
2.45k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
317
318
2.45k
  if (m_priv->prettyPrint)
319
1.18k
  {
320
1.18k
    buf.append(m_priv->ppIndentL1);
321
1.18k
  }
322
323
2.45k
  appendQuotedEscapedString(buf, LOG4CXX_STR("context_map"));
324
2.45k
  buf.append(LOG4CXX_STR(": {"));
325
2.45k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
326
327
2.45k
  for (LoggingEvent::KeySet::iterator it = keys.begin();
328
5.87k
    it != keys.end(); ++it)
329
3.41k
  {
330
3.41k
    if (m_priv->prettyPrint)
331
1.74k
    {
332
1.74k
      buf.append(m_priv->ppIndentL2);
333
1.74k
    }
334
335
3.41k
    appendQuotedEscapedString(buf, *it);
336
3.41k
    buf.append(LOG4CXX_STR(": "));
337
3.41k
    LogString value;
338
3.41k
    event->getMDC(*it, value);
339
3.41k
    appendQuotedEscapedString(buf, value);
340
341
    /* if this isn't the last k:v pair, we need a comma */
342
3.41k
    if (it + 1 != keys.end())
343
960
    {
344
960
      buf.append(LOG4CXX_STR(","));
345
960
      buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
346
960
    }
347
2.45k
    else
348
2.45k
    {
349
2.45k
      buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
350
2.45k
    }
351
3.41k
  }
352
353
2.45k
  if (m_priv->prettyPrint)
354
1.18k
  {
355
1.18k
    buf.append(m_priv->ppIndentL1);
356
1.18k
  }
357
358
2.45k
  buf.append(LOG4CXX_STR("}"));
359
2.45k
}
360
361
void JSONLayout::appendSerializedNDC(LogString& buf,
362
  const LoggingEventPtr& event) const
363
4.16k
{
364
4.16k
  LogString ndcVal;
365
366
4.16k
  if (!event->getNDC(ndcVal))
367
0
  {
368
0
    return;
369
0
  }
370
371
4.16k
  buf.append(LOG4CXX_STR(","));
372
4.16k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
373
374
4.16k
  if (m_priv->prettyPrint)
375
2.13k
  {
376
2.13k
    buf.append(m_priv->ppIndentL1);
377
2.13k
  }
378
379
4.16k
  appendQuotedEscapedString(buf, LOG4CXX_STR("context_stack"));
380
4.16k
  buf.append(LOG4CXX_STR(": ["));
381
4.16k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
382
383
4.16k
  if (m_priv->prettyPrint)
384
2.13k
  {
385
2.13k
    buf.append(m_priv->ppIndentL2);
386
2.13k
  }
387
388
4.16k
  appendQuotedEscapedString(buf, ndcVal);
389
4.16k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
390
391
4.16k
  if (m_priv->prettyPrint)
392
2.13k
  {
393
2.13k
    buf.append(m_priv->ppIndentL1);
394
2.13k
  }
395
396
4.16k
  buf.append(LOG4CXX_STR("]"));
397
4.16k
}
log4cxx::JSONLayout::appendSerializedNDC(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&) const
Line
Count
Source
363
1.70k
{
364
1.70k
  LogString ndcVal;
365
366
1.70k
  if (!event->getNDC(ndcVal))
367
0
  {
368
0
    return;
369
0
  }
370
371
1.70k
  buf.append(LOG4CXX_STR(","));
372
1.70k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
373
374
1.70k
  if (m_priv->prettyPrint)
375
953
  {
376
953
    buf.append(m_priv->ppIndentL1);
377
953
  }
378
379
1.70k
  appendQuotedEscapedString(buf, LOG4CXX_STR("context_stack"));
380
1.70k
  buf.append(LOG4CXX_STR(": ["));
381
1.70k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
382
383
1.70k
  if (m_priv->prettyPrint)
384
953
  {
385
953
    buf.append(m_priv->ppIndentL2);
386
953
  }
387
388
1.70k
  appendQuotedEscapedString(buf, ndcVal);
389
1.70k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
390
391
1.70k
  if (m_priv->prettyPrint)
392
953
  {
393
953
    buf.append(m_priv->ppIndentL1);
394
953
  }
395
396
1.70k
  buf.append(LOG4CXX_STR("]"));
397
1.70k
}
log4cxx::JSONLayout::appendSerializedNDC(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&) const
Line
Count
Source
363
2.45k
{
364
2.45k
  LogString ndcVal;
365
366
2.45k
  if (!event->getNDC(ndcVal))
367
0
  {
368
0
    return;
369
0
  }
370
371
2.45k
  buf.append(LOG4CXX_STR(","));
372
2.45k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
373
374
2.45k
  if (m_priv->prettyPrint)
375
1.18k
  {
376
1.18k
    buf.append(m_priv->ppIndentL1);
377
1.18k
  }
378
379
2.45k
  appendQuotedEscapedString(buf, LOG4CXX_STR("context_stack"));
380
2.45k
  buf.append(LOG4CXX_STR(": ["));
381
2.45k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
382
383
2.45k
  if (m_priv->prettyPrint)
384
1.18k
  {
385
1.18k
    buf.append(m_priv->ppIndentL2);
386
1.18k
  }
387
388
2.45k
  appendQuotedEscapedString(buf, ndcVal);
389
2.45k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
390
391
2.45k
  if (m_priv->prettyPrint)
392
1.18k
  {
393
1.18k
    buf.append(m_priv->ppIndentL1);
394
1.18k
  }
395
396
2.45k
  buf.append(LOG4CXX_STR("]"));
397
2.45k
}
398
399
void JSONLayout::appendSerializedLocationInfo(LogString& buf,
400
  const LoggingEventPtr& event, Pool& p) const
401
2.60k
{
402
2.60k
  if (m_priv->prettyPrint)
403
1.60k
  {
404
1.60k
    buf.append(m_priv->ppIndentL1);
405
1.60k
  }
406
407
2.60k
  appendQuotedEscapedString(buf, LOG4CXX_STR("location_info"));
408
2.60k
  buf.append(LOG4CXX_STR(": {"));
409
2.60k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
410
2.60k
  const LocationInfo& locInfo = event->getLocationInformation();
411
412
2.60k
  if (m_priv->prettyPrint)
413
1.60k
  {
414
1.60k
    buf.append(m_priv->ppIndentL2);
415
1.60k
  }
416
417
2.60k
  appendQuotedEscapedString(buf, LOG4CXX_STR("file"));
418
2.60k
  buf.append(LOG4CXX_STR(": "));
419
2.60k
  LOG4CXX_DECODE_CHAR(fileName, locInfo.getFileName());
420
2.60k
  appendQuotedEscapedString(buf, fileName);
421
2.60k
  buf.append(LOG4CXX_STR(","));
422
2.60k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
423
424
2.60k
  if (m_priv->prettyPrint)
425
1.60k
  {
426
1.60k
    buf.append(m_priv->ppIndentL2);
427
1.60k
  }
428
429
2.60k
  appendQuotedEscapedString(buf, LOG4CXX_STR("line"));
430
2.60k
  buf.append(LOG4CXX_STR(": "));
431
2.60k
  LogString lineNumber;
432
2.60k
  StringHelper::toString(locInfo.getLineNumber(), p, lineNumber);
433
2.60k
  appendQuotedEscapedString(buf, lineNumber);
434
2.60k
  buf.append(LOG4CXX_STR(","));
435
2.60k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
436
437
2.60k
  if (m_priv->prettyPrint)
438
1.60k
  {
439
1.60k
    buf.append(m_priv->ppIndentL2);
440
1.60k
  }
441
442
2.60k
  appendQuotedEscapedString(buf, LOG4CXX_STR("class"));
443
2.60k
  buf.append(LOG4CXX_STR(": "));
444
2.60k
  LOG4CXX_DECODE_CHAR(className, locInfo.getClassName());
445
2.60k
  appendQuotedEscapedString(buf, className);
446
2.60k
  buf.append(LOG4CXX_STR(","));
447
2.60k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
448
449
2.60k
  if (m_priv->prettyPrint)
450
1.60k
  {
451
1.60k
    buf.append(m_priv->ppIndentL2);
452
1.60k
  }
453
454
2.60k
  appendQuotedEscapedString(buf, LOG4CXX_STR("method"));
455
2.60k
  buf.append(LOG4CXX_STR(": "));
456
2.60k
  LOG4CXX_DECODE_CHAR(methodName, locInfo.getMethodName());
457
2.60k
  appendQuotedEscapedString(buf, methodName);
458
2.60k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
459
460
2.60k
  if (m_priv->prettyPrint)
461
1.60k
  {
462
1.60k
    buf.append(m_priv->ppIndentL1);
463
1.60k
  }
464
465
2.60k
  buf.append(LOG4CXX_STR("}"));
466
2.60k
}
log4cxx::JSONLayout::appendSerializedLocationInfo(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, log4cxx::helpers::Pool&) const
Line
Count
Source
401
1.12k
{
402
1.12k
  if (m_priv->prettyPrint)
403
738
  {
404
738
    buf.append(m_priv->ppIndentL1);
405
738
  }
406
407
1.12k
  appendQuotedEscapedString(buf, LOG4CXX_STR("location_info"));
408
1.12k
  buf.append(LOG4CXX_STR(": {"));
409
1.12k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
410
1.12k
  const LocationInfo& locInfo = event->getLocationInformation();
411
412
1.12k
  if (m_priv->prettyPrint)
413
738
  {
414
738
    buf.append(m_priv->ppIndentL2);
415
738
  }
416
417
1.12k
  appendQuotedEscapedString(buf, LOG4CXX_STR("file"));
418
1.12k
  buf.append(LOG4CXX_STR(": "));
419
1.12k
  LOG4CXX_DECODE_CHAR(fileName, locInfo.getFileName());
420
1.12k
  appendQuotedEscapedString(buf, fileName);
421
1.12k
  buf.append(LOG4CXX_STR(","));
422
1.12k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
423
424
1.12k
  if (m_priv->prettyPrint)
425
738
  {
426
738
    buf.append(m_priv->ppIndentL2);
427
738
  }
428
429
1.12k
  appendQuotedEscapedString(buf, LOG4CXX_STR("line"));
430
1.12k
  buf.append(LOG4CXX_STR(": "));
431
1.12k
  LogString lineNumber;
432
1.12k
  StringHelper::toString(locInfo.getLineNumber(), p, lineNumber);
433
1.12k
  appendQuotedEscapedString(buf, lineNumber);
434
1.12k
  buf.append(LOG4CXX_STR(","));
435
1.12k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
436
437
1.12k
  if (m_priv->prettyPrint)
438
738
  {
439
738
    buf.append(m_priv->ppIndentL2);
440
738
  }
441
442
1.12k
  appendQuotedEscapedString(buf, LOG4CXX_STR("class"));
443
1.12k
  buf.append(LOG4CXX_STR(": "));
444
1.12k
  LOG4CXX_DECODE_CHAR(className, locInfo.getClassName());
445
1.12k
  appendQuotedEscapedString(buf, className);
446
1.12k
  buf.append(LOG4CXX_STR(","));
447
1.12k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
448
449
1.12k
  if (m_priv->prettyPrint)
450
738
  {
451
738
    buf.append(m_priv->ppIndentL2);
452
738
  }
453
454
1.12k
  appendQuotedEscapedString(buf, LOG4CXX_STR("method"));
455
1.12k
  buf.append(LOG4CXX_STR(": "));
456
1.12k
  LOG4CXX_DECODE_CHAR(methodName, locInfo.getMethodName());
457
1.12k
  appendQuotedEscapedString(buf, methodName);
458
1.12k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
459
460
1.12k
  if (m_priv->prettyPrint)
461
738
  {
462
738
    buf.append(m_priv->ppIndentL1);
463
738
  }
464
465
1.12k
  buf.append(LOG4CXX_STR("}"));
466
1.12k
}
log4cxx::JSONLayout::appendSerializedLocationInfo(std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >&, std::__1::shared_ptr<log4cxx::spi::LoggingEvent> const&, log4cxx::helpers::Pool&) const
Line
Count
Source
401
1.47k
{
402
1.47k
  if (m_priv->prettyPrint)
403
870
  {
404
870
    buf.append(m_priv->ppIndentL1);
405
870
  }
406
407
1.47k
  appendQuotedEscapedString(buf, LOG4CXX_STR("location_info"));
408
1.47k
  buf.append(LOG4CXX_STR(": {"));
409
1.47k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
410
1.47k
  const LocationInfo& locInfo = event->getLocationInformation();
411
412
1.47k
  if (m_priv->prettyPrint)
413
870
  {
414
870
    buf.append(m_priv->ppIndentL2);
415
870
  }
416
417
1.47k
  appendQuotedEscapedString(buf, LOG4CXX_STR("file"));
418
1.47k
  buf.append(LOG4CXX_STR(": "));
419
1.47k
  LOG4CXX_DECODE_CHAR(fileName, locInfo.getFileName());
420
1.47k
  appendQuotedEscapedString(buf, fileName);
421
1.47k
  buf.append(LOG4CXX_STR(","));
422
1.47k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
423
424
1.47k
  if (m_priv->prettyPrint)
425
870
  {
426
870
    buf.append(m_priv->ppIndentL2);
427
870
  }
428
429
1.47k
  appendQuotedEscapedString(buf, LOG4CXX_STR("line"));
430
1.47k
  buf.append(LOG4CXX_STR(": "));
431
1.47k
  LogString lineNumber;
432
1.47k
  StringHelper::toString(locInfo.getLineNumber(), p, lineNumber);
433
1.47k
  appendQuotedEscapedString(buf, lineNumber);
434
1.47k
  buf.append(LOG4CXX_STR(","));
435
1.47k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
436
437
1.47k
  if (m_priv->prettyPrint)
438
870
  {
439
870
    buf.append(m_priv->ppIndentL2);
440
870
  }
441
442
1.47k
  appendQuotedEscapedString(buf, LOG4CXX_STR("class"));
443
1.47k
  buf.append(LOG4CXX_STR(": "));
444
1.47k
  LOG4CXX_DECODE_CHAR(className, locInfo.getClassName());
445
1.47k
  appendQuotedEscapedString(buf, className);
446
1.47k
  buf.append(LOG4CXX_STR(","));
447
1.47k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
448
449
1.47k
  if (m_priv->prettyPrint)
450
870
  {
451
870
    buf.append(m_priv->ppIndentL2);
452
870
  }
453
454
1.47k
  appendQuotedEscapedString(buf, LOG4CXX_STR("method"));
455
1.47k
  buf.append(LOG4CXX_STR(": "));
456
1.47k
  LOG4CXX_DECODE_CHAR(methodName, locInfo.getMethodName());
457
1.47k
  appendQuotedEscapedString(buf, methodName);
458
1.47k
  buf.append(m_priv->prettyPrint ? LOG4CXX_EOL : LOG4CXX_STR(" "));
459
460
1.47k
  if (m_priv->prettyPrint)
461
870
  {
462
870
    buf.append(m_priv->ppIndentL1);
463
870
  }
464
465
1.47k
  buf.append(LOG4CXX_STR("}"));
466
1.47k
}
467