it_bus/bus_logger.h

00001 #ifndef _IT_BUS_BUS_LOGGER_H_
00002 #define _IT_BUS_BUS_LOGGER_H_
00003 
00004 // prevent logging_support.h being included !!!!
00005 #if defined(_IT_BUS_LOGGING_SUPPORT_H_) || defined(_IT_BUS_OLD_LOGGING_HELPER_H_)
00006 #error bus_logger.h should not be included with logging_support.h or old_logging_helper.h
00007 #endif
00008 
00009 // @Copyright 2005 IONA Technologies, Plc. All Rights Reserved.
00010 //
00011 #include <it_bus_pdk/pdk_bus.h>
00012 #include <it_bus/logging_defs.h>
00013 
00014 namespace IT_Logging
00015 {
00016     class EventLog;
00017 }
00018 
00019 namespace IT_Bus
00020 {
00021     namespace Logging
00022     {
00023         class ServiceNameRetriever;
00024         class LoggingConfig;
00025 
00026         class IT_BUS_API BusLogger
00027         {
00028           protected:
00029             BusLogger();
00030 
00031           public:
00032             virtual ~BusLogger();
00033 
00034             virtual void
00035             write_log_record(
00036                 IT_Bus::Logging::ServiceNameRetriever* snr,
00037                 IT_TraceLevel trace_level,
00038                 const char* description,
00039                 ...) = 0;
00040 
00041             virtual void
00042             write_log_record_with_CDATA(
00043                 IT_Bus::Logging::ServiceNameRetriever* snr,
00044                 IT_TraceLevel trace_level,
00045                 const char* description,
00046                 const char* data_buffer,
00047                 long buffer_size
00048             ) = 0;
00049 
00050             virtual void
00051             write_log_record_with_binary(
00052                 IT_Bus::Logging::ServiceNameRetriever* snr,
00053                 IT_TraceLevel trace_level,
00054                 const char* description,
00055                 const char* data_buffer,
00056                 long buffer_size
00057             ) = 0;
00058 
00059             virtual const char*
00060             get_subsystem() = 0;
00061 
00062             inline IT_Bool
00063             is_loggable(
00064                 IT_TraceLevel level
00065             )
00066             {
00067                 return ((m_bus_master_log_filter & level) != 0);
00068             }
00069 
00070             inline IT_Bool
00071             is_loggable_subsystem(
00072                 IT_TraceLevel level
00073             )
00074             {
00075                 return ((m_subsystem_log_filter & level) != 0);
00076             }
00077 
00078             inline IT_TraceLevel
00079             get_subsystem_log_filter()
00080             {
00081                 return m_subsystem_log_filter;
00082             }
00083 
00084             inline IT_TraceLevel
00085             get_bus_master_log_filter()
00086             {
00087                 return m_bus_master_log_filter;
00088             }
00089 
00090           protected:
00091             IT_TraceLevel m_bus_master_log_filter;
00092             IT_TraceLevel m_subsystem_log_filter;
00093 
00094           private:
00095             BusLogger& operator=(const BusLogger& rhs);
00096             BusLogger(const BusLogger& rhs);
00097         };
00098     }
00099 }
00100 
00101 #define IT_LOG_BUFFER(bus_logger, Entry, Length) \
00102     if (bus_logger->is_loggable(IT_TRACE_BUFFER)) \
00103     { \
00104         bus_logger->write_log_record_with_binary(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, "Buffer Output", Entry, Length); \
00105     } 
00106 
00107 #define IT_LOG_CDATA(bus_logger, description, Entry) \
00108     if (bus_logger->is_loggable(IT_TRACE_BUFFER) \
00109     { \
00110         bus_logger->write_log_record_with_CDATA(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, description, Entry, 0); \
00111     }
00112 
00113 #define IT_LOG_CDATA_SIZE(bus_logger, description, Entry, Size) \
00114     if (bus_logger->is_loggable(IT_TRACE_BUFFER) \
00115     { \
00116         bus_logger->write_log_record_with_CDATA(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, description, Entry, Size); \
00117     }
00118 
00119 #define IT_LOG_CDATA_BINARY_BUFFER(bus_logger, description, bbData) \
00120     if (bus_logger->is_loggable(IT_TRACE_BUFFER) \
00121     { \
00122         bus_logger->write_log_record_with_binary(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, description, bbData.get_const_pointer(), bbData.get_size()); \
00123     }
00124 
00125 // these are used for controlled tracing operations.  description is a printf format string
00126 // they allow specifying the trace level so callers can control visibility
00127 #define IT_LOG_GUARDED0(bus_logger, snr, trace_level, description) \
00128     if (bus_logger->is_loggable(trace_level)) \
00129     { \
00130         bus_logger->write_log_record(snr, trace_level, description); \
00131     }
00132 
00133 #define IT_LOG_GUARDED(bus_logger, snr, trace_level, description) \
00134     IT_LOG_GUARDED0(bus_logger, snr, trace_level, description)
00135 
00136 #define IT_LOG_GUARDED1(bus_logger, snr, trace_level, description, Arg1) \
00137     if (bus_logger->is_loggable(trace_level)) \
00138     { \
00139             bus_logger->write_log_record(snr, trace_level, description, Arg1); \
00140     } 
00141 
00142 #define IT_LOG_GUARDED2(bus_logger, snr, trace_level, description, Arg1, Arg2) \
00143     if (bus_logger->is_loggable(trace_level)) \
00144     { \
00145             bus_logger->write_log_record(snr, trace_level, description, Arg1, Arg2); \
00146     } 
00147 
00148 #define IT_LOG_GUARDED3(bus_logger, snr, trace_level, description, Arg1, Arg2, Arg3) \
00149     if (bus_logger->is_loggable(trace_level)) \
00150     { \
00151             bus_logger->write_log_record(snr, trace_level, description, Arg1, Arg2, Arg3); \
00152     } 
00153 
00154 #define IT_LOG_GUARDED4(bus_logger, snr, trace_level, description, Arg1, Arg2, Arg3, Arg4) \
00155     if (bus_logger->is_loggable(trace_level)) \
00156     { \
00157             bus_logger->write_log_record(snr, trace_level, description, Arg1, Arg2, Arg3, Arg4); \
00158     } 
00159 
00160 #define IT_LOG_GUARDED5(bus_logger, snr, trace_level, description, Arg1, Arg2, Arg3, Arg4, Arg5) \
00161     if (bus_logger->is_loggable(trace_level)) \
00162     { \
00163             bus_logger->write_log_record(snr, trace_level, description, Arg1, Arg2, Arg3, Arg4, Arg5); \
00164     } 
00165 
00166 
00167 //these are used to guard a code block from executing when the purpose of the code
00168 //block is solely for formatting a trace statement.  It prevents the code from 
00169 //executing when the trace_level is filtered out and wouldn't be used anyway.
00170 #define BEGIN_TRACE(trace_level)                                        \
00171     if (_IT_BUS_LOGGER->is_loggable(trace_level)) \
00172     {                                                                                                    
00173 
00174 #define BEGIN_SUBSYSTEM_TRACE(trace_level)                                        \
00175     if (_IT_BUS_LOGGER->is_loggable_subsystem(trace_level)) \
00176     {                                                                                                    
00177 
00178 #define END_TRACE                                                                        \
00179     }
00180 
00181 //all the macros that follow are just short hand for the previous ones, but they
00182 //default the bus_logger to "this"
00183 
00184 #define TRACELOGBUFFER(Entry, Length) \
00185     if (_IT_BUS_LOGGER->is_loggable(IT_TRACE_BUFFER)) \
00186     { \
00187         _IT_BUS_LOGGER->write_log_record_with_binary(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, "Buffer Output", Entry, Length); \
00188     } 
00189 
00190 #define TRACELOG_CDATA(description, Entry) \
00191     if (_IT_BUS_LOGGER->is_loggable(IT_TRACE_BUFFER)) \
00192     { \
00193         _IT_BUS_LOGGER->write_log_record_with_CDATA(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, description, Entry, 0); \
00194     }
00195 
00196 #define TRACELOG_CDATA_SIZE(description, Entry, Size) \
00197     if (_IT_BUS_LOGGER->is_loggable(IT_TRACE_BUFFER)) \
00198     { \
00199         _IT_BUS_LOGGER->write_log_record_with_CDATA(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, description, Entry, Size); \
00200     }
00201 
00202 #define SUBSYSTEM_TRACELOG_CDATA_SIZE(priority, description, Entry, Size) \
00203     if (_IT_BUS_LOGGER->is_loggable_subsystem(priority)) \
00204     { \
00205         _IT_BUS_LOGGER->write_log_record_with_CDATA(_IT_SUBSYSTEM_SERVICE, priority, description, Entry, Size); \
00206     }
00207 
00208 
00209 #define SUBSYSTEM_TRACELOG(priority, description) \
00210     if (_IT_BUS_LOGGER->is_loggable_subsystem(priority)) \
00211     { \
00212         _IT_BUS_LOGGER->write_log_record(_IT_SUBSYSTEM_SERVICE, priority, description); \
00213     }
00214 
00215 #define TRACELOG_CDATA_BINARY_BUFFER(description, bbData) \
00216     if (_IT_BUS_LOGGER->is_loggable(IT_TRACE_BUFFER)) \
00217     { \
00218         _IT_BUS_LOGGER->write_log_record_with_binary(_IT_SUBSYSTEM_SERVICE, IT_TRACE_BUFFER, description, bbData.get_const_pointer(), bbData.get_size()); \
00219     }
00220 
00221 //These are used for method level tracing
00222 //to see output from these, include INFO_LOW in your event_log:filters
00223 #define BEGIN_INTERNAL_METHOD(Name) \
00224     const char *FuncName = Name; \
00225     if (_IT_BUS_LOGGER->is_loggable(IT_TRACE_METHODS_INTERNAL)) \
00226         _IT_BUS_LOGGER->write_log_record(_IT_SUBSYSTEM_SERVICE, IT_TRACE_METHODS_INTERNAL, FuncName); 
00227 
00228 #define END_INTERNAL_METHOD    
00229 
00230 #define BEGIN_METHOD(Name) \
00231     const char *FuncName = Name; \
00232     if (_IT_BUS_LOGGER->is_loggable(IT_TRACE_METHODS_INTERNAL)) \
00233         _IT_BUS_LOGGER->write_log_record(_IT_SUBSYSTEM_SERVICE, IT_TRACE_METHODS, FuncName);    
00234 
00235 #define END_METHOD        
00236 
00237 
00238 //these are used for controlled tracing operations.  description is a printf format string
00239 //they allow specifying the trace level so callers can control visibility
00240 #define TRACELOG_WITH_LEVEL0(trace_level, description) \
00241     IT_LOG_GUARDED(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description)
00242 
00243 #define TRACELOG_WITH_LEVEL(trace_level, description) \
00244     IT_LOG_GUARDED(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description)
00245 
00246 #define TRACELOG_WITH_LEVEL1(trace_level, description, Arg1) \
00247     IT_LOG_GUARDED1(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description, Arg1)
00248 
00249 #define TRACELOG_WITH_LEVEL2(trace_level, description, Arg1, Arg2) \
00250     IT_LOG_GUARDED2(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description, Arg1, Arg2)
00251 
00252 #define TRACELOG_WITH_LEVEL3(trace_level, description, Arg1, Arg2, Arg3) \
00253     IT_LOG_GUARDED3(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description, Arg1, Arg2, Arg3)
00254 
00255 #define TRACELOG_WITH_LEVEL4(trace_level, description, Arg1, Arg2, Arg3, Arg4) \
00256     IT_LOG_GUARDED4(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description, Arg1, Arg2, Arg3, Arg4)
00257 
00258 #define TRACELOG_WITH_LEVEL5(trace_level, description, Arg1, Arg2, Arg3, Arg4, Arg5) \
00259     IT_LOG_GUARDED5(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE , trace_level, description, Arg1, Arg2, Arg3, Arg4, Arg5)
00260 
00261 // as above but these are used as above but where service name logging 
00262 // is enabled but not available in the current scope
00263 #define TRACELOG_NSN_WITH_LEVEL0(trace_level, description) \
00264     IT_LOG_GUARDED(_IT_BUS_LOGGER, 0, trace_level, description)
00265 
00266 #define TRACELOG_NSN_WITH_LEVEL(trace_level, description) \
00267     IT_LOG_GUARDED(_IT_BUS_LOGGER, 0, trace_level, description)
00268 
00269 #define TRACELOG_NSN_WITH_LEVEL1(trace_level, description, Arg1) \
00270     IT_LOG_GUARDED1(_IT_BUS_LOGGER, 0, trace_level, description, Arg1)
00271 
00272 #define TRACELOG_NSN_WITH_LEVEL2(trace_level, description, Arg1, Arg2) \
00273     IT_LOG_GUARDED2(_IT_BUS_LOGGER, 0, trace_level, description, Arg1, Arg2)
00274 
00275 #define TRACELOG_NSN_WITH_LEVEL3(trace_level, description, Arg1, Arg2, Arg3) \
00276     IT_LOG_GUARDED3(_IT_BUS_LOGGER, 0, trace_level, description, Arg1, Arg2, Arg3)
00277 
00278 #define TRACELOG_NSN_WITH_LEVEL4(trace_level, description, Arg1, Arg2, Arg3, Arg4) \
00279     IT_LOG_GUARDED4(_IT_BUS_LOGGER, 0, trace_level, description, Arg1, Arg2, Arg3, Arg4)
00280 
00281 #define TRACELOG_NSN_WITH_LEVEL5(trace_level, description, Arg1, Arg2, Arg3, Arg4, Arg5) \
00282     IT_LOG_GUARDED5(_IT_BUS_LOGGER, 0, trace_level, description, Arg1, Arg2, Arg3, Arg4, Arg5)
00283 
00284 //these are used for normal tracing operations.  description is a printf format string
00285 //they default the trace level to IT_TRACE, if you want to use another level see the previous set
00286 #define TRACELOG(description) \
00287     IT_LOG_GUARDED(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description)
00288 
00289 #define TRACELOG0(description) \
00290     IT_LOG_GUARDED(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description)
00291 
00292 #define TRACELOG1(description, Arg1) \
00293     IT_LOG_GUARDED1(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description, Arg1)
00294 
00295 #define TRACELOG2(description, Arg1, Arg2) \
00296     IT_LOG_GUARDED2(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description, Arg1, Arg2)
00297 
00298 #define TRACELOG3(description, Arg1, Arg2, Arg3) \
00299     IT_LOG_GUARDED3(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description, Arg1, Arg2, Arg3)
00300 
00301 #define TRACELOG4(description, Arg1, Arg2, Arg3, Arg4) \
00302     IT_LOG_GUARDED4(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description, Arg1, Arg2, Arg3, Arg4)
00303 
00304 #define TRACELOG5(description, Arg1, Arg2, Arg3, Arg4, Arg5) \
00305     IT_LOG_GUARDED5(_IT_BUS_LOGGER, _IT_SUBSYSTEM_SERVICE, IT_TRACE , description, Arg1, Arg2, Arg3, Arg4, Arg5)
00306 
00307 // as above but these are used as above but where service name logging 
00308 // is enabled but not available in the current scope
00309 #define TRACELOG_NSN(description) \
00310     IT_LOG_GUARDED(_IT_BUS_LOGGER, 0, IT_TRACE , description)
00311 
00312 #define TRACELOG_NSN0(description) \
00313     IT_LOG_GUARDED(_IT_BUS_LOGGER, 0, IT_TRACE , description)
00314 
00315 #define TRACELOG_NSN1(description, Arg1) \
00316     IT_LOG_GUARDED1(_IT_BUS_LOGGER, 0, IT_TRACE , description, Arg1)
00317 
00318 #define TRACELOG_NSN2(description, Arg1, Arg2) \
00319     IT_LOG_GUARDED2(_IT_BUS_LOGGER, 0, IT_TRACE , description, Arg1, Arg2)
00320 
00321 #define TRACELOG_NSN3(description, Arg1, Arg2, Arg3) \
00322     IT_LOG_GUARDED3(_IT_BUS_LOGGER, 0, IT_TRACE , description, Arg1, Arg2, Arg3)
00323 
00324 #define TRACELOG_NSN4(description, Arg1, Arg2, Arg3, Arg4) \
00325     IT_LOG_GUARDED4(_IT_BUS_LOGGER, 0, IT_TRACE , description, Arg1, Arg2, Arg3, Arg4)
00326 
00327 #define TRACELOG_NSN5(description, Arg1, Arg2, Arg3, Arg4, Arg5) \
00328     IT_LOG_GUARDED5(_IT_BUS_LOGGER, 0, IT_TRACE , description, Arg1, Arg2, Arg3, Arg4, Arg5)
00329 
00330 #ifdef _IT_LOGGING_SERVICE_NAME_RETRIEVER_INSTANCE_
00331     #define _IT_SUBSYSTEM_SERVICE _IT_LOGGING_SERVICE_NAME_RETRIEVER_INSTANCE_
00332 #else
00333     #define _IT_SUBSYSTEM_SERVICE 0
00334 #endif
00335 
00336 #ifndef _IT_BUS_LOGGER
00337 #define _IT_BUS_LOGGER _it_bus_logger
00338 #endif
00339 
00340 #ifdef _IT_IN_WSDL_CPP_CLIENT_STUBS
00341   #ifndef _IT_SUBSYSTEM_SCOPE
00342     #define _IT_SUBSYSTEM_SCOPE "IT_BUS.STUB.CLIENT"
00343   #endif
00344 #endif
00345 #ifdef _IT_IN_WSDL_CPP_SERVER_STUBS
00346   #ifndef _IT_SUBSYSTEM_SCOPE
00347     #define _IT_SUBSYSTEM_SCOPE "IT_BUS.STUB.SERVER"
00348   #endif
00349 #endif
00350 
00351 #ifndef _IT_SUBSYSTEM_SCOPE
00352     #define _IT_SUBSYSTEM_SCOPE "IT_BUS"
00353 #endif
00354 
00355 #define IT_INIT_BUS_LOGGER_MEM(bus) \
00356     _it_bus_logger = bus->get_pdk_bus()->get_bus_logger(_IT_SUBSYSTEM_SCOPE);
00357 
00358 #define IT_NULL_BUS_LOGGER_MEM \
00359     _it_bus_logger = 0;
00360 
00361 #define IT_FINALISE_BUS_LOGGER_MEM(bus) \
00362     bus->get_pdk_bus()->bus_logger_complete( \
00363         _it_bus_logger,_IT_SUBSYSTEM_SCOPE \
00364     ); \
00365     _it_bus_logger = 0;
00366 
00367 
00368 #define IT_DECLARE_BUS_LOGGER_MEM_SAFE IT_Bus::Logging::BusLogger* _it_bus_logger = 0;
00369 
00370 #define IT_INIT_BUS_LOGGER_MEM_SAFE(bus) \
00371     if (_it_bus_logger == 0) _it_bus_logger = bus->get_pdk_bus()->get_bus_logger(_IT_SUBSYSTEM_SCOPE);
00372 
00373 #define IT_FINALISE_BUS_LOGGER_MEM_SAFE(bus) \
00374     if (_it_bus_logger != 0) { \
00375       bus->get_pdk_bus()->bus_logger_complete( \
00376         _it_bus_logger,_IT_SUBSYSTEM_SCOPE \
00377       ); \
00378       _it_bus_logger = 0; \
00379     }
00380 
00381 #define IT_GET_SUBSYSTEM(subsystem) \
00382     if (0 == _IT_BUS_LOGGER) \
00383         throw Exception("BusLogger not available"); \
00384     subsystem = _IT_BUS_LOGGER->get_subsystem();
00385 
00386 #define IT_GET_SUBSYSTEM_LOG_FILTER(filter) \
00387     if (0 == _IT_BUS_LOGGER) \
00388         throw Exception("BusLogger not available"); \
00389     filter = _IT_BUS_LOGGER->get_subsystem_log_filter();
00390 
00391 #define IT_GET_BUS_MASTER_LOG_FILTER(filter) \
00392     if (0 == _IT_BUS_LOGGER) \
00393         throw Exception("BusLogger not available"); \
00394     filter = _IT_BUS_LOGGER->get_bus_master_log_filter();
00395 
00396 #endif  

Generated on Tue Mar 20 15:27:41 2007 for Artix by  doxygen 1.5.1-p1