mirror of
https://github.com/gabime/spdlog.git
synced 2025-10-02 11:29:01 +08:00
pattern per sink and pattern caching
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "fmt/fmt.h"
|
||||
#include "spdlog/details/log_msg.h"
|
||||
|
||||
#include <memory>
|
||||
@@ -12,31 +13,32 @@
|
||||
#include <vector>
|
||||
|
||||
namespace spdlog {
|
||||
namespace details {
|
||||
class flag_formatter;
|
||||
}
|
||||
|
||||
class formatter
|
||||
{
|
||||
public:
|
||||
virtual ~formatter() = default;
|
||||
virtual void format(details::log_msg &msg) = 0;
|
||||
virtual void format(const details::log_msg &msg, fmt::memory_buffer &dest) = 0;
|
||||
};
|
||||
|
||||
namespace details {
|
||||
class flag_formatter;
|
||||
}
|
||||
|
||||
class pattern_formatter SPDLOG_FINAL : public formatter
|
||||
{
|
||||
public:
|
||||
explicit pattern_formatter(const std::string &pattern, pattern_time_type pattern_time = pattern_time_type::local,
|
||||
std::string eol = spdlog::details::os::default_eol);
|
||||
pattern_formatter(const pattern_formatter &) = delete;
|
||||
pattern_formatter &operator=(const pattern_formatter &) = delete;
|
||||
void format(details::log_msg &msg) override;
|
||||
pattern_formatter(const pattern_formatter &) = default;
|
||||
pattern_formatter &operator=(const pattern_formatter &) = default;
|
||||
void format(const details::log_msg &msg, fmt::memory_buffer &dest) override;
|
||||
|
||||
private:
|
||||
const std::string eol_;
|
||||
const pattern_time_type pattern_time_;
|
||||
std::vector<std::unique_ptr<details::flag_formatter>> formatters_;
|
||||
std::tm get_time(details::log_msg &msg);
|
||||
std::tm get_time(const details::log_msg &msg);
|
||||
void handle_flag(char flag);
|
||||
void compile_pattern(const std::string &pattern);
|
||||
};
|
||||
|
Reference in New Issue
Block a user