00001 /****************************************************************************** 00002 * 00003 * package: Log4Qt 00004 * file: ttcclayout.h 00005 * created: September 2007 00006 * author: Martin Heinrich 00007 * 00008 * 00009 * Copyright 2007 Martin Heinrich 00010 * 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 * 00023 ******************************************************************************/ 00024 00025 #ifndef LOG4QT_TTCCLAYOUT_H 00026 #define LOG4QT_TTCCLAYOUT_H 00027 00028 00029 /****************************************************************************** 00030 * Dependencies 00031 ******************************************************************************/ 00032 00033 #include "log4qt/layout.h" 00034 00035 00036 /****************************************************************************** 00037 * Declarations 00038 ******************************************************************************/ 00039 00040 namespace Log4Qt 00041 { 00042 00043 class LoggingEvent; 00044 class PatternFormatter; 00045 00053 class TTCCLayout : public Layout 00054 { 00055 Q_OBJECT 00056 00064 Q_PROPERTY(bool categoryPrefixing READ categoryPrefixing WRITE setCategoryPrefixing) 00065 00066 00074 Q_PROPERTY(bool contextPrinting READ contextPrinting WRITE setContextPrinting) 00075 00083 Q_PROPERTY(QString dateFormat READ dateFormat WRITE setDateFormat) 00084 00092 Q_PROPERTY(bool threadPrinting READ threadPrinting WRITE setThreadPrinting) 00093 00094 public: 00100 enum DateFormat 00101 { 00103 NONE, 00108 ISO8601, 00113 ABSOLUTE, 00118 DATE, 00123 RELATIVE 00124 }; 00125 Q_ENUMS(DateFormat) 00126 00127 TTCCLayout(QObject *pParent = 0); 00128 TTCCLayout(const QString &rDateFormat, 00129 QObject *pParent = 0); 00130 00135 TTCCLayout(DateFormat dateFormat, 00136 QObject *pParent = 0); 00137 00138 virtual ~TTCCLayout(); 00139 private: 00140 TTCCLayout(const TTCCLayout &rOther); // Not implemented 00141 TTCCLayout &operator=(const TTCCLayout &rOther); // Not implemented 00142 00143 public: 00144 bool categoryPrefixing() const; 00145 bool contextPrinting() const; 00146 QString dateFormat() const; 00147 // JAVA: bool ignoresThrowable() const; 00148 bool threadPrinting() const; 00149 void setCategoryPrefixing(bool categoryPrefixing); 00150 void setContextPrinting(bool contextPrinting); 00151 void setDateFormat(const QString &rDateFormat); 00152 00157 void setDateFormat(DateFormat dateFormat); 00158 00159 // JAVA: setIgnoresThrowable(bool ignoresThrowable); 00160 void setThreadPrinting(bool threadPrinting); 00161 virtual QString format(const LoggingEvent &rEvent); 00162 00163 protected: 00164 #ifndef QT_NO_DEBUG_STREAM 00165 00176 virtual QDebug debug(QDebug &rDebug) const; 00177 #endif // QT_NO_DEBUG_STREAM 00178 00179 private: 00180 void updatePatternFormatter(); 00181 00182 private: 00183 bool mCategoryPrefixing; 00184 bool mContextPrinting; 00185 QString mDateFormat; 00186 bool mThreadPrinting; 00187 PatternFormatter *mpPatternFormatter; 00188 }; 00189 00190 00191 /************************************************************************** 00192 * Operators, Helper 00193 **************************************************************************/ 00194 00195 00196 /************************************************************************** 00197 * Inline 00198 **************************************************************************/ 00199 00200 inline bool TTCCLayout::categoryPrefixing() const 00201 { return mCategoryPrefixing; } 00202 00203 inline bool TTCCLayout::contextPrinting() const 00204 { return mContextPrinting; } 00205 00206 inline QString TTCCLayout::dateFormat() const 00207 { return mDateFormat; } 00208 00209 inline bool TTCCLayout::threadPrinting() const 00210 { return mThreadPrinting; } 00211 00212 inline void TTCCLayout::setCategoryPrefixing(bool categoryPrefixing) 00213 { mCategoryPrefixing = categoryPrefixing; 00214 updatePatternFormatter(); } 00215 00216 inline void TTCCLayout::setContextPrinting(bool contextPrinting) 00217 { mContextPrinting = contextPrinting; 00218 updatePatternFormatter(); } 00219 00220 inline void TTCCLayout::setDateFormat(const QString &rDateFormat) 00221 { mDateFormat = rDateFormat; 00222 updatePatternFormatter(); } 00223 00224 inline void TTCCLayout::setThreadPrinting(bool threadPrinting) 00225 { mThreadPrinting = threadPrinting; 00226 updatePatternFormatter(); } 00227 00228 00229 } // namespace Log4Qt 00230 00231 00232 // Q_DECLARE_TYPEINFO(Log4Qt::TTCCLayout, Q_COMPLEX_TYPE); // Use default 00233 00234 00235 #endif // LOG4QT_TTCCLAYOUT_H