libyui
|
00001 /************************************************************************** 00002 Copyright (C) 2000 - 2010 Novell, Inc. 00003 All Rights Reserved. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License along 00016 with this program; if not, write to the Free Software Foundation, Inc., 00017 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00018 00019 **************************************************************************/ 00020 00021 00022 /*---------------------------------------------------------------------\ 00023 | | 00024 | __ __ ____ _____ ____ | 00025 | \ \ / /_ _/ ___|_ _|___ \ | 00026 | \ V / _` \___ \ | | __) | | 00027 | | | (_| |___) || | / __/ | 00028 | |_|\__,_|____/ |_| |_____| | 00029 | | 00030 | core system | 00031 | (C) SuSE GmbH | 00032 \----------------------------------------------------------------------/ 00033 00034 File: YUILog.h 00035 00036 Author: Stefan Hundhammer <sh@suse.de> 00037 00038 /-*/ 00039 00040 #ifndef YUILog_h 00041 00042 #ifndef YUILogComponent 00043 #error Missing #define YUILogComponent "myComponent" before #include "YUILog.h" 00044 #endif 00045 00046 #include <iostream> 00047 #include <string> 00048 00049 #include "ImplPtr.h" 00050 00051 00052 // 00053 // UI Logging: Macros for Application use. 00054 // 00055 // They all return a std::ostream & for use with operator<<(). 00056 // #define YUILogComponent before including this header file 00057 // to identify what subsystem ("my-ui" etc.) this log line belongs to. 00058 // 00059 // #define YUILogComponent "myComponent" 00060 // #include <YUILog.h> 00061 // 00062 // ... 00063 // yuiDebug() << "Creating widget" << widget << endl; 00064 // yuiError() << "No widget with ID " << id << endl; 00065 // 00066 // Unless the underlying logger function handles this differently, 00067 // Milestone, Warning and Error are always logged, Debug only when enabled. 00068 // 00069 00070 #define yuiDebug() YUILog::debug ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ ) 00071 #define yuiMilestone() YUILog::milestone( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ ) 00072 #define yuiWarning() YUILog::warning ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ ) 00073 #define yuiError() YUILog::error ( YUILogComponent, __FILE__, __LINE__, __FUNCTION__ ) 00074 00075 using std::endl; 00076 using std::hex; 00077 using std::dec; 00078 using std::boolalpha; 00079 using std::noboolalpha; 00080 using std::string; 00081 00082 // 00083 // ------ End of user relevant part ------ 00084 // 00085 00086 00087 00088 class YUILogPrivate; 00089 00090 enum YUILogLevel_t 00091 { 00092 YUI_LOG_DEBUG = 0, 00093 YUI_LOG_MILESTONE, 00094 YUI_LOG_WARNING, 00095 YUI_LOG_ERROR 00096 }; 00097 00098 00104 typedef void (*YUILoggerFunction)( YUILogLevel_t, // logLevel 00105 const char *, // logComponent 00106 const char *, // sourceFileName 00107 int, // sourceLineNo 00108 const char *, // sourceFunctionName 00109 const char * ); // message 00110 00111 typedef void (*YUIEnableDebugLoggingFunction)( bool ); 00112 typedef bool (*YUIDebugLoggingEnabledFunction)(); 00113 00114 00118 class YUILog 00119 { 00120 public: 00121 00126 static std::ostream & debug ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName ); 00127 static std::ostream & milestone( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName ); 00128 static std::ostream & warning ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName ); 00129 static std::ostream & error ( const char * logComponent, const char * sourceFileName, int lineNo, const char * functionName ); 00130 00134 std::ostream & log( YUILogLevel_t logLevel, 00135 const char * logComponent, 00136 const char * sourceFileName, 00137 int lineNo, 00138 const char * functionName ); 00139 00144 static YUILog * instance(); 00145 00149 static void enableDebugLogging( bool debugLogging = true ); 00150 00154 static bool debugLoggingEnabled(); 00155 00178 static bool setLogFileName( const string & logFileName ); 00179 00185 static string logFileName(); 00186 00195 static void setLoggerFunction( YUILoggerFunction loggerFunction ); 00196 00204 static YUILoggerFunction loggerFunction( bool returnStdLogger = false ); 00205 00216 static void setEnableDebugLoggingHooks( YUIEnableDebugLoggingFunction enableFunction, 00217 YUIDebugLoggingEnabledFunction isEnabledFunction ); 00218 00223 static YUIEnableDebugLoggingFunction enableDebugLoggingHook(); 00224 00229 static YUIDebugLoggingEnabledFunction debugLoggingEnabledHook(); 00230 00234 static string basename( const string & fileNameWithPath ); 00235 00236 00237 private: 00244 YUILog(); 00245 00249 ~YUILog(); 00250 00251 // 00252 // Data 00253 // 00254 00255 ImplPtr<YUILogPrivate> priv; 00256 }; 00257 00258 00259 #define YUILog_h 00260 00261 #endif // YUILog_h