You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

123 lines
3.9 KiB

#ifndef __BASICLOGCOLLECTION_H_INCL__
#define __BASICLOGCOLLECTION_H_INCL__
#include <time.h>
#include "basicLoggingService.h"
#include "basicMutex.h"
typedef enum EE_LOG_LEVEL{
_LOG_NONE = 0,
_LOG_CRITICAL = 1,
_LOG_ERROR,
_LOG_DEBUG,
_LOG_VERBOSE,
_LOG_ALL
} _LOG_LEVEL;
typedef enum EE_LOG_SETTINGS{
_LOG_SIMPLE = 0,
_LOG_TIME = 1,
_LOG_PTR = 2,
_LOG_TIME_PTR = 3,
_LOG_LVL = 4,
_LOG_LVL_TIME = 5,
_LOG_LVL_PTR = 6,
_LOG_LVL_TIME_PTR = 7
} _LOG_SETTINGS;
#define _DEFAULT_LOG_LEVEL_ _LOG_DEBUG
#define _WORKING_LOG_LEVEL_ _LOG_ALL
#define _DEFAULT_LOG_SETTINGS _LOG_TIME_PTR
/**
* @Description Singleton class to handle logging
*
* @author Gagua
*/
class basicLogCollection {
private:
basicMutex m_mLogMutex;
LoggersRing *m_pRing;
_LOG_LEVEL m_bMaxLevel;
_LOG_SETTINGS m_bLogSettings;
static CSTR m_pBroadcastBuffer;
void broadcast( CSTR Msg );
public:
// Method to fetch singleton instance.
static basicLogCollection* getInstance( _LOG_SETTINGS val = _DEFAULT_LOG_SETTINGS );
// Destructor
virtual ~basicLogCollection();
void addHandler( basicLoggingService *handler );
void setLogLevel( _LOG_LEVEL level );
void Log( const char *Mod, void *ptr, CSTR Msg );
void Log( const char *Mod, void *ptr, const char *Msg );
void Log( const char *Mod, void *ptr, _LOG_LEVEL Level, CSTR Msg );
void Log( const char *Mod, void *ptr, _LOG_LEVEL Level, const char *Msg );
protected:
// Constructor - protected so users cannot call it.
explicit basicLogCollection( _LOG_SETTINGS val );
private:
// private static member referencing the single instance of the object
// TODO: Replace basicLogCollection with the type of object you want to
// return the single instance of
static basicLogCollection* _instance;
// Copy constructor
// Declared but not defined to prevent auto-generated
// copy constructor. Refer to "Effective C++" by Meyers
basicLogCollection(const basicLogCollection& src);
// Assignment operator
// Declared but not defined to prevent auto-generated
// assignment operator. Refer to "Effective C++" by Meyers
basicLogCollection& operator=(const basicLogCollection& src);
};
// Constructor implementation
inline basicLogCollection::basicLogCollection( _LOG_SETTINGS val ):m_mLogMutex(){
m_pBroadcastBuffer = (CSTR) malloc( MAX_LOG_MSG_SIZE );
if( m_pBroadcastBuffer!= NULL ) {
m_pRing = new LoggersRing();//4); // Maximum 4 Logginig Engines;
if( m_pRing != NULL ) {
m_bLogSettings = val;
memset( m_pBroadcastBuffer, 0, MAX_LOG_MSG_SIZE );
m_bMaxLevel = _DEFAULT_LOG_LEVEL_;
} else {
printf( "Error Creating MemRing for LogCollection!");
};
} else {
m_pRing = NULL;
};
};
// Destructor implementation
inline basicLogCollection::~basicLogCollection(){
if( m_pRing != NULL ) delete m_pRing;
if( m_pBroadcastBuffer != NULL ) free(m_pBroadcastBuffer );
};
// TODO: Uncomment the copy constructor when you need it.
//inline basicLogCollection::basicLogCollection(const basicLogCollection& src)
//{
// // TODO: copy
//}
// TODO: Uncomment the assignment operator when you need it.
//inline basicLogCollection& basicLogCollection::operator=(const basicLogCollection& rhs)
//{
// if (this == &rhs) {
// return *this;
// }
//
// // TODO: assignment
//
// return *this;
//}
#endif // __BASICLOGCOLLECTION_H_INCL__