/src/logging-log4cxx/src/main/cpp/consoleappender.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 | | #include <log4cxx/logstring.h> |
18 | | #include <log4cxx/consoleappender.h> |
19 | | #include <log4cxx/helpers/loglog.h> |
20 | | #include <log4cxx/helpers/systemoutwriter.h> |
21 | | #include <log4cxx/helpers/systemerrwriter.h> |
22 | | #include <log4cxx/helpers/stringhelper.h> |
23 | | #include <log4cxx/layout.h> |
24 | | #include <log4cxx/private/appenderskeleton_priv.h> |
25 | | #include <log4cxx/private/writerappender_priv.h> |
26 | | |
27 | | using namespace LOG4CXX_NS; |
28 | | using namespace LOG4CXX_NS::helpers; |
29 | | |
30 | | struct ConsoleAppender::ConsoleAppenderPriv : public WriterAppender::WriterAppenderPriv |
31 | | { |
32 | | ConsoleAppenderPriv(LogString target) : |
33 | 0 | WriterAppenderPriv(), |
34 | 0 | target(target) {} |
35 | | |
36 | | LogString target; |
37 | | }; |
38 | | |
39 | 0 | #define _priv static_cast<ConsoleAppenderPriv*>(m_priv.get()) |
40 | | |
41 | | IMPLEMENT_LOG4CXX_OBJECT(ConsoleAppender) |
42 | | |
43 | | ConsoleAppender::ConsoleAppender() |
44 | 0 | : WriterAppender (std::make_unique<ConsoleAppenderPriv>(getSystemOut())) |
45 | 0 | { |
46 | 0 | } Unexecuted instantiation: log4cxx::ConsoleAppender::ConsoleAppender() Unexecuted instantiation: log4cxx::ConsoleAppender::ConsoleAppender() |
47 | | |
48 | | ConsoleAppender::ConsoleAppender(const LayoutPtr& layout) |
49 | 0 | : WriterAppender (std::make_unique<ConsoleAppenderPriv>(getSystemOut())) |
50 | 0 | { |
51 | 0 | setLayout(layout); |
52 | 0 | Pool p; |
53 | 0 | setWriter(std::make_shared<SystemOutWriter>()); |
54 | 0 | WriterAppender::activateOptions(p); |
55 | 0 | } Unexecuted instantiation: log4cxx::ConsoleAppender::ConsoleAppender(std::__1::shared_ptr<log4cxx::Layout> const&) Unexecuted instantiation: log4cxx::ConsoleAppender::ConsoleAppender(std::__1::shared_ptr<log4cxx::Layout> const&) |
56 | | |
57 | | ConsoleAppender::ConsoleAppender(const LayoutPtr& layout, const LogString& target) |
58 | 0 | : WriterAppender (std::make_unique<ConsoleAppenderPriv>(target)) |
59 | 0 | { |
60 | 0 | setLayout(layout); |
61 | 0 | setTarget(target); |
62 | 0 | Pool p; |
63 | 0 | ConsoleAppender::activateOptions(p); |
64 | 0 | } Unexecuted instantiation: log4cxx::ConsoleAppender::ConsoleAppender(std::__1::shared_ptr<log4cxx::Layout> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) Unexecuted instantiation: log4cxx::ConsoleAppender::ConsoleAppender(std::__1::shared_ptr<log4cxx::Layout> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) |
65 | | |
66 | | ConsoleAppender::~ConsoleAppender() |
67 | 0 | { |
68 | 0 | finalize(); |
69 | 0 | } |
70 | | |
71 | | const LogString& ConsoleAppender::getSystemOut() |
72 | 0 | { |
73 | 0 | static const WideLife<LogString> name(LOG4CXX_STR("System.out")); |
74 | 0 | return name; |
75 | 0 | } |
76 | | |
77 | | const LogString& ConsoleAppender::getSystemErr() |
78 | 0 | { |
79 | 0 | static const WideLife<LogString> name(LOG4CXX_STR("System.err")); |
80 | 0 | return name; |
81 | 0 | } |
82 | | |
83 | | void ConsoleAppender::setTarget(const LogString& value) |
84 | 0 | { |
85 | 0 | LogString v = StringHelper::trim(value); |
86 | |
|
87 | 0 | if (StringHelper::equalsIgnoreCase(v, |
88 | 0 | LOG4CXX_STR("SYSTEM.OUT"), LOG4CXX_STR("system.out"))) |
89 | 0 | { |
90 | 0 | _priv->target = getSystemOut(); |
91 | 0 | } |
92 | 0 | else if (StringHelper::equalsIgnoreCase(v, |
93 | 0 | LOG4CXX_STR("SYSTEM.ERR"), LOG4CXX_STR("system.err"))) |
94 | 0 | { |
95 | 0 | _priv->target = getSystemErr(); |
96 | 0 | } |
97 | 0 | else |
98 | 0 | { |
99 | 0 | targetWarn(value); |
100 | 0 | } |
101 | 0 | } |
102 | | |
103 | | LogString ConsoleAppender::getTarget() const |
104 | 0 | { |
105 | 0 | return _priv->target; |
106 | 0 | } |
107 | | |
108 | | void ConsoleAppender::targetWarn(const LogString& val) |
109 | 0 | { |
110 | 0 | LogLog::warn(((LogString) LOG4CXX_STR("[")) |
111 | 0 | + val + LOG4CXX_STR("] should be system.out or system.err.")); |
112 | 0 | LogLog::warn(LOG4CXX_STR("Using previously set target, System.out by default.")); |
113 | 0 | } |
114 | | |
115 | | void ConsoleAppender::activateOptions(Pool& p) |
116 | 0 | { |
117 | 0 | if (StringHelper::equalsIgnoreCase(_priv->target, |
118 | 0 | LOG4CXX_STR("SYSTEM.OUT"), LOG4CXX_STR("system.out"))) |
119 | 0 | { |
120 | 0 | WriterPtr writer1 = std::make_shared<SystemOutWriter>(); |
121 | 0 | setWriter(writer1); |
122 | 0 | } |
123 | 0 | else if (StringHelper::equalsIgnoreCase(_priv->target, |
124 | 0 | LOG4CXX_STR("SYSTEM.ERR"), LOG4CXX_STR("system.err"))) |
125 | 0 | { |
126 | 0 | WriterPtr writer1 = std::make_shared<SystemErrWriter>(); |
127 | 0 | setWriter(writer1); |
128 | 0 | } |
129 | |
|
130 | 0 | WriterAppender::activateOptions(p); |
131 | 0 | } |
132 | | |
133 | | void ConsoleAppender::setOption(const LogString& option, const LogString& value) |
134 | 0 | { |
135 | 0 | if (StringHelper::equalsIgnoreCase(option, |
136 | 0 | LOG4CXX_STR("TARGET"), LOG4CXX_STR("target"))) |
137 | 0 | { |
138 | 0 | setTarget(value); |
139 | 0 | } |
140 | 0 | else |
141 | 0 | { |
142 | 0 | WriterAppender::setOption(option, value); |
143 | 0 | } |
144 | 0 | } |
145 | | |
146 | | |
147 | | |
148 | | |
149 | | |
150 | | |