Source

pyGAP / game / engine / common / log.h

#ifndef _COMMON_LOG_
#define _COMMON_LOG_


#if defined(DEBUG)


#include <map>
#include <string>


#define LOG(...)                { if (log_) log_->write(common::Log::LOG_DEBUG, __VA_ARGS__); }
#define LOG_I(...)              { if (log_) log_->write(common::Log::LOG_INFO, __VA_ARGS__); }
#define LOG_W(...)              { if (log_) log_->write(common::Log::LOG_WARNING, __VA_ARGS__); }
#define LOG_E(...)              { if (log_) log_->write(common::Log::LOG_ERROR, __VA_ARGS__); }


namespace common {


class Log {
public:

    enum log_level_e {
        LOG_DEBUG,
        LOG_INFO,
        LOG_WARNING,
        LOG_ERROR
    };

    static Log* get(const char* context);
    static void clear();

    void write(log_level_e log_level, const char* format, ...);
    void set_log_threshold(log_level_e log_level=LOG_DEBUG);

private:
    Log(const char* context);
    virtual ~Log();

    char*   buffer_;
    int     context_length_;
    log_level_e threshold_;

    typedef std::map<std::string, Log*> log_map_t;
    static log_map_t    allocated_;
};


} /* namespace common */


#else // defined(DEBUG)

#define LOG(...)        {}
#define LOG_I(...)      {}
#define LOG_W(...)      {}
#define LOG_E(...)      {}

#endif // defined(DEBUG)



#endif