|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2012 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 #ifndef KATANA_PLUGINAPI_FNLOGGING_FNLOGGING_H_ 00003 #define KATANA_PLUGINAPI_FNLOGGING_FNLOGGING_H_ 00004 #include <sstream> 00005 #include <string> 00006 #include <vector> 00007 00008 #include "FnPlatform/internal/Portability.h" 00009 #include "FnPluginSystem/FnPluginSystem.h" 00010 00011 #include "FnLogging/FnLoggingAPI.h" 00012 #include "FnLogging/ns.h" 00013 #include "FnLogging/suite/FnLoggingSuite.h" 00014 00015 FNLOGGING_NAMESPACE_ENTER 00016 { 00017 namespace FnLogging 00018 { 00019 FNLOGGING_API 00020 FnPlugStatus setHost(FnPluginHost* host); 00021 } // namespace FnLogging 00022 00023 class FNLOGGING_API FnLog 00024 { 00025 public: 00026 explicit FnLog(const std::string& module = ""); 00027 ~FnLog(); 00028 00029 void log(const std::string& message, FnLoggingSeverity severity) const; 00030 00031 void debug(const std::string& message) const 00032 { 00033 log(message, kFnLoggingSeverityDebug); 00034 } 00035 00036 void info(const std::string& message) const 00037 { 00038 log(message, kFnLoggingSeverityInfo); 00039 } 00040 00041 void warning(const std::string& message) const 00042 { 00043 log(message, kFnLoggingSeverityWarning); 00044 } 00045 00046 void error(const std::string& message) const 00047 { 00048 log(message, kFnLoggingSeverityError); 00049 } 00050 00051 void critical(const std::string& message) const 00052 { 00053 log(message, kFnLoggingSeverityCritical); 00054 } 00055 00056 bool isSeverityEnabled(FnLoggingSeverity severity) const; 00057 00058 static FnPlugStatus setHost(FnPluginHost* host); 00059 static void setSuite(FnLoggingHostSuite_v1* suite); 00060 static const FnLoggingHostSuite_v1* getSuite(); 00061 00062 private: 00063 // no copy/assign 00064 FnLog(const FnLog& rhs); 00065 FnLog& operator=(const FnLog& rhs); 00066 00067 std::string _module; 00068 00069 static const FnLoggingHostSuite_v1* _loggingSuite; 00070 }; 00071 namespace FnLogging 00072 { 00073 using FNLOGGING_NAMESPACE::FnLog; // compatibility alias 00074 } // namespace FnLogging 00075 } 00076 FNLOGGING_NAMESPACE_EXIT 00077 00078 // Some definitions used to set up logging in a plugin source file and 00079 // to compose log messages 00080 00081 #if defined(__clang__) 00082 #define FnLogSetup(name) \ 00083 _Pragma("clang diagnostic push"); \ 00084 _Pragma("clang diagnostic ignored \"-Wexit-time-destructors\""); \ 00085 static ::FnLogging::FnLog _fnLog(name); \ 00086 _Pragma("clang diagnostic pop"); 00087 #else 00088 #define FnLogSetup(name) static ::FnLogging::FnLog _fnLog(name); 00089 #endif // __clang__ 00090 00091 // The following macros build up string buffers automagically behind 00092 // the scenes, reducing the amount of effort required to use logging 00093 // first, a generalised internal version 00094 #define FnLogInternal(logEvent, severity) \ 00095 do \ 00096 { \ 00097 std::ostringstream _log_buf; \ 00098 _log_buf << logEvent; \ 00099 _fnLog.log(_log_buf.str(), severity); \ 00100 } while (0); 00101 00102 // and now, wrappers for all the levels 00103 00104 #define FnLogDebug(logEvent) FnLogInternal(logEvent, kFnLoggingSeverityDebug) 00105 #define FnLogInfo(logEvent) FnLogInternal(logEvent, kFnLoggingSeverityInfo) 00106 #define FnLogWarn(logEvent) FnLogInternal(logEvent, kFnLoggingSeverityWarning) 00107 #define FnLogError(logEvent) FnLogInternal(logEvent, kFnLoggingSeverityError) 00108 #define FnLogCritical(logEvent) \ 00109 FnLogInternal(logEvent, kFnLoggingSeverityCritical) 00110 00112 00113 FNLOGGING_NAMESPACE_ENTER 00114 { 00115 struct FnLogQueueEntry 00116 { 00117 std::string message; 00118 unsigned int severity; 00119 std::string module; 00120 }; 00121 00122 // This class is a historical curiosity that has never been implemented. 00123 class FNLOGGING_API FnLogQueue 00124 { 00125 public: 00126 FNKAT_DEPRECATED explicit FnLogQueue(unsigned int severityFilter, 00127 const char* moduleFilter = 0x0); 00128 FNKAT_DEPRECATED FnLogQueue(); 00129 00130 FNKAT_DEPRECATED ~FnLogQueue(); 00131 00132 FNKAT_DEPRECATED void clear(); 00133 00134 FNKAT_DEPRECATED const std::vector<FnLogQueueEntry>& getEntries() const 00135 { 00136 return _entries; 00137 } 00138 00139 FNKAT_DEPRECATED std::string getEntriesAsString() const; 00140 00141 FNKAT_DEPRECATED static void handler(const char* message, 00142 unsigned int severity, 00143 const char* module, 00144 void* userData); 00145 00146 FNKAT_DEPRECATED static FnPlugStatus setHost(FnPluginHost* host); 00147 FNKAT_DEPRECATED static void setSuite(FnLoggingHostSuite_v1* suite); 00148 00149 private: 00150 // no copy/assign 00151 FnLogQueue(const FnLogQueue& rhs); 00152 FnLogQueue& operator=(const FnLogQueue& rhs); 00153 00154 void init(unsigned int severityFilter, const char* moduleFilter); 00155 00156 void _appendEntry(const char* message, 00157 unsigned int severity, 00158 const char* module); 00159 00160 std::vector<FnLogQueueEntry> _entries; 00161 00162 static const FnLoggingHostSuite_v1* _loggingSuite; 00163 }; 00164 00165 #if defined(FNGEOLIB_INTERNAL_NAMESPACE) 00166 using FNLOGGING_NAMESPACE::FnLogging::setHost; 00167 #else 00168 namespace FnLogging 00169 { 00170 using FNLOGGING_NAMESPACE::FnLogQueueEntry; // compatibility alias 00171 using FNLOGGING_NAMESPACE::FnLogQueue; // compatibility alias 00172 } // namespace FnLogging 00173 #endif // defined(FNGEOLIB_INTERNAL_NAMESPACE) 00174 } 00175 FNLOGGING_NAMESPACE_EXIT 00176 00177 #endif // KATANA_PLUGINAPI_FNLOGGING_FNLOGGING_H_
1.7.3