-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjson_logger.h
31 lines (27 loc) · 1.06 KB
/
json_logger.h
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
#ifndef JSON_LOGGER_H
#define JSON_LOGGER_H
#include <map>
#include <set>
#include <string>
#include <vector>
#include <boost/variant.hpp>
class json_logger {
public:
typedef enum { LOG_NONE, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, LOG_ERROR, LOG_FATAL } severity;
typedef enum { FMT_TEXT, FMT_JSON } format;
typedef boost::variant<long, double, std::string> meta_value;
typedef std::map<std::string, meta_value> meta_data;
static std::string to_json_string(const meta_data&);
private:
static std::vector<std::pair<format, std::ostream*>> log_output;
static severity severity_;
static severity max_severity_;
public:
static void register_output(format f, std::ostream* os) { log_output.push_back({ f, os }); }
static void set_severity(severity s) { severity_ = s; }
static severity get_severity() { return severity_; }
static severity get_max_severity() { return max_severity_; }
static void message(severity s, const std::string& m, const std::map<std::string, meta_data>& meta);
static void message(severity s, const std::string& m) { message(s, m, {}); };
};
#endif