[89] | 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_PATTERN_CONVERTER_H
|
---|
| 19 | #define _LOG4CXX_PATTERN_PATTERN_CONVERTER_H
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | #include <log4cxx/helpers/objectimpl.h>
|
---|
| 23 | #include <log4cxx/logstring.h>
|
---|
| 24 | #include <vector>
|
---|
| 25 |
|
---|
| 26 | #ifdef _MSC_VER
|
---|
| 27 | // disable identifier too wide for debugging warning
|
---|
| 28 | #pragma warning ( disable: 4231 4251 4275 4786 )
|
---|
| 29 | #endif
|
---|
| 30 |
|
---|
| 31 | #define DECLARE_LOG4CXX_PATTERN(cls) DECLARE_ABSTRACT_LOG4CXX_OBJECT(cls)
|
---|
| 32 |
|
---|
| 33 | namespace log4cxx {
|
---|
| 34 | namespace pattern {
|
---|
| 35 |
|
---|
| 36 | typedef std::vector<LogString> OptionsList;
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 |
|
---|
| 40 | <p>PatternConverter is an abstract class that provides the
|
---|
| 41 | formatting functionality that derived classes need.
|
---|
| 42 |
|
---|
| 43 | <p>Conversion specifiers in a conversion patterns are parsed to
|
---|
| 44 | individual PatternConverters. Each of which is responsible for
|
---|
| 45 | converting an object in a converter specific manner.
|
---|
| 46 |
|
---|
| 47 | */
|
---|
| 48 | class LOG4CXX_EXPORT PatternConverter : public virtual log4cxx::helpers::ObjectImpl {
|
---|
| 49 |
|
---|
| 50 | /**
|
---|
| 51 | * Converter name.
|
---|
| 52 | */
|
---|
| 53 | const LogString name;
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * Converter style name.
|
---|
| 57 | */
|
---|
| 58 | const LogString style;
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | protected:
|
---|
| 62 | /**
|
---|
| 63 | * Create a new pattern converter.
|
---|
| 64 | * @param name name for pattern converter.
|
---|
| 65 | * @param style CSS style for formatted output.
|
---|
| 66 | */
|
---|
| 67 | PatternConverter(const LogString& name,
|
---|
| 68 | const LogString& style);
|
---|
| 69 |
|
---|
| 70 | virtual ~PatternConverter();
|
---|
| 71 |
|
---|
| 72 | public:
|
---|
| 73 | DECLARE_LOG4CXX_PATTERN(PatternConverter)
|
---|
| 74 | BEGIN_LOG4CXX_CAST_MAP()
|
---|
| 75 | LOG4CXX_CAST_ENTRY(PatternConverter)
|
---|
| 76 | END_LOG4CXX_CAST_MAP()
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * Formats an object into a string buffer.
|
---|
| 80 | * @param obj event to format, may not be null.
|
---|
| 81 | * @param toAppendTo string buffer to which the formatted event will be appended. May not be null.
|
---|
| 82 | * @param p pool for any allocations necessary during formatting.
|
---|
| 83 | */
|
---|
| 84 | virtual void format(const log4cxx::helpers::ObjectPtr& obj,
|
---|
| 85 | LogString& toAppendTo,
|
---|
| 86 | log4cxx::helpers::Pool& p) const = 0;
|
---|
| 87 |
|
---|
| 88 | /**
|
---|
| 89 | * This method returns the name of the conversion pattern.
|
---|
| 90 | *
|
---|
| 91 | * The name can be useful to certain Layouts such as HTMLLayout.
|
---|
| 92 | *
|
---|
| 93 | * @return the name of the conversion pattern
|
---|
| 94 | */
|
---|
| 95 | LogString getName() const;
|
---|
| 96 |
|
---|
| 97 | /**
|
---|
| 98 | * This method returns the CSS style class that should be applied to
|
---|
| 99 | * the LoggingEvent passed as parameter, which can be null.
|
---|
| 100 | *
|
---|
| 101 | * This information is currently used only by HTMLLayout.
|
---|
| 102 | *
|
---|
| 103 | * @param e null values are accepted
|
---|
| 104 | * @return the name of the conversion pattern
|
---|
| 105 | */
|
---|
| 106 | virtual LogString getStyleClass(const log4cxx::helpers::ObjectPtr& e) const;
|
---|
| 107 |
|
---|
| 108 | protected:
|
---|
| 109 | /**
|
---|
| 110 | * Appends content in the locale code page to a LogString.
|
---|
| 111 | * @param toAppendTo string to which content is appended.
|
---|
| 112 | * @param src content.
|
---|
| 113 | */
|
---|
| 114 | static void append(LogString& toAppendTo, const std::string& src);
|
---|
| 115 | };
|
---|
| 116 |
|
---|
| 117 |
|
---|
| 118 | LOG4CXX_PTR_DEF(PatternConverter);
|
---|
| 119 |
|
---|
| 120 | }
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 |
|
---|
| 124 | #endif
|
---|