1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 11:23:51 +00:00
openmw-tes3mp/components/openmw-mp/Log.hpp
Koncord 916ada108f [General] Modernize Log utility
* Reverse Log levels
* Add LOG_TRACE
* Spawn instance of Log in Get() function
2017-10-25 14:45:36 +08:00

61 lines
1.6 KiB
C++

//
// Created by koncord on 15.08.16.
//
#ifndef OPENMW_LOG_HPP
#define OPENMW_LOG_HPP
#include <boost/filesystem.hpp>
#ifdef __GNUC__
#pragma GCC system_header
#endif
#if defined(NOLOGS)
#define LOG_INIT(logLevel)
#define LOG_QUIT()
#define LOG_MESSAGE(level, msg, ...)
#define LOG_MESSAGE_SIMPLE(level, msg, ...)
#else
#define LOG_INIT(logLevel) Log::Get().SetLevel(logLevel)
#define LOG_QUIT()
#if defined(_MSC_VER)
#define LOG_MESSAGE(level, msg, ...) Log::Get().print((level), (1), (__FILE__), (__LINE__), (msg), __VA_ARGS__)
#define LOG_MESSAGE_SIMPLE(level, msg, ...) Log::Get().print((level), (1), (0), (0), (msg), __VA_ARGS__)
#define LOG_APPEND(level, msg, ...) Log::Get().print((level), (0), (0), (0), (msg), __VA_ARGS__)
#else
#define LOG_MESSAGE(level, msg, args...) Log::Get().print((level), (1), (__FILE__), (__LINE__), (msg), ##args)
#define LOG_MESSAGE_SIMPLE(level, msg, args...) Log::Get().print((level), (true), (0), (0), (msg), ##args)
#define LOG_APPEND(level, msg, args...) Log::Get().print((level), (false), (0), (0), (msg), ##args)
#endif
#endif
class Log
{
public:
enum
{
LOG_OFF = 0,
LOG_FATAL,
LOG_ERROR,
LOG_WARN,
LOG_INFO,
LOG_VERBOSE,
LOG_TRACE,
};
static Log &Get();
void SetLevel(int level);
void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const;
static std::string getFilenameTimestamp();
Log(const Log &) = delete;
Log &operator=(Log &) = delete;
private:
explicit Log(int logLevel);
int logLevel;
};
#endif //OPENMW_LOG_HPP