00001 /* 00002 * 00003 * Copyright (C) 2009-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: oflog 00015 * 00016 * Author: Uli Schlachter 00017 * 00018 * Purpose: Simplify the usage of log4cplus to other modules (Header) 00019 * 00020 * Last Update: $Author: joergr $ 00021 * Update Date: $Date: 2010-10-14 13:20:52 $ 00022 * CVS/RCS Revision: $Revision: 1.12 $ 00023 * Status: $State: Exp $ 00024 * 00025 * CVS/RCS Log at end of file 00026 * 00027 */ 00028 00029 00030 #ifndef OFLOG_H 00031 #define OFLOG_H 00032 00033 #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */ 00034 00035 #include "dcmtk/oflog/logger.h" 00036 #include "dcmtk/ofstd/oftypes.h" 00037 #include "dcmtk/ofstd/ofconapp.h" 00038 00039 #define OFLOG_TRACE(logger, msg) LOG4CPLUS_TRACE(logger, msg) 00040 #define OFLOG_DEBUG(logger, msg) LOG4CPLUS_DEBUG(logger, msg) 00041 #define OFLOG_INFO(logger, msg) LOG4CPLUS_INFO(logger, msg) 00042 #define OFLOG_WARN(logger, msg) LOG4CPLUS_WARN(logger, msg) 00043 #define OFLOG_ERROR(logger, msg) LOG4CPLUS_ERROR(logger, msg) 00044 #define OFLOG_FATAL(logger, msg) LOG4CPLUS_FATAL(logger, msg) 00045 00049 class OFLogger : private log4cplus::Logger 00050 { 00051 public: 00055 OFLogger(const log4cplus::Logger &base); 00056 00058 enum LogLevel { 00060 TRACE_LOG_LEVEL = log4cplus::TRACE_LOG_LEVEL, 00062 DEBUG_LOG_LEVEL = log4cplus::DEBUG_LOG_LEVEL, 00064 INFO_LOG_LEVEL = log4cplus::INFO_LOG_LEVEL, 00066 WARN_LOG_LEVEL = log4cplus::WARN_LOG_LEVEL, 00068 ERROR_LOG_LEVEL = log4cplus::ERROR_LOG_LEVEL, 00070 FATAL_LOG_LEVEL = log4cplus::FATAL_LOG_LEVEL 00071 }; 00072 00082 bool isEnabledFor(log4cplus::LogLevel ll) const { 00083 return Logger::isEnabledFor(ll); 00084 } 00085 00087 void forcedLog(log4cplus::LogLevel ll, const log4cplus::tstring& message, 00088 const char* file=NULL, int line=-1, const char* function=NULL) const { 00089 Logger::forcedLog(ll, message, file, line, function); 00090 } 00091 00098 LogLevel getChainedLogLevel() const { 00099 return OFstatic_cast(LogLevel, Logger::getChainedLogLevel()); 00100 } 00101 }; 00102 00105 class OFLog 00106 { 00107 private: 00108 00111 OFLog() { } 00112 00116 static void configureLogger(log4cplus::LogLevel level); 00117 00118 public: 00119 00123 static OFLogger getLogger(const char *name); 00124 00128 static void configure(OFLogger::LogLevel level = OFLogger::WARN_LOG_LEVEL); 00129 00134 static void configureFromCommandLine(OFCommandLine &cmd, OFConsoleApplication &app); 00135 00139 static void addOptions(OFCommandLine &cmd); 00140 00146 static void reconfigure(OFCommandLine *cmd = NULL); 00147 00148 private: 00149 00151 static OFauto_ptr<log4cplus::helpers::Properties> configProperties_; 00152 }; 00153 00154 #endif 00155 00156 00157 /* 00158 * 00159 * CVS/RCS Log: 00160 * $Log: oflog.h,v $ 00161 * Revision 1.12 2010-10-14 13:20:52 joergr 00162 * Updated copyright header. Added reference to COPYRIGHT file. 00163 * 00164 * Revision 1.11 2010-08-05 08:38:11 uli 00165 * Fixed some warnings from -Wold-style-cast. 00166 * 00167 * Revision 1.10 2010-05-14 12:29:55 uli 00168 * Added new function OFLog::reconfigure() which reinterprets the logger config 00169 * file. This can e.g. be useful for logging to a different file after fork(). 00170 * 00171 * Revision 1.9 2010-04-26 12:22:30 uli 00172 * Fixed a some minor doxygen warnings. 00173 * 00174 * Revision 1.8 2010-04-23 11:04:46 uli 00175 * Updated oflog to log4cplus revision 1200 from PRODUCTION_1_0_x branch. 00176 * 00177 * Revision 1.7 2010-03-08 10:50:40 uli 00178 * Don't use "using" to fix compilation with MSVC6. 00179 * 00180 * Revision 1.6 2009-11-17 14:26:21 uli 00181 * Make OFLogger::getChainedLogLevel() accessible. 00182 * 00183 * Revision 1.5 2009-11-06 09:41:22 joergr 00184 * Changed documentation on log level "trace". 00185 * 00186 * Revision 1.4 2009-09-16 10:04:26 joergr 00187 * Changed OFLogger's copy constructor: use "const &" for the parameter. 00188 * Added missing documentation on parameters. 00189 * 00190 * Revision 1.3 2009-09-14 10:51:05 joergr 00191 * Removed (now) unused helper function toLogMode(). 00192 * 00193 * Revision 1.2 2009-08-20 12:08:02 joergr 00194 * Added documentation on log level values. 00195 * 00196 * Revision 1.1 2009-08-19 11:54:00 joergr 00197 * Added new module "oflog" which is based on log4cplus. 00198 * 00199 * 00200 */