-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.hpp
40 lines (36 loc) · 1.12 KB
/
logger.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef LOGGER_HPP_INCLUDED
#define LOGGER_HPP_INCLUDED
#include "NonCopyable.hpp"
#include <cstdarg>
#include <ostream>
class Logger : public NonCopyable
{
public:
enum LEVEL {
LEVEL_DEBUG,
LEVEL_INFO,
LEVEL_WARN,
LEVEL_ERROR,
LEVEL_FATAL,
};
static Logger &get_instance();
Logger(std::ostream &os, const LEVEL level);
void log(const LEVEL level, const char *format, ...);
void debug(const char *format, ...);
void info(const char *format, ...);
void warn(const char *format, ...);
void error(const char *format, ...);
void fatal(const char *format, ...);
void set_level(const LEVEL level) { level_ = level; }
protected:
void vlog(const Logger::LEVEL, const char *format, va_list args);
private:
std::ostream &os_;
LEVEL level_;
};
#define LOG_DEBUG(...) Logger::get_instance().debug(__VA_ARGS__)
#define LOG_INFO(...) Logger::get_instance().info(__VA_ARGS__)
#define LOG_WARN(...) Logger::get_instance().warn(__VA_ARGS__)
#define LOG_ERROR(...) Logger::get_instance().error(__VA_ARGS__)
#define LOG_FATAL(...) Logger::get_instance().fatal(__VA_ARGS__)
#endif // !defined(LOGGER_HPP_INCLUDED)