00001 /* 00002 * 00003 * Copyright (C) 2000-2005, OFFIS 00004 * 00005 * This software and supporting documentation were developed by 00006 * 00007 * Kuratorium OFFIS e.V. 00008 * Healthcare Information and Communication Systems 00009 * Escherweg 2 00010 * D-26121 Oldenburg, Germany 00011 * 00012 * THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND OFFIS MAKES NO WARRANTY 00013 * REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY OR 00014 * FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES OR 00015 * ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND 00016 * PERFORMANCE OF THE SOFTWARE IS WITH THE USER. 00017 * 00018 * Module: ofstd 00019 * 00020 * Author: Joerg Riesmeier 00021 * 00022 * Purpose: Define general purpose facility for log file output 00023 * 00024 * Last Update: $Author: meichel $ 00025 * Update Date: $Date: 2005/12/08 16:05:59 $ 00026 * CVS/RCS Revision: $Revision: 1.13 $ 00027 * Status: $State: Exp $ 00028 * 00029 * CVS/RCS Log at end of file 00030 * 00031 */ 00032 00033 00034 #ifndef OFLOGFIL_H 00035 #define OFLOGFIL_H 00036 00037 #include "dcmtk/config/osconfig.h" 00038 #include "dcmtk/ofstd/ofthread.h" 00039 #include "dcmtk/ofstd/ofstream.h" 00040 00041 #define INCLUDE_CSTDLIB 00042 #include "dcmtk/ofstd/ofstdinc.h" 00043 00044 00049 class OFLogFile 00050 { 00051 public: 00052 00055 enum LF_Level 00056 { 00058 LL_none = 0, 00060 LL_error = 1, 00062 LL_warning = 2, 00064 LL_informational = 3, 00066 LL_debug = 4 00067 }; 00068 00074 OFLogFile(const char *filename, int flags = ios::app); 00075 00078 virtual ~OFLogFile() {} 00079 00088 ofstream &lockFile(LF_Level level = LL_none, const char *module = NULL); 00089 00092 void unlockFile() 00093 { 00094 File.flush(); 00095 #ifdef _REENTRANT 00096 Mutex.unlock(); 00097 #endif 00098 } 00099 00103 OFBool good() 00104 { 00105 #ifdef _REENTRANT 00106 Mutex.lock(); 00107 #endif 00108 OFBool status = File.good() ? OFTrue : OFFalse; 00109 #ifdef _REENTRANT 00110 Mutex.unlock(); 00111 #endif 00112 return status; 00113 } 00114 00120 ostream& getFile() 00121 { 00122 return File; 00123 } 00124 00132 void writeMessage(const char *message, int indent = 3); 00133 00142 void setFilter(LF_Level level) 00143 { 00144 #ifdef _REENTRANT 00145 Mutex.lock(); 00146 #endif 00147 Filter = level; 00148 #ifdef _REENTRANT 00149 Mutex.unlock(); 00150 #endif 00151 } 00152 00156 LF_Level getFilter() 00157 { 00158 return Filter; 00159 } 00160 00165 OFBool checkFilter(LF_Level level) 00166 { 00167 return (level != LL_none) && (level <= Filter); 00168 } 00169 00170 00171 private: 00172 00174 OFLogFile(const OFLogFile &arg); 00175 00177 OFLogFile& operator=(const OFLogFile &arg); 00178 00180 ofstream File; 00181 00183 LF_Level Filter; 00184 00185 #ifdef _REENTRANT 00186 00187 OFMutex Mutex; 00188 #endif 00189 }; 00190 00191 00192 #endif 00193 00194 00195 /* 00196 * 00197 * CVS/RCS Log: 00198 * $Log: oflogfil.h,v $ 00199 * Revision 1.13 2005/12/08 16:05:59 meichel 00200 * Changed include path schema for all DCMTK header files 00201 * 00202 * Revision 1.12 2004/01/16 10:30:12 joergr 00203 * Removed acknowledgements with e-mail addresses from CVS log. 00204 * 00205 * Revision 1.11 2003/12/05 10:37:41 joergr 00206 * Removed leading underscore characters from preprocessor symbols (reserved 00207 * symbols). Updated copyright date where appropriate. 00208 * 00209 * Revision 1.10 2003/06/12 13:14:29 joergr 00210 * Fixed inconsistent API documentation reported by Doxygen. 00211 * 00212 * Revision 1.9 2003/06/11 13:26:09 meichel 00213 * Cleaned up usage of boolean constants 00214 * 00215 * Revision 1.8 2002/11/27 11:23:05 meichel 00216 * Adapted module ofstd to use of new header file ofstdinc.h 00217 * 00218 * Revision 1.7 2002/05/16 15:56:18 meichel 00219 * Minor fixes to make ofstd compile on NeXTStep 3.3 00220 * 00221 * Revision 1.6 2002/05/14 08:12:29 joergr 00222 * Updated comments. 00223 * 00224 * Revision 1.5 2002/04/16 13:36:03 joergr 00225 * Added configurable support for C++ ANSI standard includes (e.g. streams). 00226 * 00227 * Revision 1.4 2001/06/01 15:51:34 meichel 00228 * Updated copyright header 00229 * 00230 * Revision 1.3 2000/12/12 17:19:57 joergr 00231 * Changed type of stream 'open_mode' from long to int to avoid compiler 00232 * warnings reported by SunCC 2.0.1. 00233 * 00234 * Revision 1.2 2000/06/21 15:47:54 meichel 00235 * Including stdlib.h, required for Sun CC 4.2 00236 * 00237 * Revision 1.1 2000/06/05 16:16:23 joergr 00238 * Added new class for writing standardized status messages to a log file. 00239 * 00240 * 00241 */