Sha256: f6da7181d286e9ea066a690b574b68354edf6d3009b7b16239a3afb147eab210

Contents?: true

Size: 1.22 KB

Versions: 42

Compression:

Stored size: 1.22 KB

Contents

// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)

#pragma once

#include <spdlog/details/null_mutex.h>
#include <spdlog/sinks/base_sink.h>

#include <mutex>
#include <ostream>

namespace spdlog {
namespace sinks {
template<typename Mutex>
class ostream_sink final : public base_sink<Mutex>
{
public:
    explicit ostream_sink(std::ostream &os, bool force_flush = false)
        : ostream_(os)
        , force_flush_(force_flush)
    {}
    ostream_sink(const ostream_sink &) = delete;
    ostream_sink &operator=(const ostream_sink &) = delete;

protected:
    void sink_it_(const details::log_msg &msg) override
    {
        memory_buf_t formatted;
        base_sink<Mutex>::formatter_->format(msg, formatted);
        ostream_.write(formatted.data(), static_cast<std::streamsize>(formatted.size()));
        if (force_flush_)
        {
            ostream_.flush();
        }
    }

    void flush_() override
    {
        ostream_.flush();
    }

    std::ostream &ostream_;
    bool force_flush_;
};

using ostream_sink_mt = ostream_sink<std::mutex>;
using ostream_sink_st = ostream_sink<details::null_mutex>;

} // namespace sinks
} // namespace spdlog

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
couchbase-3.5.0 ext/cache/spdlog/66ab2619a0014319471759c03e2de1af6bda14de/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.4.5 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.4.4 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.4.3 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.4.2 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.4.1 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.4.0 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.3.0 ext/couchbase/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.2.0-universal-darwin-20 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.2.0 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.1.1 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.1.1-universal-darwin-20 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.1.0 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.3 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.3-universal-darwin-20 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.2 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.1-universal-darwin-19 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.1 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.0-universal-darwin-19 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h
couchbase-3.0.0 ext/third_party/spdlog/include/spdlog/sinks/ostream_sink.h