2019-08-26 12:59:16 -04:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "spdlog/details/log_msg_buffer.h"
|
|
|
|
#include "spdlog/details/circular_q.h"
|
2019-09-04 18:58:34 -04:00
|
|
|
|
|
|
|
#include <atomic>
|
2019-08-26 12:59:16 -04:00
|
|
|
#include <mutex>
|
2019-09-04 18:58:34 -04:00
|
|
|
#include <functional>
|
|
|
|
|
2019-08-26 12:59:16 -04:00
|
|
|
// Store log messages in circular buffer.
|
|
|
|
// Useful for storing debug data in case of error/warning happens.
|
|
|
|
|
|
|
|
namespace spdlog {
|
2019-09-04 18:25:00 -04:00
|
|
|
namespace details {
|
|
|
|
class backtracer
|
|
|
|
{
|
|
|
|
mutable std::mutex mutex_;
|
|
|
|
std::atomic<bool> enabled_{false};
|
|
|
|
circular_q<log_msg_buffer> messages_;
|
2019-09-04 17:39:11 -04:00
|
|
|
|
2019-09-04 18:25:00 -04:00
|
|
|
public:
|
|
|
|
backtracer() = default;
|
|
|
|
backtracer(const backtracer &other);
|
2019-09-04 17:39:11 -04:00
|
|
|
|
2019-09-04 18:25:00 -04:00
|
|
|
backtracer(backtracer &&other) SPDLOG_NOEXCEPT;
|
|
|
|
backtracer &operator=(backtracer other);
|
2019-09-04 18:58:34 -04:00
|
|
|
|
2019-09-04 18:25:00 -04:00
|
|
|
void enable(size_t size);
|
|
|
|
void disable();
|
|
|
|
bool enabled() const;
|
|
|
|
explicit operator bool() const;
|
|
|
|
void push_back(const log_msg &msg);
|
2019-09-04 17:39:11 -04:00
|
|
|
|
2019-09-04 18:25:00 -04:00
|
|
|
// pop all items in the q and apply the given fun on each of them.
|
|
|
|
void foreach_pop(std::function<void(const details::log_msg &)> fun);
|
|
|
|
};
|
2019-09-04 17:39:11 -04:00
|
|
|
|
2019-09-04 18:25:00 -04:00
|
|
|
} // namespace details
|
|
|
|
} // namespace spdlog
|
2019-09-04 17:39:11 -04:00
|
|
|
|
2019-09-04 18:25:00 -04:00
|
|
|
#ifdef SPDLOG_HEADER_ONLY
|
|
|
|
#include "backtracer-inl.h"
|
|
|
|
#endif
|