/src/logging-log4cxx/src/main/include/log4cxx/xml/xmllayout.h
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 | | #ifndef _LOG4CXX_XML_LAYOUT_H |
19 | | #define _LOG4CXX_XML_LAYOUT_H |
20 | | |
21 | | #include <log4cxx/layout.h> |
22 | | |
23 | | namespace LOG4CXX_NS |
24 | | { |
25 | | namespace xml |
26 | | { |
27 | | |
28 | | /** |
29 | | The output of the XMLLayout consists of a series of log4j:event |
30 | | elements. It does not output a |
31 | | complete well-formed XML file. The output is designed to be |
32 | | included as an <em>external entity</em> in a separate file to form |
33 | | a correct XML file. |
34 | | |
35 | | <p>For example, if <code>abc</code> is the name of the file where |
36 | | the XMLLayout ouput goes, then a well-formed XML file would be: |
37 | | |
38 | | <code> |
39 | | <?xml version="1.0" ?> |
40 | | |
41 | | <!DOCTYPE log4j:eventSet [<!ENTITY data SYSTEM "abc">]> |
42 | | |
43 | | <log4j:eventSet version="1.2" xmlns:log4j="http://jakarta.apache.org/log4j/"> |
44 | | |
45 | | @&data; |
46 | | |
47 | | </log4j:eventSet> |
48 | | </code> |
49 | | |
50 | | <p>This approach enforces the independence of the XMLLayout and the |
51 | | appender where it is embedded. |
52 | | */ |
53 | | class LOG4CXX_EXPORT XMLLayout : public Layout |
54 | | { |
55 | | private: |
56 | | LOG4CXX_DECLARE_PRIVATE_MEMBER_PTR(XMLLayoutPrivate, m_priv) |
57 | | |
58 | | public: |
59 | | DECLARE_LOG4CXX_OBJECT(XMLLayout) |
60 | 0 | BEGIN_LOG4CXX_CAST_MAP() |
61 | 0 | LOG4CXX_CAST_ENTRY(XMLLayout) |
62 | 0 | LOG4CXX_CAST_ENTRY_CHAIN(Layout) |
63 | 0 | END_LOG4CXX_CAST_MAP() |
64 | | |
65 | | XMLLayout(); |
66 | | ~XMLLayout(); |
67 | | |
68 | | /** |
69 | | The <b>LocationInfo</b> option takes a boolean value. By |
70 | | default, it is set to false which means there will be no location |
71 | | information output by this layout. If the the option is set to |
72 | | true, then the file name and line number of the statement |
73 | | at the origin of the log statement will be output. |
74 | | |
75 | | <p>If you are embedding this layout within a SMTPAppender |
76 | | then make sure to set the |
77 | | <b>LocationInfo</b> option of that appender as well. |
78 | | */ |
79 | | void setLocationInfo(bool locationInfo1); |
80 | | |
81 | | /** |
82 | | Returns the current value of the <b>LocationInfo</b> option. |
83 | | */ |
84 | | bool getLocationInfo() const; |
85 | | |
86 | | /** |
87 | | * Sets whether MDC key-value pairs should be output, default false. |
88 | | * @param flag new value. |
89 | | * |
90 | | */ |
91 | | void setProperties(bool flag); |
92 | | |
93 | | /** |
94 | | * Gets whether MDC key-value pairs should be output. |
95 | | * @return true if MDC key-value pairs are output. |
96 | | * |
97 | | */ |
98 | | bool getProperties(); |
99 | | |
100 | | /** |
101 | | \copybrief spi::OptionHandler::activateOptions() |
102 | | |
103 | | No action is performed in this implementation. |
104 | | */ |
105 | 0 | void activateOptions(helpers::Pool& /* p */) override { } |
106 | | |
107 | | /** |
108 | | \copybrief spi::OptionHandler::setOption() |
109 | | |
110 | | Supported options | Supported values | Default value | |
111 | | -------------- | ---------------- | --------------- | |
112 | | Properties | True,False | False | |
113 | | LocationInfo | True,False | False | |
114 | | */ |
115 | | void setOption(const LogString& option, |
116 | | const LogString& value) override; |
117 | | |
118 | | /** |
119 | | * Formats a {@link spi::LoggingEvent LoggingEvent} |
120 | | * in conformance with the log4cxx.dtd. |
121 | | **/ |
122 | | void format(LogString& output, |
123 | | const spi::LoggingEventPtr& event, |
124 | | helpers::Pool& p) const override; |
125 | | |
126 | | /** |
127 | | The XMLLayout prints and does not ignore exceptions. Hence the |
128 | | return value <code>false</code>. |
129 | | */ |
130 | | bool ignoresThrowable() const override |
131 | 0 | { |
132 | 0 | return false; |
133 | 0 | } |
134 | | |
135 | | }; // class XMLLayout |
136 | | LOG4CXX_PTR_DEF(XMLLayout); |
137 | | } // namespace xml |
138 | | } // namespace log4cxx |
139 | | |
140 | | #endif // _LOG4CXX_XML_LAYOUT_H |