Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-01 08:53:38

0001 // Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
0002 // Distributed under the MIT License (http://opensource.org/licenses/MIT)
0003 
0004 #pragma once
0005 
0006 // Fast asynchronous logger.
0007 // Uses pre allocated queue.
0008 // Creates a single back thread to pop messages from the queue and log them.
0009 //
0010 // Upon each log write the logger:
0011 //    1. Checks if its log level is enough to log the message
0012 //    2. Push a new copy of the message to a queue (or block the caller until
0013 //    space is available in the queue)
0014 // Upon destruction, logs all remaining messages in the queue before
0015 // destructing..
0016 
0017 #include <spdlog/logger.h>
0018 
0019 namespace spdlog {
0020 
0021 // Async overflow policy - block by default.
0022 enum class async_overflow_policy {
0023     block,           // Block until message can be enqueued
0024     overrun_oldest,  // Discard oldest message in the queue if full when trying to
0025                      // add new item.
0026     discard_new      // Discard new message if the queue is full when trying to add new item.
0027 };
0028 
0029 namespace details {
0030 class thread_pool;
0031 }
0032 
0033 class SPDLOG_API async_logger final : public std::enable_shared_from_this<async_logger>,
0034                                       public logger {
0035     friend class details::thread_pool;
0036 
0037 public:
0038     template <typename It>
0039     async_logger(std::string logger_name,
0040                  It begin,
0041                  It end,
0042                  std::weak_ptr<details::thread_pool> tp,
0043                  async_overflow_policy overflow_policy = async_overflow_policy::block)
0044         : logger(std::move(logger_name), begin, end),
0045           thread_pool_(std::move(tp)),
0046           overflow_policy_(overflow_policy) {}
0047 
0048     async_logger(std::string logger_name,
0049                  sinks_init_list sinks_list,
0050                  std::weak_ptr<details::thread_pool> tp,
0051                  async_overflow_policy overflow_policy = async_overflow_policy::block);
0052 
0053     async_logger(std::string logger_name,
0054                  sink_ptr single_sink,
0055                  std::weak_ptr<details::thread_pool> tp,
0056                  async_overflow_policy overflow_policy = async_overflow_policy::block);
0057 
0058     std::shared_ptr<logger> clone(std::string new_name) override;
0059 
0060 protected:
0061     void sink_it_(const details::log_msg &msg) override;
0062     void flush_() override;
0063     void backend_sink_it_(const details::log_msg &incoming_log_msg);
0064     void backend_flush_();
0065 
0066 private:
0067     std::weak_ptr<details::thread_pool> thread_pool_;
0068     async_overflow_policy overflow_policy_;
0069 };
0070 }  // namespace spdlog
0071 
0072 #ifdef SPDLOG_HEADER_ONLY
0073     #include "async_logger-inl.h"
0074 #endif