/src/logging-log4cxx/src/main/include/log4cxx/consoleappender.h
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 | | #ifndef _LOG4CXX_CONSOLE_APPENDER_H |
19 | | #define _LOG4CXX_CONSOLE_APPENDER_H |
20 | | |
21 | | #include <log4cxx/writerappender.h> |
22 | | |
23 | | namespace LOG4CXX_NS |
24 | | { |
25 | | |
26 | | /** |
27 | | * ConsoleAppender appends log events to <code>stdout</code> or |
28 | | * <code>stderr</code> using a layout specified by the user. |
29 | | * |
30 | | * The default target is <code>stdout</code>. |
31 | | * |
32 | | * You can use <a href="https://en.cppreference.com/w/c/io/fwide">fwide(stdout, 1)</a> in your configuration code |
33 | | * or use the cmake directive `LOG4CXX_FORCE_WIDE_CONSOLE=ON` when building Log4cxx |
34 | | * to force Log4cxx to use <a href="https://en.cppreference.com/w/c/io/fputws">fputws</a>. |
35 | | * If doing this ensure the cmake directive `LOG4CXX_WCHAR_T` is also enabled. |
36 | | */ |
37 | | class LOG4CXX_EXPORT ConsoleAppender : public WriterAppender |
38 | | { |
39 | | private: |
40 | | struct ConsoleAppenderPriv; |
41 | | |
42 | | public: |
43 | | DECLARE_LOG4CXX_OBJECT(ConsoleAppender) |
44 | 0 | BEGIN_LOG4CXX_CAST_MAP() |
45 | 0 | LOG4CXX_CAST_ENTRY(ConsoleAppender) |
46 | 0 | LOG4CXX_CAST_ENTRY_CHAIN(AppenderSkeleton) |
47 | 0 | END_LOG4CXX_CAST_MAP() |
48 | | |
49 | | /** |
50 | | * A <code>stdout</code> log event appender. |
51 | | * |
52 | | * See also #setLayout and #setTarget. |
53 | | */ |
54 | | ConsoleAppender(); |
55 | | |
56 | | /** |
57 | | * A <code>stdout</code> log event appender formatted using \c layout. |
58 | | * |
59 | | * @param layout formats a log event |
60 | | */ |
61 | | ConsoleAppender(const LayoutPtr& layout); |
62 | | |
63 | | /** |
64 | | * A \c target log event appender formatted using \c layout. |
65 | | * |
66 | | * @param layout formats a log event |
67 | | * @param target the value provided by #getSystemOut or #getSystemErr |
68 | | */ |
69 | | ConsoleAppender(const LayoutPtr& layout, const LogString& target); |
70 | | ~ConsoleAppender(); |
71 | | |
72 | | |
73 | | /** |
74 | | * Use \c newValue for the <b>target</b> property. |
75 | | * |
76 | | * @param newValue the value provided by #getSystemOut or #getSystemErr |
77 | | * */ |
78 | | void setTarget(const LogString& newValue); |
79 | | |
80 | | /** |
81 | | * @returns the current value of the <b>target</b> property. |
82 | | */ |
83 | | LogString getTarget() const; |
84 | | |
85 | | /** |
86 | | \copybrief WriterAppender::activateOptions() |
87 | | |
88 | | No action is performed in this implementation. |
89 | | */ |
90 | | void activateOptions(helpers::Pool& p) override; |
91 | | /** |
92 | | \copybrief WriterAppender::setOption() |
93 | | |
94 | | Supported options | Supported values | Default value |
95 | | -------------- | ---------------- | --------------- |
96 | | Target | System.err,System.out | System.out |
97 | | |
98 | | \sa WriterAppender::setOption() |
99 | | */ |
100 | | void setOption(const LogString& option, const LogString& value) override; |
101 | | |
102 | | /** |
103 | | * @returns the name recognised as <code>stdout</code>. |
104 | | */ |
105 | | static const LogString& getSystemOut(); |
106 | | |
107 | | /** |
108 | | * @returns the name recognised as <code>stderr</code>. |
109 | | */ |
110 | | static const LogString& getSystemErr(); |
111 | | |
112 | | |
113 | | private: |
114 | | void targetWarn(const LogString& val); |
115 | | |
116 | | }; |
117 | | LOG4CXX_PTR_DEF(ConsoleAppender); |
118 | | } //namespace log4cxx |
119 | | |
120 | | #endif //_LOG4CXX_CONSOLE_APPENDER_H |
121 | | |