Livox SDK API
V2.0.0
ostream_sink.h
Go to the documentation of this file.
1
//
2
// Copyright(c) 2015 Gabi Melman.
3
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
4
//
5
6
#pragma once
7
8
#ifndef SPDLOG_H
9
#include "
spdlog/spdlog.h
"
10
#endif
11
12
#include "
spdlog/details/null_mutex.h
"
13
#include "
spdlog/sinks/base_sink.h
"
14
15
#include <mutex>
16
#include <ostream>
17
18
namespace
spdlog
{
19
namespace
sinks {
20
template
<
typename
Mutex>
21
class
ostream_sink
final :
public
base_sink
<Mutex>
22
{
23
public
:
24
explicit
ostream_sink
(std::ostream &os,
bool
force_flush =
false
)
25
:
ostream_
(os)
26
,
force_flush_
(force_flush)
27
{
28
}
29
ostream_sink
(
const
ostream_sink
&) =
delete
;
30
ostream_sink
&
operator=
(
const
ostream_sink
&) =
delete
;
31
32
protected
:
33
void
sink_it_
(
const
details::log_msg
&msg)
override
34
{
35
fmt::memory_buffer
formatted;
36
sink::formatter_
->format(msg, formatted);
37
ostream_
.write(formatted.
data
(), static_cast<std::streamsize>(formatted.
size
()));
38
if
(
force_flush_
)
39
{
40
ostream_
.flush();
41
}
42
}
43
44
void
flush_
()
override
45
{
46
ostream_
.flush();
47
}
48
49
std::ostream &
ostream_
;
50
bool
force_flush_
;
51
};
52
53
using
ostream_sink_mt
=
ostream_sink<std::mutex>
;
54
using
ostream_sink_st
=
ostream_sink<details::null_mutex>
;
55
56
}
// namespace sinks
57
}
// namespace spdlog
fmt::v5::basic_memory_buffer
Definition:
format.h:464
spdlog::sinks::sink::formatter_
std::unique_ptr< spdlog::formatter > formatter_
Definition:
sink.h:50
spdlog::sinks::ostream_sink::ostream_sink
ostream_sink(std::ostream &os, bool force_flush=false)
Definition:
ostream_sink.h:24
base_sink.h
spdlog::sinks::ostream_sink::flush_
void flush_() override
Definition:
ostream_sink.h:44
fmt::v5::internal::basic_buffer::size
std::size_t size() const
Definition:
core.h:250
fmt::v5::internal::basic_buffer::data
T * data()
Definition:
core.h:256
null_mutex.h
spdlog
Definition:
async.h:27
spdlog::sinks::ostream_sink::force_flush_
bool force_flush_
Definition:
ostream_sink.h:50
spdlog::sinks::base_sink
Definition:
base_sink.h:22
spdlog.h
spdlog::sinks::ostream_sink::sink_it_
void sink_it_(const details::log_msg &msg) override
Definition:
ostream_sink.h:33
spdlog::details::log_msg
Definition:
log_msg.h:16
spdlog::sinks::ostream_sink::operator=
ostream_sink & operator=(const ostream_sink &)=delete
spdlog::sinks::ostream_sink
Definition:
ostream_sink.h:21
spdlog::sinks::ostream_sink::ostream_
std::ostream & ostream_
Definition:
ostream_sink.h:49
sdk_core
include
third_party
spdlog
spdlog
sinks
ostream_sink.h
Generated by
1.8.16