2014-01-25 04:09:04 -05:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include<string>
|
|
|
|
#include<chrono>
|
|
|
|
#include<functional>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "../level.h"
|
|
|
|
#include "../details/os.h"
|
|
|
|
|
|
|
|
namespace c11log {
|
|
|
|
namespace formatters {
|
2014-02-05 18:21:40 -05:00
|
|
|
typedef std::chrono::system_clock clock;
|
|
|
|
typedef clock::time_point time_point;
|
|
|
|
typedef std::function<std::string(const std::string& logger_name, const std::string&, level::level_enum, const time_point&)> format_fn;
|
2014-02-11 14:03:57 -05:00
|
|
|
|
|
|
|
|
2014-01-25 04:09:04 -05:00
|
|
|
std::string to_hex(const unsigned char* buf, std::size_t size);
|
|
|
|
|
|
|
|
class formatter {
|
|
|
|
public:
|
|
|
|
formatter() {}
|
|
|
|
virtual ~formatter() {}
|
2014-02-05 18:21:40 -05:00
|
|
|
virtual void format_header(const std::string& logger_name, level::level_enum level, const time_point& tp, std::ostream& dest) = 0;
|
2014-01-25 04:09:04 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class default_formatter: public formatter {
|
|
|
|
public:
|
|
|
|
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
|
2014-02-05 18:21:40 -05:00
|
|
|
void format_header(const std::string& logger_name, level::level_enum level, const time_point& tp, std::ostream& dest) override
|
2014-01-25 04:09:04 -05:00
|
|
|
{
|
2014-02-11 14:03:57 -05:00
|
|
|
_format_time(tp, dest);
|
2014-01-25 04:09:04 -05:00
|
|
|
dest << " [" << logger_name << ":" << c11log::level::to_str(level) << "] ";
|
|
|
|
}
|
2014-02-11 14:03:57 -05:00
|
|
|
private:
|
|
|
|
void _format_time(const time_point& tp, std::ostream &dest);
|
2014-01-25 04:09:04 -05:00
|
|
|
|
|
|
|
};
|
|
|
|
} //namespace formatter
|
|
|
|
} //namespace c11log
|