#ifndef TILE_BASE_LOGGING_SPLITTER_SINK_H
#define TILE_BASE_LOGGING_SPLITTER_SINK_H

#pragma once
#include "tile/base/internal/logging.h"

#include <mutex>
#include <set>

namespace tile {
class SplitterSink : public LogSink {
public:
    using Ptr = std::shared_ptr<SplitterSink>;
    static Ptr Create();
    static Ptr Create(std::initializer_list<std::shared_ptr<LogSink>> init_list);

    const char *name() const override { return "SplitterSink"; }

    ~SplitterSink() override;

    void Send(LogSeverity severity,
              const char *full_filename,
              const char *base_filename,
              int line,
              const LogMessageTime &logmsgtime,
              const char *message,
              size_t message_len) override;
    void Flush() override;

    void AddSink(std::shared_ptr<LogSink> sink);
    void RemoveSink(std::shared_ptr<LogSink> sink);
    void ClearSinks();
    std::set<LogSink::Ptr> sinks();

protected:
    SplitterSink();

private:
    std::set<std::shared_ptr<LogSink>> sinks_;
    std::mutex sinks_mutex_;
    bool doing_ = false;
};
}// namespace tile

#endif// TILE_BASE_LOGGING_SPLITTER_SINK_H
