userver: userver/logging/stacktrace_cache.hpp Source File
Loading...
Searching...
No Matches
stacktrace_cache.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/logging/stacktrace_cache.hpp
4/// @brief Cached stringification for Boost stack traces.
5/// @ingroup userver_universal
6
7#include <string>
8
9#include <boost/stacktrace/stacktrace_fwd.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13/// @brief Cached stringification for stack traces.
14namespace logging::stacktrace_cache {
15
16/// Get cached stacktrace
17/// @see GlobalEnableStacktrace
18std::string to_string(const boost::stacktrace::stacktrace& st); // NOLINT(readability-identifier-naming)
19
20/// Enable/disable stacktraces. If disabled, stacktrace_cache::to_string()
21/// returns with a const string.
22///
23/// @note Disabling stacktraces is a hack for the Boost.Stacktrace memory leak
24bool GlobalEnableStacktrace(bool enable);
25
26/// RAII-wrapper for `GlobalEnableStacktrace`. Should be used to temporarily
27/// enable stacktraces after `GlobalEnableStacktrace(false)`.
29public:
30 explicit StacktraceGuard(bool enabled);
31
32 ~StacktraceGuard();
33
34private:
35 const bool old_;
36};
37
38} // namespace logging::stacktrace_cache
39
40USERVER_NAMESPACE_END