/src/logging-log4cxx/src/main/include/log4cxx/pattern/datepatternconverter.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_PATTERN_DATE_PATTERN_CONVERTER |
19 | | #define _LOG4CXX_PATTERN_DATE_PATTERN_CONVERTER |
20 | | |
21 | | #include <log4cxx/pattern/loggingeventpatternconverter.h> |
22 | | #include <log4cxx/helpers/cacheddateformat.h> |
23 | | #include <log4cxx/helpers/date.h> |
24 | | #include <vector> |
25 | | |
26 | | namespace LOG4CXX_NS |
27 | | { |
28 | | namespace pattern |
29 | | { |
30 | | |
31 | | |
32 | | /** |
33 | | * Convert and format a date or timestamp into a string. |
34 | | */ |
35 | | class LOG4CXX_EXPORT DatePatternConverter : public LoggingEventPatternConverter |
36 | | { |
37 | | struct DatePatternConverterPrivate; |
38 | | |
39 | | /** |
40 | | * Obtains an instance of pattern converter. |
41 | | * @param options options, may be null. |
42 | | * @return instance of pattern converter. |
43 | | */ |
44 | | static helpers::DateFormatPtr getDateFormat(const OptionsList& options); |
45 | | public: |
46 | | DECLARE_LOG4CXX_PATTERN(DatePatternConverter) |
47 | 8.15k | BEGIN_LOG4CXX_CAST_MAP() |
48 | 8.15k | LOG4CXX_CAST_ENTRY(DatePatternConverter) |
49 | 0 | LOG4CXX_CAST_ENTRY_CHAIN(LoggingEventPatternConverter) |
50 | 0 | END_LOG4CXX_CAST_MAP() |
51 | | |
52 | | /** |
53 | | * An object that can convert a date or timestamp to the format |
54 | | * described by the conversion specifier in the first element in \c options. |
55 | | * |
56 | | * If the conversion specifier contains a \% character, |
57 | | * the date is formated using <a href="https://en.cppreference.com/w/cpp/chrono/c/strftime">strftime</a>. |
58 | | * |
59 | | * Otherwise the conversion specifier must be a pattern compatible with |
60 | | * java.text.SimpleDateFormat, "ABSOLUTE", "DATE" or "ISO8601". |
61 | | * For example, "HH:mm:ss,SSS", "dd MMM yyyy HH:mm:ss,SSS" or "DATE". |
62 | | * |
63 | | * ISO8601 format is assumed if the first element in \c options missing or empty. |
64 | | * |
65 | | * If \c options has a second element, it is assumed to be a time zone specifier, |
66 | | * for example, "GMT-6" |
67 | | */ |
68 | | DatePatternConverter(const OptionsList& options); |
69 | | |
70 | | ~DatePatternConverter(); |
71 | | |
72 | | /** |
73 | | * \copydoc #DatePatternConverter::DatePatternConverter() |
74 | | */ |
75 | | static PatternConverterPtr newInstance( |
76 | | const std::vector<LogString>& options); |
77 | | |
78 | | /** |
79 | | * Append to \c output a textual version of the timestamp in \c event. |
80 | | */ |
81 | | void format(const spi::LoggingEventPtr& event, |
82 | | LogString& output, |
83 | | helpers::Pool& p) const override; |
84 | | |
85 | | /** |
86 | | * Append to \c output a textual version of the date or timestamp in \c obj. |
87 | | * |
88 | | * Nothing is added to \c output if \c obj does not point to a Date or spi::LoggingEvent. |
89 | | */ |
90 | | void format(const helpers::ObjectPtr& obj, |
91 | | LogString& output, |
92 | | helpers::Pool& p) const override; |
93 | | |
94 | | /** |
95 | | * Append to \c toAppendTo a textual version of \c date. |
96 | | */ |
97 | | void format(const helpers::DatePtr& date, |
98 | | LogString& toAppendTo, |
99 | | helpers::Pool& p) const; |
100 | | }; |
101 | | |
102 | | LOG4CXX_PTR_DEF(DatePatternConverter); |
103 | | |
104 | | } |
105 | | } |
106 | | #endif |
107 | | |