Back to home page

EIC code displayed by LXR

 
 

    


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

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 #include <spdlog/details/log_msg_buffer.h>
0007 #include <spdlog/details/circular_q.h>
0008 
0009 #include <atomic>
0010 #include <mutex>
0011 #include <functional>
0012 
0013 // Store log messages in circular buffer.
0014 // Useful for storing debug data in case of error/warning happens.
0015 
0016 namespace spdlog {
0017 namespace details {
0018 class SPDLOG_API backtracer
0019 {
0020     mutable std::mutex mutex_;
0021     std::atomic<bool> enabled_{false};
0022     circular_q<log_msg_buffer> messages_;
0023 
0024 public:
0025     backtracer() = default;
0026     backtracer(const backtracer &other);
0027 
0028     backtracer(backtracer &&other) SPDLOG_NOEXCEPT;
0029     backtracer &operator=(backtracer other);
0030 
0031     void enable(size_t size);
0032     void disable();
0033     bool enabled() const;
0034     void push_back(const log_msg &msg);
0035 
0036     // pop all items in the q and apply the given fun on each of them.
0037     void foreach_pop(std::function<void(const details::log_msg &)> fun);
0038 };
0039 
0040 } // namespace details
0041 } // namespace spdlog
0042 
0043 #ifdef SPDLOG_HEADER_ONLY
0044 #    include "backtracer-inl.h"
0045 #endif