27#include <core/config.h>
65#ifdef H2CORE_HAVE_DEBUG
72#ifdef H2CORE_HAVE_DEBUG
111 static QString
base_clock(
const QString& sMsg );
137 virtual QString
toQString(
const QString& sPrefix =
"",
bool bShort =
true )
const;
143 void Print(
bool bShort =
true )
const;
149#ifdef H2CORE_HAVE_DEBUG
172 d << ( o ? o->
toQString(
"",
true ) :
"(nullptr)" );
176inline QDebug
operator<<( QDebug d, std::shared_ptr<Base> o ) {
177 d << ( o ? o->toQString(
"",
true ) :
"(nullptr)" );
184#ifdef H2CORE_HAVE_DEBUG
197#ifdef H2CORE_HAVE_DEBUG
211#ifdef H2CORE_HAVE_DEBUG
227#define H2_OBJECT(name) \
228 public: static const char* _class_name() { return #name; } \
229 const char* class_name() const override { return _class_name(); }
232#define __LOG_METHOD( lvl, msg ) if( __logger->should_log( (lvl) ) ) { __logger->log( (lvl), _class_name(), __FUNCTION__, QString( "%1" ).arg( msg ) ); }
233#define __LOG_CLASS( lvl, msg ) if( logger()->should_log( (lvl) ) ) { logger()->log( (lvl), _class_name(), __FUNCTION__, QString( "%1" ).arg( msg ) ); }
234#define __LOG_OBJ( lvl, msg ) if( __object->logger()->should_log( (lvl) ) ) { __object->logger()->log( (lvl), 0, __PRETTY_FUNCTION__, QString( "%1" ).arg( msg ) ); }
235#define __LOG_STATIC( lvl, msg ) if( H2Core::Logger::get_instance()->should_log( (lvl) ) ) { H2Core::Logger::get_instance()->log( (lvl), 0, __PRETTY_FUNCTION__, QString( "%1" ).arg( msg ) ); }
236#define __LOG( logger, lvl, msg ) if( (logger)->should_log( (lvl) ) ) { (logger)->log( (lvl), 0, 0, QString( "%1" ).arg( msg ) ); }
239#define DEBUGLOG(x) __LOG_METHOD( H2Core::Logger::Debug, (x) );
240#define INFOLOG(x) __LOG_METHOD( H2Core::Logger::Info, (x) );
241#define WARNINGLOG(x) __LOG_METHOD( H2Core::Logger::Warning, (x) );
242#define ERRORLOG(x) __LOG_METHOD( H2Core::Logger::Error, (x) );
245#define _DEBUGLOG(x) __LOG_CLASS( H2Core::Logger::Debug, (x) );
246#define _INFOLOG(x) __LOG_CLASS( H2Core::Logger::Info, (x) );
247#define _WARNINGLOG(x) __LOG_CLASS( H2Core::Logger::Warning, (x) );
248#define _ERRORLOG(x) __LOG_CLASS( H2Core::Logger::Error, (x) );
251#define __DEBUGLOG(x) __LOG_OBJ( H2Core::Logger::Debug, (x) );
252#define __INFOLOG(x) __LOG_OBJ( H2Core::Logger::Info, (x) );
253#define __WARNINGLOG(x) __LOG_OBJ( H2Core::Logger::Warning, (x) );
254#define __ERRORLOG(x) __LOG_OBJ( H2Core::Logger::Error, (x) );
257#define ___DEBUGLOG(x) __LOG_STATIC( H2Core::Logger::Debug, (x) );
258#define ___INFOLOG(x) __LOG_STATIC( H2Core::Logger::Info, (x) );
259#define ___WARNINGLOG(x) __LOG_STATIC(H2Core::Logger::Warning, (x) );
260#define ___ERRORLOG(x) __LOG_STATIC( H2Core::Logger::Error, (x) );
263#define CLOCK(...) __LOG_METHOD( H2Core::Logger::Debug, base_clock( QString( "%1" ).arg( #__VA_ARGS__ ) ) );
264#define CLOCKIN(...) __LOG_METHOD( H2Core::Logger::Debug, base_clock_in( QString( "%1" ).arg( #__VA_ARGS__ ) ) );
static std::atomic< int > __objects_count
total objects count
static void write_objects_map_to_cerr()
output objects map to stderr
static void registerClass(const char *name, const atomic_obj_cpt_t *counters)
static Logger * logger()
return the logger instance
virtual QString toQString(const QString &sPrefix="", bool bShort=true) const
Formatted string version for debugging purposes.
static QString base_clock_in(const QString &sMsg)
static object_map_t getObjectMap()
static pthread_mutex_t __mutex
yeah this has to be thread safe
static bool count_active()
static QString base_clock(const QString &sMsg)
Measures the current time and stores it in __last_clock.
static int getAliveObjectCount()
void Print(bool bShort=true) const
Prints content of toQString() via DEBUGLOG.
void logBacktrace() const
Print the current stack at point into the debug log.
static bool __count
should we count class instances
static int objects_count()
static void set_count(bool flag)
enable/disable class instances counting
static int bootstrap(Logger *logger, bool count=false)
must be called before any Object instantiation !
static timeval __last_clock
static object_internal_map_t __objects_map
objects classes and instances count structure
static QString sPrintIndention
String used to format the debugging string output of some core classes.
static void write_objects_map_to(std::ostream &out, object_map_t *map=nullptr)
output the full objects map to a given ostream
virtual const char * class_name() const
static void printObjectMapDiff(object_map_t map)
Creates the difference between a snapshot of the object map and its current state and prints it to st...
static const char * _class_name()
return the class name
Class for writing logs to the console.
Object(const Object< T > &other)
static atomic_obj_cpt_t counters
std::map< const char *, const atomic_obj_cpt_t * > object_internal_map_t
struct H2Core::atomic_obj_cpt_t atomic_obj_cpt_t
an objects class map item type
std::ostream & operator<<(std::ostream &os, const Base &object)
std::map< const char *, obj_cpt_t > object_map_t
the objects class map types
atomic_obj_cpt_t Object< T >::counters
an objects class map item type
std::atomic< int > constructed
std::atomic< int > destructed