/src/logging-log4cxx/src/main/cpp/namepatternconverter.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/namepatternconverter.h> |
20 | | #include <log4cxx/pattern/nameabbreviator.h> |
21 | | #include <log4cxx/spi/loggingevent.h> |
22 | | #include <log4cxx/private/patternconverter_priv.h> |
23 | | |
24 | | using namespace LOG4CXX_NS; |
25 | | using namespace LOG4CXX_NS::pattern; |
26 | | using namespace LOG4CXX_NS::spi; |
27 | | |
28 | 0 | #define priv static_cast<NamePatternConverterPrivate*>(m_priv.get()) |
29 | | |
30 | | struct NamePatternConverter::NamePatternConverterPrivate : public PatternConverterPrivate |
31 | | { |
32 | | NamePatternConverterPrivate( const LogString& name, const LogString& style, const NameAbbreviatorPtr abbrev ) : |
33 | 0 | PatternConverterPrivate( name, style ), |
34 | 0 | abbreviator(abbrev) {} |
35 | | |
36 | | /** |
37 | | * Abbreviator. |
38 | | */ |
39 | | const NameAbbreviatorPtr abbreviator; |
40 | | }; |
41 | | |
42 | | IMPLEMENT_LOG4CXX_OBJECT(NamePatternConverter) |
43 | | |
44 | | NamePatternConverter::NamePatternConverter( |
45 | | const LogString& name1, |
46 | | const LogString& style1, |
47 | | const std::vector<LogString>& options) : |
48 | 0 | LoggingEventPatternConverter(std::make_unique<NamePatternConverterPrivate>(name1, style1, |
49 | 0 | getAbbreviator(options))) |
50 | 0 | { |
51 | 0 | } |
52 | | |
53 | | NameAbbreviatorPtr NamePatternConverter::getAbbreviator( |
54 | | const std::vector<LogString>& options) |
55 | 0 | { |
56 | 0 | if (options.size() > 0) |
57 | 0 | { |
58 | 0 | return NameAbbreviator::getAbbreviator(options[0]); |
59 | 0 | } |
60 | | |
61 | 0 | return NameAbbreviator::getDefaultAbbreviator(); |
62 | 0 | } |
63 | | |
64 | | /** |
65 | | * Abbreviate name in string buffer. |
66 | | * @param nameStart starting position of name to abbreviate. |
67 | | * @param buf string buffer containing name. |
68 | | */ |
69 | | void NamePatternConverter::abbreviate(LogString::size_type nameStart, LogString& buf) const |
70 | 0 | { |
71 | 0 | priv->abbreviator->abbreviate(nameStart, buf); |
72 | 0 | } |