| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //
- // 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);
-
- void format_msg(std::ostream & os, std::string const & interp, size_t pos,
- std::vector<detail::object> const & objs, size_t idx);
-
- template <typename... Args>
- std::string format_msg(std::string const & interp, Args && ...args) {
- std::stringstream msg;
- format_msg(msg, interp, 0, {detail::object(args)...}, 0);
- return msg.str();
- }
- }
|