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_TTCC_LAYOUT_H
|
---|
19 | #define _LOG4CXX_TTCC_LAYOUT_H
|
---|
20 |
|
---|
21 | #if defined(_MSC_VER)
|
---|
22 | #pragma warning ( push )
|
---|
23 | #pragma warning ( disable: 4231 4251 4275 4786 )
|
---|
24 | #endif
|
---|
25 |
|
---|
26 | #include <log4cxx/helpers/datelayout.h>
|
---|
27 |
|
---|
28 | namespace log4cxx
|
---|
29 | {
|
---|
30 |
|
---|
31 | /**
|
---|
32 | TTCC layout format consists of time, thread, logger name and nested
|
---|
33 | diagnostic context information, hence the name.
|
---|
34 |
|
---|
35 | <p>Each of the four fields can be individually enabled or
|
---|
36 | disabled. The time format depends on the <code>DateFormat</code>
|
---|
37 | used.
|
---|
38 |
|
---|
39 | <p>Here is an example TTCCLayout output with the
|
---|
40 | {@link helpers::RelativeTimeDateFormat RelativeTimeDateFormat}.
|
---|
41 |
|
---|
42 | <pre>
|
---|
43 | 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
|
---|
44 | 225 [main] INFO examples.SortAlgo - Entered the sort method.
|
---|
45 | 262 [main] DEBUG examples.SortAlgo.OUTER i=1 - Outer loop.
|
---|
46 | 276 [main] DEBUG examples.SortAlgo.SWAP i=1 j=0 - Swapping intArray[0] = 1 and intArray[1] = 0
|
---|
47 | 290 [main] DEBUG examples.SortAlgo.OUTER i=0 - Outer loop.
|
---|
48 | 304 [main] INFO examples.SortAlgo.DUMP - Dump of interger array:
|
---|
49 | 317 [main] INFO examples.SortAlgo.DUMP - Element [0] = 0
|
---|
50 | 331 [main] INFO examples.SortAlgo.DUMP - Element [1] = 1
|
---|
51 | 343 [main] INFO examples.Sort - The next log statement should be an error message.
|
---|
52 | 346 [main] ERROR examples.SortAlgo.DUMP - Tried to dump an uninitialized array.
|
---|
53 | 467 [main] INFO examples.Sort - Exiting main method.
|
---|
54 | </pre>
|
---|
55 |
|
---|
56 | <p>The first field is the number of milliseconds elapsed since the
|
---|
57 | start of the program. The second field is the thread outputting the
|
---|
58 | log statement. The third field is the level, the fourth field is
|
---|
59 | the logger to which the statement belongs.
|
---|
60 |
|
---|
61 | <p>The fifth field (just before the '-') is the nested diagnostic
|
---|
62 | context. Note the nested diagnostic context may be empty as in the
|
---|
63 | first two statements. The text after the '-' is the message of the
|
---|
64 | statement.
|
---|
65 |
|
---|
66 | <p><b>WARNING</b> Do not use the same TTCCLayout instance from
|
---|
67 | within different appenders. The TTCCLayout is not thread safe when
|
---|
68 | used in his way. However, it is perfectly safe to use a TTCCLayout
|
---|
69 | instance from just one appender.
|
---|
70 |
|
---|
71 | <p>PatternLayout offers a much more flexible alternative.
|
---|
72 | */
|
---|
73 | class LOG4CXX_EXPORT TTCCLayout : public helpers::DateLayout
|
---|
74 | {
|
---|
75 | private:
|
---|
76 | // Internal representation of options
|
---|
77 | bool threadPrinting;
|
---|
78 | bool categoryPrefixing;
|
---|
79 | bool contextPrinting;
|
---|
80 | bool filePrinting;
|
---|
81 |
|
---|
82 | public:
|
---|
83 | DECLARE_LOG4CXX_OBJECT(TTCCLayout)
|
---|
84 | BEGIN_LOG4CXX_CAST_MAP()
|
---|
85 | LOG4CXX_CAST_ENTRY(TTCCLayout)
|
---|
86 | LOG4CXX_CAST_ENTRY_CHAIN(Layout)
|
---|
87 | END_LOG4CXX_CAST_MAP()
|
---|
88 |
|
---|
89 | /**
|
---|
90 | Instantiate a TTCCLayout object with {@link
|
---|
91 | helpers::RelativeTimeDateFormat RelativeTimeDateFormat} as the date
|
---|
92 | formatter in the local time zone.
|
---|
93 | */
|
---|
94 | TTCCLayout();
|
---|
95 |
|
---|
96 | /**
|
---|
97 | Instantiate a TTCCLayout object using the local time zone. The
|
---|
98 | DateFormat used will depend on the <code>dateFormatType</code>.
|
---|
99 | <p>This constructor just calls the {@link
|
---|
100 | helpers::DateLayout#setDateFormat DateLayout::setDateFormat} method.
|
---|
101 | */
|
---|
102 | TTCCLayout(const LogString& dateFormatType);
|
---|
103 |
|
---|
104 | /**
|
---|
105 | The <b>ThreadPrinting</b> option specifies whether the name of the
|
---|
106 | current thread is part of log output or not. This is true by default.
|
---|
107 | */
|
---|
108 | inline void setThreadPrinting(bool threadPrinting1)
|
---|
109 | { this->threadPrinting = threadPrinting1; }
|
---|
110 |
|
---|
111 | /**
|
---|
112 | Returns value of the <b>ThreadPrinting</b> option.
|
---|
113 | */
|
---|
114 | inline bool getThreadPrinting() const
|
---|
115 | { return threadPrinting; }
|
---|
116 |
|
---|
117 | /**
|
---|
118 | The <b>CategoryPrefixing</b> option specifies whether Logger
|
---|
119 | name is part of log output or not. This is true by default.
|
---|
120 | */
|
---|
121 | inline void setCategoryPrefixing(bool categoryPrefixing1)
|
---|
122 | { this->categoryPrefixing = categoryPrefixing1; }
|
---|
123 |
|
---|
124 | /**
|
---|
125 | Returns value of the <b>CategoryPrefixing</b> option.
|
---|
126 | */
|
---|
127 | inline bool getCategoryPrefixing() const
|
---|
128 | { return categoryPrefixing; }
|
---|
129 |
|
---|
130 | /**
|
---|
131 | The <b>ContextPrinting</b> option specifies log output will include
|
---|
132 | the nested context information belonging to the current thread.
|
---|
133 | This is true by default.
|
---|
134 | */
|
---|
135 | inline void setContextPrinting(bool contextPrinting1)
|
---|
136 | { this->contextPrinting = contextPrinting1; }
|
---|
137 |
|
---|
138 | /**
|
---|
139 | Returns value of the <b>ContextPrinting</b> option.
|
---|
140 | */
|
---|
141 | inline bool getContextPrinting() const
|
---|
142 | { return contextPrinting; }
|
---|
143 |
|
---|
144 | /**
|
---|
145 | The <b>FilePrinting</b> option specifies log output will include
|
---|
146 | the file and the line where the log statement was written.
|
---|
147 | */
|
---|
148 | inline void setFilePrinting(bool filePrinting1)
|
---|
149 | { this->filePrinting = filePrinting1; }
|
---|
150 |
|
---|
151 | /**
|
---|
152 | Returns value of the <b>ContextPrinting</b> option.
|
---|
153 | */
|
---|
154 | inline bool getFilePrinting() const
|
---|
155 | { return filePrinting; }
|
---|
156 |
|
---|
157 | /**
|
---|
158 | In addition to the level of the statement and message, this function
|
---|
159 | writes to the ouput stream time, thread, logger and NDC
|
---|
160 | information.
|
---|
161 |
|
---|
162 | <p>Time, thread, logger and diagnostic context are printed
|
---|
163 | depending on options.
|
---|
164 |
|
---|
165 | @param output destination to receive formatted output.
|
---|
166 | @param event event to format.
|
---|
167 | @param pool pool used to allocate memory needed during formatting.
|
---|
168 | */
|
---|
169 | virtual void format(LogString& output,
|
---|
170 | const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& pool) const;
|
---|
171 |
|
---|
172 | /**
|
---|
173 | The TTCCLayout does not handle the throwable contained within
|
---|
174 | {@link spi::LoggingEvent LoggingEvents}. Thus, it returns
|
---|
175 | <code>true</code>.
|
---|
176 | */
|
---|
177 | virtual bool ignoresThrowable() const { return true; }
|
---|
178 | };
|
---|
179 | LOG4CXX_PTR_DEF(TTCCLayout);
|
---|
180 | }
|
---|
181 |
|
---|
182 |
|
---|
183 | #if defined(_MSC_VER)
|
---|
184 | #pragma warning ( pop )
|
---|
185 | #endif
|
---|
186 |
|
---|
187 | #endif
|
---|