stdout_sinks.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 
10 
11 #include <cstdio>
12 #include <memory>
13 #include <mutex>
14 
15 namespace spdlog
16 {
17 namespace sinks
18 {
19 
20 template <class Mutex>
21 class stdout_sink SPDLOG_FINAL : public base_sink<Mutex>
22 {
23  using MyType = stdout_sink<Mutex>;
24 public:
26  {}
27  static std::shared_ptr<MyType> instance()
28  {
29  static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
30  return instance;
31  }
32 protected:
33  void _sink_it(const details::log_msg& msg) override
34  {
35  fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stdout);
36  _flush();
37  }
38 
39  void _flush() override
40  {
41  fflush(stdout);
42  }
43 };
44 
45 typedef stdout_sink<details::null_mutex> stdout_sink_st;
46 typedef stdout_sink<std::mutex> stdout_sink_mt;
47 
48 
49 template <class Mutex>
50 class stderr_sink SPDLOG_FINAL : public base_sink<Mutex>
51 {
52  using MyType = stderr_sink<Mutex>;
53 public:
55  {}
56  static std::shared_ptr<MyType> instance()
57  {
58  static std::shared_ptr<MyType> instance = std::make_shared<MyType>();
59  return instance;
60  }
61 protected:
62  void _sink_it(const details::log_msg& msg) override
63  {
64  fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stderr);
65  _flush();
66  }
67 
68  void _flush() override
69  {
70  fflush(stderr);
71  }
72 };
73 
74 typedef stderr_sink<std::mutex> stderr_sink_mt;
75 typedef stderr_sink<details::null_mutex> stderr_sink_st;
76 }
77 }
#define SPDLOG_FINAL
static std::shared_ptr< MyType > instance()
Definition: stdout_sinks.h:27
const Char * data() const FMT_NOEXCEPT
Definition: format.h:2866
stderr_sink< details::null_mutex > stderr_sink_st
Definition: stdout_sinks.h:75
fmt::MemoryWriter formatted
Definition: log_msg.h:46
std::size_t size() const
Definition: format.h:2857
void _sink_it(const details::log_msg &msg) override
Definition: stdout_sinks.h:33
stdout_sink< details::null_mutex > stdout_sink_st
Definition: stdout_sinks.h:45
stderr_sink< std::mutex > stderr_sink_mt
Definition: stdout_sinks.h:74
stdout_sink< std::mutex > stdout_sink_mt
Definition: stdout_sinks.h:46


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Tue Jan 19 2021 03:12:08