1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00
SqMod/source/Logger.hpp

101 lines
3.4 KiB
C++
Raw Normal View History

2015-09-30 02:56:11 +02:00
#ifndef _LOGGER_HPP_
#define _LOGGER_HPP_
// ------------------------------------------------------------------------------------------------
#include "Base/Shared.hpp"
#include "Base/Buffer.hpp"
2015-09-30 02:56:11 +02:00
// ------------------------------------------------------------------------------------------------
namespace SqMod {
// ------------------------------------------------------------------------------------------------
enum LogLvl
2015-09-30 02:56:11 +02:00
{
LL_NIL = (1 << 0),
LL_DBG = (1 << 1),
LL_USR = (1 << 2),
LL_SCS = (1 << 3),
LL_INF = (1 << 4),
LL_WRN = (1 << 5),
LL_ERR = (1 << 6),
LL_FTL = (1 << 7),
LL_ANY = 0xFF
};
// --------------------------------------------------------------------------------------------
extern SQMOD_MANAGEDPTR_TYPE(Logger) _Log;
2015-09-30 02:56:11 +02:00
// ------------------------------------------------------------------------------------------------
class Logger
{
protected:
2015-09-30 02:56:11 +02:00
// --------------------------------------------------------------------------------------------
Logger();
2015-09-30 02:56:11 +02:00
// --------------------------------------------------------------------------------------------
Logger(const Logger & o) = delete;
Logger(Logger && o) = delete;
// --------------------------------------------------------------------------------------------
Logger & operator= (const Logger & o) = delete;
Logger & operator= (Logger && o) = delete;
2015-09-30 02:56:11 +02:00
public:
// --------------------------------------------------------------------------------------------
~Logger();
// --------------------------------------------------------------------------------------------
static Logger * Get()
{
if (!_Log)
{
return _Log = SQMOD_MANAGEDPTR_MAKE(Logger, new Logger());
}
return SQMOD_MANAGEDPTR_GET(_Log);
}
// --------------------------------------------------------------------------------------------
void ToggleTime(bool enabled) { m_Time = enabled; }
bool HasTime() const { return m_Time; }
2015-09-30 02:56:11 +02:00
// --------------------------------------------------------------------------------------------
void SetLevels(Uint8 levels) { m_Levels = levels; }
Uint8 GetLevels() const { return m_Levels; }
// --------------------------------------------------------------------------------------------
void EnableLevel(Uint8 level) { m_Levels |= level; }
void DisableLevel(Uint8 level) { if (m_Levels & level) m_Levels ^= level; }
// --------------------------------------------------------------------------------------------
void Send(Uint8 type, bool sub, CCStr fmt, va_list args);
// --------------------------------------------------------------------------------------------
void Message(Uint8 type, bool sub, CCStr fmt, ...);
// --------------------------------------------------------------------------------------------
void Debug(CCStr fmt, ...);
void Debug(CCStr fmt, va_list args);
protected:
// --------------------------------------------------------------------------------------------
void Proccess(Uint8 type, bool sub);
2015-09-30 02:56:11 +02:00
private:
// --------------------------------------------------------------------------------------------
Buffer m_Buffer;
SQChar m_TmBuff[80];
// --------------------------------------------------------------------------------------------
Uint8 m_Levels;
bool m_Time;
2015-09-30 02:56:11 +02:00
};
} // Namespace:: SqMod
#endif // _LOGGER_HPP_