Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:12:43

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 {
0024     block,         // Block until message can be enqueued
0025     overrun_oldest // Discard oldest message in the queue if full when trying to
0026                    // 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>, public logger
0034 {
0035     friend class details::thread_pool;
0036 
0037 public:
0038     template<typename It>
0039     async_logger(std::string logger_name, It begin, It end, std::weak_ptr<details::thread_pool> tp,
0040         async_overflow_policy overflow_policy = async_overflow_policy::block)
0041         : logger(std::move(logger_name), begin, end)
0042         , thread_pool_(std::move(tp))
0043         , overflow_policy_(overflow_policy)
0044     {}
0045 
0046     async_logger(std::string logger_name, sinks_init_list sinks_list, std::weak_ptr<details::thread_pool> tp,
0047         async_overflow_policy overflow_policy = async_overflow_policy::block);
0048 
0049     async_logger(std::string logger_name, sink_ptr single_sink, std::weak_ptr<details::thread_pool> tp,
0050         async_overflow_policy overflow_policy = async_overflow_policy::block);
0051 
0052     std::shared_ptr<logger> clone(std::string new_name) override;
0053 
0054 protected:
0055     void sink_it_(const details::log_msg &msg) override;
0056     void flush_() override;
0057     void backend_sink_it_(const details::log_msg &incoming_log_msg);
0058     void backend_flush_();
0059 
0060 private:
0061     std::weak_ptr<details::thread_pool> thread_pool_;
0062     async_overflow_policy overflow_policy_;
0063 };
0064 } // namespace spdlog
0065 
0066 #ifdef SPDLOG_HEADER_ONLY
0067 #    include "async_logger-inl.h"
0068 #endif