| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- //
- // format.hpp
- // logger
- //
- // Created by Sam Jaffe on 8/21/16.
- //
- #pragma once
- #include <functional>
- #include <sstream>
- #include <string>
- #include <vector>
- #include "logger_fwd.h"
- #include "wrapper_object.h"
- namespace logging {
- class format {
- public:
- enum class token_id {
- DATE, PRIORITY, CATEGORY, MESSAGE, STRING, NEWLINE
- };
-
- using generator = std::function<void(logpacket const &, std::ostream &)>;
-
- static format parse_format_string(std::string const &);
- void process(logpacket const & pkt, std::ostream & os) const;
- std::string process(logpacket const & pkt) const;
- private:
- std::vector<generator> gen;
- };
-
- using string_generator = std::function<std::string(logpacket const &)>;
- string_generator get_date_formatter(std::string fmt);
-
- class message {
- public:
- message() = default;
- message(char const * fmt) : format_code(fmt) {}
- template <typename... Args>
- message(std::string const & fmt, Args && ...args);
-
- std::string str() const;
- Json::Value json() const;
- private:
- std::string format_code;
- std::vector<detail::object> objects;
- };
-
- template <typename... Args>
- message::message(std::string const & fmt, Args && ...args)
- : format_code(fmt), objects({detail::object(args)...}) {
-
- }
- }
|