135 {
136 if (!my->gelf_endpoint)
137 return;
138
139 log_context
context = message.get_context();
140
141 mutable_variant_object gelf_message;
142 gelf_message["version"] = "1.1";
143 gelf_message["host"] = my->cfg.host;
144 gelf_message[
"short_message"] =
format_string(message.get_format(), message.get_data(),
true);
145
146
148 gelf_message["timestamp"] = time_ns / 1000000.;
149 gelf_message["_timestamp_ns"] = time_ns;
150
153
154 switch (
context.get_log_level())
155 {
157 gelf_message["level"] = 7;
158 break;
160 gelf_message["level"] = 6;
161 break;
163 gelf_message["level"] = 4;
164 break;
166 gelf_message["level"] = 3;
167 break;
170
171 gelf_message["level"] = 6;
172 break;
173 }
174
175 if (!
context.get_context().empty())
176 gelf_message[
"context"] =
context.get_context();
177 gelf_message[
"_line"] =
context.get_line_number();
178 gelf_message[
"_file"] =
context.get_file();
179 gelf_message[
"_method_name"] =
context.get_method();
180 gelf_message[
"_thread_name"] =
context.get_thread_name();
181 if (!
context.get_task_name().empty())
182 gelf_message[
"_task_name"] =
context.get_task_name();
183
184 for(
auto&&
field : my->cfg.user_fields) {
186 }
187
191 gelf_message_as_string =
zlib_compress(gelf_message_as_string);
192
193
194
195
196
197
198
199 const unsigned max_payload_size = 512;
200
201 if (gelf_message_as_string.size() <= max_payload_size)
202 {
203
204 std::shared_ptr<char> send_buffer(new char[gelf_message_as_string.size()],
205 [](
char*
p){ delete[] p; });
206 memcpy(send_buffer.get(), gelf_message_as_string.c_str(),
207 gelf_message_as_string.size());
208
209 my->gelf_socket.send_to(send_buffer, gelf_message_as_string.size(),
210 *my->gelf_endpoint);
211 }
212 else
213 {
214
215
216
217 uint64_t message_id =
city_hash64(gelf_message_as_string.c_str(), gelf_message_as_string.size());
218 const unsigned header_length = 2 + 8 + 1 + 1 ;
219 const unsigned body_length = max_payload_size - header_length;
220 unsigned total_number_of_packets = (gelf_message_as_string.size() + body_length - 1) / body_length;
221 unsigned bytes_sent = 0;
222 unsigned number_of_packets_sent = 0;
223 while (bytes_sent < gelf_message_as_string.size())
224 {
225 unsigned bytes_to_send = std::min((unsigned)gelf_message_as_string.size() - bytes_sent,
226 body_length);
227
228 std::shared_ptr<char> send_buffer(new char[max_payload_size],
229 [](
char*
p){
delete[]
p; });
230 char*
ptr = send_buffer.get();
231
232 *(
unsigned char*)
ptr++ = 0x1e;
233 *(
unsigned char*)
ptr++ = 0x0f;
234
235
236 memcpy(
ptr, (
char*)&message_id,
sizeof(message_id));
237 ptr +=
sizeof(message_id);
238
239 *(
unsigned char*)(
ptr++) = number_of_packets_sent;
240 *(
unsigned char*)(
ptr++) = total_number_of_packets;
241 memcpy(
ptr, gelf_message_as_string.c_str() + bytes_sent,
242 bytes_to_send);
243 my->gelf_socket.send_to(send_buffer, header_length + bytes_to_send,
244 *my->gelf_endpoint);
245 ++number_of_packets_sent;
246 bytes_sent += bytes_to_send;
247 }
248 FC_ASSERT(number_of_packets_sent == total_number_of_packets);
249 }
250 }
std::shared_ptr< appender > ptr
static constexpr fc::microseconds format_time_limit
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
constexpr int64_t count() const
constexpr const microseconds & time_since_epoch() const
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
fc::string to_string(double)
string zlib_compress(const string &in)
uint64_t city_hash64(const char *buf, size_t len)
fc::string format_string(const fc::string &, const variant_object &, bool minimize=false)
unsigned __int64 uint64_t
memcpy((char *) pInfo->slotDescription, s, l)