async_logger.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 // Very fast asynchronous logger (millions of logs per second on an average desktop)
9 // Uses pre allocated lockfree queue for maximum throughput even under large number of threads.
10 // Creates a single back thread to pop messages from the queue and log them.
11 //
12 // Upon each log write the logger:
13 // 1. Checks if its log level is enough to log the message
14 // 2. Push a new copy of the message to a queue (or block the caller until space is available in the queue)
15 // 3. will throw spdlog_ex upon log exceptions
16 // Upon destruction, logs all remaining messages in the queue before destructing..
17 
18 #include "opc/spdlog/common.h"
19 #include "opc/spdlog/logger.h"
20 
21 #include <chrono>
22 #include <functional>
23 #include <string>
24 #include <memory>
25 
26 namespace spdlog
27 {
28 
29 namespace details
30 {
31 class async_log_helper;
32 }
33 
34 class async_logger SPDLOG_FINAL :public logger
35 {
36 public:
37  template<class It>
38  async_logger(const std::string& name,
39  const It& begin,
40  const It& end,
41  size_t queue_size,
43  const std::function<void()>& worker_warmup_cb = nullptr,
44  const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
45  const std::function<void()>& worker_teardown_cb = nullptr);
46 
47  async_logger(const std::string& logger_name,
48  sinks_init_list sinks,
49  size_t queue_size,
51  const std::function<void()>& worker_warmup_cb = nullptr,
52  const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
53  const std::function<void()>& worker_teardown_cb = nullptr);
54 
55  async_logger(const std::string& logger_name,
56  sink_ptr single_sink,
57  size_t queue_size,
59  const std::function<void()>& worker_warmup_cb = nullptr,
60  const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(),
61  const std::function<void()>& worker_teardown_cb = nullptr);
62 
63  //Wait for the queue to be empty, and flush synchronously
64  //Warning: this can potentially last forever as we wait it to complete
65  void flush() override;
66 
67  // Error handler
68  virtual void set_error_handler(log_err_handler) override;
69  virtual log_err_handler error_handler() override;
70 
71 protected:
72  void _sink_it(details::log_msg& msg) override;
73  void _set_formatter(spdlog::formatter_ptr msg_formatter) override;
74  void _set_pattern(const std::string& pattern, pattern_time_type pattern_time) override;
75 
76 private:
77  std::unique_ptr<details::async_log_helper> _async_log_helper;
78 };
79 }
80 
81 
std::unique_ptr< details::async_log_helper > _async_log_helper
Definition: async_logger.h:77
std::shared_ptr< spdlog::formatter > formatter_ptr
std::shared_ptr< sinks::sink > sink_ptr
name
Definition: setup.py:38
OStream< ChannelType > & flush(OStream< ChannelType > &os)
Definition: stream.h:147
void set_error_handler(log_err_handler)
Definition: spdlog_impl.h:239
std::initializer_list< sink_ptr > sinks_init_list
std::function< void(const std::string &err_msg)> log_err_handler


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