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_HELPERS_DATE_LAYOUT_H 19 #define _LOG4CXX_HELPERS_DATE_LAYOUT_H 20 21 #include <log4cxx/layout.h> 22 #include <log4cxx/helpers/dateformat.h> 23 #include <log4cxx/helpers/timezone.h> 24 25 #if defined(_MSC_VER) 26 #pragma warning ( push ) 27 #pragma warning ( disable: 4251 ) 28 #endif 29 30 namespace log4cxx 31 { 32 namespace helpers 33 { 34 /** 35 This abstract layout takes care of all the date related options and 36 formatting work. 37 */ 38 class LOG4CXX_EXPORT DateLayout : public Layout 39 { 40 private: 41 LogString timeZoneID; 42 LogString dateFormatOption; 43 44 protected: 45 DateFormatPtr dateFormat; 46 47 public: 48 DateLayout(const LogString& dateLayoutOption); 49 virtual ~DateLayout(); 50 51 virtual void activateOptions(log4cxx::helpers::Pool& p); 52 virtual void setOption(const LogString& option, const LogString& value); 53 54 /** 55 The value of the <b>DateFormat</b> option should be either an 56 argument to the constructor of helpers::DateFormat or one of 57 the strings <b>"NULL"</b>, <b>"RELATIVE"</b>, <b>"ABSOLUTE"</b>, 58 <b>"DATE"</b> or <b>"ISO8601</b>. 59 */ setDateFormat(const LogString & dateFormat1)60 inline void setDateFormat(const LogString& dateFormat1) 61 { 62 this->dateFormatOption.assign(dateFormat1); 63 } 64 65 /** 66 Returns value of the <b>DateFormat</b> option. 67 */ getDateFormat()68 inline const LogString& getDateFormat() const 69 { 70 return dateFormatOption; 71 } 72 73 /** 74 The <b>TimeZoneID</b> option is a time zone ID string in the format 75 expected by the <code>locale</code> C++ standard class. 76 */ setTimeZone(const LogString & timeZone)77 inline void setTimeZone(const LogString& timeZone) 78 { 79 this->timeZoneID.assign(timeZone); 80 } 81 82 /** 83 Returns value of the <b>TimeZone</b> option. 84 */ getTimeZone()85 inline const LogString& getTimeZone() const 86 { 87 return timeZoneID; 88 } 89 90 void formatDate(LogString& s, 91 const spi::LoggingEventPtr& event, 92 log4cxx::helpers::Pool& p) const; 93 94 private: 95 // 96 // prevent copy and assignment 97 DateLayout(const DateLayout&); 98 DateLayout& operator=(const DateLayout&); 99 100 }; 101 } // namespace helpers 102 } // namespace log4cxx 103 104 #if defined(_MSC_VER) 105 #pragma warning (pop) 106 #endif 107 108 #endif // _LOG4CXX_HELPERS_DATE_LAYOUT_H 109