Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00024
00025 #ifndef ICL_CORE_LOGGING_LOGGING_H_INCLUDED
00026 #define ICL_CORE_LOGGING_LOGGING_H_INCLUDED
00027
00028 #include <assert.h>
00029 #include <boost/shared_ptr.hpp>
00030
00031 #include <icl_core/TimeSpan.h>
00032 #include <icl_core/TimeStamp.h>
00033 #include "icl_core_logging/Constants.h"
00034 #include "icl_core_logging/ImportExport.h"
00035 #include "icl_core_logging/LoggingManager.h"
00036 #include "icl_core_logging/LogStream.h"
00037 #include "icl_core_logging/ThreadStream.h"
00038 #include "icl_core_config/GetoptParser.h"
00039
00040
00041 #include "icl_core_logging/tLoggingManager.h"
00042 #include "icl_core_logging/tLogLevel.h"
00043
00044
00045 #include "icl_core_logging/LoggingMacros_LOGGING.h"
00046 #include "icl_core_logging/LoggingMacros_LOGGING_FMT.h"
00047 #include "icl_core_logging/LoggingMacros_LLOGGING.h"
00048 #include "icl_core_logging/LoggingMacros_LLOGGING_FMT.h"
00049 #include "icl_core_logging/LoggingMacros_MLOGGING.h"
00050 #include "icl_core_logging/LoggingMacros_MLOGGING_FMT.h"
00051 #include "icl_core_logging/LoggingMacros_SLOGGING.h"
00052 #include "icl_core_logging/LoggingMacros_SLOGGING_FMT.h"
00053
00054 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00055 # include "icl_core/Deprecate.h"
00056 #endif
00057
00058 #define LOG_THREAD_STREAM(name) name::instance().ThreadStream()
00059
00060 #ifndef _IC_BUILDER_DEPRECATED_STYLE_
00061 # define DECLARE_LOG_STREAM_CLASS_DEFINITION(name) \
00062 name : public ::icl_core::logging::LogStream \
00063 { \
00064 public: \
00065 static ::icl_core::logging::LogStream& instance(); \
00066 static ::icl_core::logging::LogStream *create(); \
00067 private: \
00068 name() \
00069 : LogStream(#name) \
00070 { } \
00071 ~name() { } \
00072 static name *m_instance; \
00073 friend class ::icl_core::logging::LoggingManager; \
00074 friend class ::icl_core::logging::hidden::LogStreamRegistrar; \
00075 };
00076 #else
00077
00078 # define DECLARE_LOG_STREAM_CLASS_DEFINITION(name) \
00079 name : public ::icl_core::logging::LogStream \
00080 { \
00081 public: \
00082 static ::icl_core::logging::LogStream& instance(); \
00083 static ::icl_core::logging::LogStream *create(); \
00084 static ICL_CORE_VC_DEPRECATE_STYLE ::icl_core::logging::LogStream& Instance() ICL_CORE_GCC_DEPRECATE_STYLE; \
00085 static ICL_CORE_VC_DEPRECATE_STYLE ::icl_core::logging::LogStream *Create() ICL_CORE_GCC_DEPRECATE_STYLE; \
00086 private: \
00087 name() \
00088 : LogStream(#name) \
00089 { } \
00090 ~name() { } \
00091 static name *m_instance; \
00092 friend class ::icl_core::logging::LoggingManager; \
00093 friend class ::icl_core::logging::hidden::LogStreamRegistrar; \
00094 }; \
00095 inline ::icl_core::logging::LogStream& name::Instance() \
00096 { return instance(); } \
00097 inline ::icl_core::logging::LogStream *name::Create() \
00098 { return create(); }
00099 #endif
00100
00101 #define DECLARE_LOG_STREAM(name) class DECLARE_LOG_STREAM_CLASS_DEFINITION(name)
00102 #define DECLARE_LOG_STREAM_IMPORT_EXPORT(name, decl) class decl DECLARE_LOG_STREAM_CLASS_DEFINITION(name)
00103
00104
00105
00106 #define REGISTER_LOG_STREAM(name) \
00107 name * name::m_instance = NULL; \
00108 ::icl_core::logging::LogStream& name::instance() \
00109 { \
00110 if (m_instance == NULL) \
00111 { \
00112 std::cout << "WARNING: Logging Instance is null, did you initialize the logging framework?\nYou should initialize the logging framework at the beginning of your program. This will also enable setting the log level on the command line." << std::endl; \
00113 ::icl_core::logging::LoggingManager::instance().initialize(); \
00114 assert(m_instance != NULL && "Tried to initialize LoggingManager but m_instance still not available."); \
00115 return *m_instance; \
00116 } \
00117 else \
00118 { \
00119 return *m_instance; \
00120 } \
00121 } \
00122 ::icl_core::logging::LogStream * name::create() \
00123 { \
00124 if (m_instance == NULL) \
00125 { \
00126 m_instance = new name; \
00127 } \
00128 return m_instance; \
00129 } \
00130 ::icl_core::logging::hidden::LogStreamRegistrar registrar##name(#name, &name::create);
00131
00132 #define REGISTER_LOG_OUTPUT_STREAM(name, factory) \
00133 ::icl_core::logging::hidden::LogOutputStreamRegistrar registrar##name(#name, factory);
00134
00135 #define DECLARE_LOG_STREAM_OPERATOR(object_type) \
00136 ::icl_core::logging::ThreadStream & operator << (::icl_core::logging::ThreadStream &str, \
00137 const object_type &object);
00138
00139 #ifdef _SYSTEM_LXRT_
00140 #define REGISTER_LOG_STREAM_OPERATOR(object_type) \
00141 ::icl_core::logging::ThreadStream & operator << (::icl_core::logging::ThreadStream &str, \
00142 const object_type &object) \
00143 { \
00144 str << "std::ostream redirection is not available in LXRT"; \
00145 return str; \
00146 }
00147 #else // _SYSTEM_LXRT_
00148 #define REGISTER_LOG_STREAM_OPERATOR(object_type) \
00149 ::icl_core::logging::ThreadStream & operator << (::icl_core::logging::ThreadStream &str, \
00150 const object_type &object) \
00151 { \
00152 std::ostringstream stream; \
00153 stream << object; \
00154 str << stream.str(); \
00155 return str; \
00156 }
00157 #endif // _SYSTEM_LXRT_
00158
00159 namespace icl_core {
00161 namespace logging {
00162
00163 ICL_CORE_LOGGING_IMPORT_EXPORT
00164 ThreadStream& operator << (ThreadStream& stream, const icl_core::TimeStamp& time_stamp);
00165
00166 ICL_CORE_LOGGING_IMPORT_EXPORT
00167 ThreadStream& operator << (ThreadStream& stream, const icl_core::TimeSpan& time_span);
00168
00169 DECLARE_LOG_STREAM_IMPORT_EXPORT(Default, ICL_CORE_LOGGING_IMPORT_EXPORT)
00170 DECLARE_LOG_STREAM_IMPORT_EXPORT(Nirwana, ICL_CORE_LOGGING_IMPORT_EXPORT)
00171 DECLARE_LOG_STREAM_IMPORT_EXPORT(QuickDebug, ICL_CORE_LOGGING_IMPORT_EXPORT)
00172
00173
00177 bool ICL_CORE_LOGGING_IMPORT_EXPORT initialize(int& argc, char *argv[], bool remove_read_arguments);
00178
00183 bool ICL_CORE_LOGGING_IMPORT_EXPORT
00184 initialize(int& argc, char *argv[],
00185 icl_core::config::Getopt::CommandLineCleaning cleanup
00186 = icl_core::config::Getopt::eCLC_None,
00187 icl_core::config::Getopt::ParameterRegistrationCheck registration_check
00188 = icl_core::config::Getopt::ePRC_Strict);
00189
00195 void ICL_CORE_LOGGING_IMPORT_EXPORT initialize();
00196
00199 void ICL_CORE_LOGGING_IMPORT_EXPORT shutdown();
00200
00201 boost::shared_ptr<LifeCycle> ICL_CORE_LOGGING_IMPORT_EXPORT autoStart(int &argc, char *argv[]);
00202
00204 void ICL_CORE_LOGGING_IMPORT_EXPORT setLogLevel(icl_core::logging::LogLevel log_level);
00205
00206
00208 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00209
00213 bool ICL_CORE_LOGGING_IMPORT_EXPORT ICL_CORE_VC_DEPRECATE_STYLE
00214 Initialize(int& argc, char *argv[], bool remove_read_arguments)
00215 ICL_CORE_GCC_DEPRECATE_STYLE;
00216
00220 bool ICL_CORE_LOGGING_IMPORT_EXPORT ICL_CORE_VC_DEPRECATE_STYLE
00221 Initialize(int& argc, char *argv[],
00222 icl_core::config::Getopt::CommandLineCleaning cleanup
00223 = icl_core::config::Getopt::eCLC_None,
00224 icl_core::config::Getopt::ParameterRegistrationCheck registration_check
00225 = icl_core::config::Getopt::ePRC_Strict)
00226 ICL_CORE_GCC_DEPRECATE_STYLE;
00227
00231 void ICL_CORE_LOGGING_IMPORT_EXPORT ICL_CORE_VC_DEPRECATE_STYLE Initialize()
00232 ICL_CORE_GCC_DEPRECATE_STYLE;
00233
00237 void ICL_CORE_LOGGING_IMPORT_EXPORT ICL_CORE_VC_DEPRECATE_STYLE Shutdown()
00238 ICL_CORE_GCC_DEPRECATE_STYLE;
00239
00240 #endif
00241
00242
00243 }
00244 }
00245
00246 #endif