openmw-tes3coop/components/openmw-mp/Log.hpp

62 lines
1.6 KiB
C++
Raw Normal View History

2016-08-14 23:45:42 +00:00
//
// Created by koncord on 15.08.16.
//
#ifndef OPENMW_LOG_HPP
#define OPENMW_LOG_HPP
2016-12-18 04:43:30 +00:00
#include <boost/filesystem.hpp>
2016-11-17 04:39:35 +00:00
#ifdef __GNUC__
#pragma GCC system_header
#endif
2016-08-14 23:45:42 +00:00
#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()
2016-11-17 12:51:03 +00:00
#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
2016-11-17 04:39:35 +00:00
#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)
2016-08-14 23:45:42 +00:00
#endif
2016-11-17 12:51:03 +00:00
#endif
2016-08-14 23:45:42 +00:00
class Log
{
2016-11-17 04:39:35 +00:00
public:
enum
{
LOG_OFF = 0,
LOG_FATAL,
2016-11-17 04:39:35 +00:00
LOG_ERROR,
LOG_WARN,
LOG_INFO,
LOG_VERBOSE,
LOG_TRACE,
2016-11-17 04:39:35 +00:00
};
static Log &Get();
void SetLevel(int level);
2016-11-17 04:39:35 +00:00
void print(int level, bool hasPrefix, const char *file, int line, const char *message, ...) const;
static std::string getFilenameTimestamp();
2017-06-27 14:56:02 +00:00
Log(const Log &) = delete;
Log &operator=(Log &) = delete;
private:
explicit Log(int logLevel);
2016-11-17 04:39:35 +00:00
int logLevel;
2016-08-14 23:45:42 +00:00
};
#endif //OPENMW_LOG_HPP