Repo-Init
 
Loading...
Searching...
No Matches
spdlog::sinks::sentry_api_sink< Mutex > Class Template Reference

#include <Sentry.hpp>

Inheritance diagram for spdlog::sinks::sentry_api_sink< Mutex >:
Collaboration diagram for spdlog::sinks::sentry_api_sink< Mutex >:

Public Member Functions

 sentry_api_sink (const std::string &sentryAddress)
 
 ~sentry_api_sink ()
 

Protected Member Functions

void sink_it_ (const details::log_msg &msg) override
 
void flush_ () override
 

Private Attributes

bool _sentryAvailable {false}
 

Detailed Description

template<typename Mutex>
class spdlog::sinks::sentry_api_sink< Mutex >

A sink for sending log messages to a Sentry server.

This sink is used to send log messages to a Sentry server for error tracking and monitoring. It provides an interface for sending log messages and flushing the sink.

Template Parameters
MutexThe type of mutex to use for thread safety.

Definition at line 20 of file Sentry.hpp.

Constructor & Destructor Documentation

◆ sentry_api_sink()

template<typename Mutex >
spdlog::sinks::sentry_api_sink< Mutex >::sentry_api_sink ( const std::string & sentryAddress)
explicit

Constructs a Sentry API sink with the specified Sentry server address.

Parameters
sentryAddressThe address of the Sentry server.

Definition at line 118 of file Sentry.cpp.

119 {
120 if (sentryAddress.empty())
121 {
122 return;
123 }
124 _sentryAvailable = true;
125
126 // Set options
127 sentry_options_t *sentryOptions = sentry_options_new();
128 sentry_options_set_release(sentryOptions, PROJECT_FULL_REVISION);
129 sentry_options_set_dsn(sentryOptions, sentryAddress.c_str());
130
131 // Init
132 sentry_init(sentryOptions);
133
134 // Tags
135 sentry_set_tag("compiler.name", COMPILER_NAME);
136 sentry_set_tag("compiler.version", COMPILER_VERSION);
137 sentry_set_tag("build", BUILD_TYPE);
138
139 /* ################################################################################### */
140 /* ############################# MAKE MODIFICATIONS HERE ############################# */
141 /* ################################################################################### */
142
143 /* ################################################################################### */
144 /* ################################ END MODIFICATIONS ################################ */
145 /* ################################################################################### */
146
147 setVersionContext();
148 setHostContext();
149 setNetworkContext();
150 }

◆ ~sentry_api_sink()

template<typename Mutex >
spdlog::sinks::sentry_api_sink< Mutex >::~sentry_api_sink ( )

Destroys the Sentry API sink.

Definition at line 152 of file Sentry.cpp.

152{ sentry_close(); }

Member Function Documentation

◆ flush_()

template<typename Mutex >
void spdlog::sinks::sentry_api_sink< Mutex >::flush_ ( )
overrideprotected

Flushes the sink.

This function is called to flush any buffered log messages to the Sentry server.

Definition at line 185 of file Sentry.cpp.

186 {
187 // Sentry library handles all operations, so no need to flush
188 }

◆ sink_it_()

template<typename Mutex >
void spdlog::sinks::sentry_api_sink< Mutex >::sink_it_ ( const details::log_msg & msg)
overrideprotected

Sends the log message to the Sentry server.

This function is called for each log message that needs to be sent to the Sentry server.

Parameters
msgThe log message to be sent.

Definition at line 154 of file Sentry.cpp.

155 {
156 if (!_sentryAvailable)
157 {
158 return;
159 }
160 switch (msg.level)
161 {
162 case spdlog::level::warn:
163 sentry_capture_event(sentry_value_new_message_event(
164 SENTRY_LEVEL_WARNING, "main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
165 break;
166 case spdlog::level::err:
167 sentry_capture_event(sentry_value_new_message_event(
168 SENTRY_LEVEL_ERROR, "main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
169 break;
170 case spdlog::level::critical:
171 sentry_capture_event(sentry_value_new_message_event(
172 SENTRY_LEVEL_FATAL, "main", std::string(msg.payload.data(), msg.payload.size()).c_str()));
173 break;
174 case spdlog::level::trace:
175 case spdlog::level::debug:
176 case spdlog::level::info:
177 case spdlog::level::off:
178 // For lower levels, do nothing for now. But you can easily handle them here.
179 break;
180 default:
181 break;
182 }
183 }

Member Data Documentation

◆ _sentryAvailable

template<typename Mutex >
bool spdlog::sinks::sentry_api_sink< Mutex >::_sentryAvailable {false}
private

Flag indicating if the Sentry server is available.

Definition at line 52 of file Sentry.hpp.

52{false};

The documentation for this class was generated from the following files: