Skip to content

Commit 646b18b

Browse files
committed
core logger support multiple level + switch ixbots to user corelogger instead of spdlog
1 parent 0670954 commit 646b18b

13 files changed

+206
-84
lines changed

ixbots/CMakeLists.txt

-5
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ if (NOT JSONCPP_FOUND)
3131
set(JSONCPP_INCLUDE_DIRS ../third_party/jsoncpp)
3232
endif()
3333

34-
find_package(SpdLog)
35-
if (NOT SPDLOG_FOUND)
36-
set(SPDLOG_INCLUDE_DIRS ../third_party/spdlog/include)
37-
endif()
38-
3934
set(IXBOTS_INCLUDE_DIRS
4035
.
4136
..

ixbots/ixbots/IXCobraBot.cpp

+43-36
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
#include "IXCobraBot.h"
88

99
#include "IXQueueManager.h"
10+
#include <ixcobra/IXCobraConnection.h>
11+
#include <ixcore/utils/IXCoreLogger.h>
12+
1013
#include <algorithm>
1114
#include <chrono>
12-
#include <ixcobra/IXCobraConnection.h>
13-
#include <spdlog/spdlog.h>
1415
#include <sstream>
1516
#include <thread>
1617
#include <vector>
@@ -34,10 +35,10 @@ namespace ix
3435
Json::FastWriter jsonWriter;
3536
std::atomic<uint64_t> sentCount(0);
3637
std::atomic<uint64_t> receivedCount(0);
37-
std::atomic<uint64_t> sentCountTotal(0);
38-
std::atomic<uint64_t> receivedCountTotal(0);
39-
std::atomic<uint64_t> sentCountPerSecs(0);
40-
std::atomic<uint64_t> receivedCountPerSecs(0);
38+
uint64_t sentCountTotal(0);
39+
uint64_t receivedCountTotal(0);
40+
uint64_t sentCountPerSecs(0);
41+
uint64_t receivedCountPerSecs(0);
4142
std::atomic<bool> stop(false);
4243
std::atomic<bool> throttled(false);
4344
std::atomic<bool> fatalCobraError(false);
@@ -58,11 +59,17 @@ namespace ix
5859
// as those are used externally, so we need to introduce
5960
// our own counters
6061
//
61-
spdlog::info("messages received {} {} sent {} {}",
62-
receivedCountPerSecs,
63-
receivedCountTotal,
64-
sentCountPerSecs,
65-
sentCountTotal);
62+
std::stringstream ss;
63+
ss << "messages received "
64+
<< receivedCountPerSecs
65+
<< " "
66+
<< receivedCountTotal
67+
<< " sent "
68+
<< sentCountPerSecs
69+
<< " "
70+
<< sentCountTotal;
71+
CoreLogger::info(ss.str());
72+
6673
receivedCountPerSecs = receivedCount - receivedCountTotal;
6774
sentCountPerSecs = sentCount - receivedCountTotal;
6875

@@ -73,7 +80,7 @@ namespace ix
7380
std::this_thread::sleep_for(duration);
7481
}
7582

76-
spdlog::info("timer thread done");
83+
CoreLogger::info("timer thread done");
7784
};
7885

7986
std::thread t1(timer);
@@ -93,7 +100,7 @@ namespace ix
93100

94101
if (currentState == state)
95102
{
96-
spdlog::error("no messages received or sent for 1 minute, exiting");
103+
CoreLogger::error("no messages received or sent for 1 minute, exiting");
97104
exit(1);
98105
}
99106
state = currentState;
@@ -102,7 +109,7 @@ namespace ix
102109
std::this_thread::sleep_for(duration);
103110
}
104111

105-
spdlog::info("heartbeat thread done");
112+
CoreLogger::info("heartbeat thread done");
106113
};
107114

108115
std::thread t2(heartbeat);
@@ -124,19 +131,19 @@ namespace ix
124131
// That might be too noisy
125132
if (verbose)
126133
{
127-
spdlog::info("cobra bot: sending succesfull");
134+
CoreLogger::info("cobra bot: sending succesfull");
128135
}
129136
++sentCount;
130137
}
131138
else
132139
{
133-
spdlog::error("cobra bot: error sending");
140+
CoreLogger::error("cobra bot: error sending");
134141
}
135142

136143
if (stop) break;
137144
}
138145

139-
spdlog::info("sender thread done");
146+
CoreLogger::info("sender thread done");
140147
};
141148

142149
std::thread t3(sender);
@@ -158,22 +165,23 @@ namespace ix
158165
&sentCount](const CobraEventPtr& event) {
159166
if (event->type == ix::CobraEventType::Open)
160167
{
161-
spdlog::info("Subscriber connected");
168+
CoreLogger::info("Subscriber connected");
162169

163170
for (auto&& it : event->headers)
164171
{
165-
spdlog::info("{}: {}", it.first, it.second);
172+
CoreLogger::info(it.first + "::" + it.second);
166173
}
167174
}
168175
else if (event->type == ix::CobraEventType::Closed)
169176
{
170-
spdlog::info("Subscriber closed: {}", event->errMsg);
177+
CoreLogger::info("Subscriber closed: {}" + event->errMsg);
171178
}
172179
else if (event->type == ix::CobraEventType::Authenticated)
173180
{
174-
spdlog::info("Subscriber authenticated");
175-
spdlog::info("Subscribing to {} at position {}", channel, subscriptionPosition);
176-
spdlog::info("Using filter: {}", filter);
181+
CoreLogger::info("Subscriber authenticated");
182+
CoreLogger::info("Subscribing to " + channel);
183+
CoreLogger::info("Subscribing at position " + subscriptionPosition);
184+
CoreLogger::info("Subscribing with filter " + filter);
177185
conn.subscribe(channel,
178186
filter,
179187
subscriptionPosition,
@@ -189,9 +197,8 @@ namespace ix
189197
&sentCount](const Json::Value& msg, const std::string& position) {
190198
if (verbose)
191199
{
192-
spdlog::info("Subscriber received message {} -> {}",
193-
position,
194-
jsonWriter.write(msg));
200+
CoreLogger::info("Subscriber received message "
201+
+ position + " -> " + jsonWriter.write(msg));
195202
}
196203

197204
subscriptionPosition = position;
@@ -217,50 +224,50 @@ namespace ix
217224
// That might be too noisy
218225
if (verbose)
219226
{
220-
spdlog::info("cobra bot: sending succesfull");
227+
CoreLogger::info("cobra bot: sending succesfull");
221228
}
222229
++sentCount;
223230
}
224231
else
225232
{
226-
spdlog::error("cobra bot: error sending");
233+
CoreLogger::error("cobra bot: error sending");
227234
}
228235
}
229236
});
230237
}
231238
else if (event->type == ix::CobraEventType::Subscribed)
232239
{
233-
spdlog::info("Subscriber: subscribed to channel {}", event->subscriptionId);
240+
CoreLogger::info("Subscriber: subscribed to channel " + event->subscriptionId);
234241
}
235242
else if (event->type == ix::CobraEventType::UnSubscribed)
236243
{
237-
spdlog::info("Subscriber: unsubscribed from channel {}", event->subscriptionId);
244+
CoreLogger::info("Subscriber: unsubscribed from channel " + event->subscriptionId);
238245
}
239246
else if (event->type == ix::CobraEventType::Error)
240247
{
241-
spdlog::error("Subscriber: error {}", event->errMsg);
248+
CoreLogger::error("Subscriber: error " + event->errMsg);
242249
}
243250
else if (event->type == ix::CobraEventType::Published)
244251
{
245-
spdlog::error("Published message hacked: {}", event->msgId);
252+
CoreLogger::error("Published message hacked: " + std::to_string(event->msgId));
246253
}
247254
else if (event->type == ix::CobraEventType::Pong)
248255
{
249-
spdlog::info("Received websocket pong: {}", event->errMsg);
256+
CoreLogger::info("Received websocket pong: " + event->errMsg);
250257
}
251258
else if (event->type == ix::CobraEventType::HandshakeError)
252259
{
253-
spdlog::error("Subscriber: Handshake error: {}", event->errMsg);
260+
CoreLogger::error("Subscriber: Handshake error: " + event->errMsg);
254261
fatalCobraError = true;
255262
}
256263
else if (event->type == ix::CobraEventType::AuthenticationError)
257264
{
258-
spdlog::error("Subscriber: Authentication error: {}", event->errMsg);
265+
CoreLogger::error("Subscriber: Authentication error: " + event->errMsg);
259266
fatalCobraError = true;
260267
}
261268
else if (event->type == ix::CobraEventType::SubscriptionError)
262269
{
263-
spdlog::error("Subscriber: Subscription error: {}", event->errMsg);
270+
CoreLogger::error("Subscriber: Subscription error: " + event->errMsg);
264271
fatalCobraError = true;
265272
}
266273
});

ixbots/ixbots/IXCobraToSentryBot.cpp

+17-18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88

99
#include "IXCobraBot.h"
1010
#include "IXQueueManager.h"
11-
#include <chrono>
1211
#include <ixcobra/IXCobraConnection.h>
13-
#include <spdlog/spdlog.h>
12+
#include <ixcore/utils/IXCoreLogger.h>
13+
14+
#include <chrono>
1415
#include <sstream>
1516
#include <vector>
1617

@@ -38,39 +39,39 @@ namespace ix
3839

3940
if (!response)
4041
{
41-
spdlog::warn("Null HTTP Response");
42+
CoreLogger::warn("Null HTTP Response");
4243
return false;
4344
}
4445

4546
if (verbose)
4647
{
4748
for (auto it : response->headers)
4849
{
49-
spdlog::info("{}: {}", it.first, it.second);
50+
CoreLogger::info(it.first + ": " + it.second);
5051
}
5152

52-
spdlog::info("Upload size: {}", response->uploadSize);
53-
spdlog::info("Download size: {}", response->downloadSize);
53+
CoreLogger::info("Upload size: " + std::to_string(response->uploadSize));
54+
CoreLogger::info("Download size: " + std::to_string(response->downloadSize));
5455

55-
spdlog::info("Status: {}", response->statusCode);
56+
CoreLogger::info("Status: " + std::to_string(response->statusCode));
5657
if (response->errorCode != HttpErrorCode::Ok)
5758
{
58-
spdlog::info("error message: {}", response->errorMsg);
59+
CoreLogger::info("error message: " + response->errorMsg);
5960
}
6061

6162
if (response->headers["Content-Type"] != "application/octet-stream")
6263
{
63-
spdlog::info("payload: {}", response->payload);
64+
CoreLogger::info("payload: " + response->payload);
6465
}
6566
}
6667

6768
bool success = response->statusCode == 200;
6869

6970
if (!success)
7071
{
71-
spdlog::error("Error sending data to sentry: {}", response->statusCode);
72-
spdlog::error("Body: {}", ret.second);
73-
spdlog::error("Response: {}", response->payload);
72+
CoreLogger::error("Error sending data to sentry: " + std::to_string(response->statusCode));
73+
CoreLogger::error("Body: " + ret.second);
74+
CoreLogger::error("Response: " + response->payload);
7475

7576
// Error 429 Too Many Requests
7677
if (response->statusCode == 429)
@@ -84,14 +85,12 @@ namespace ix
8485
if (!ss.eof() || ss.fail())
8586
{
8687
seconds = 30;
87-
spdlog::warn("Error parsing Retry-After header. "
88-
"Using {} for the sleep duration",
89-
seconds);
88+
CoreLogger::warn("Error parsing Retry-After header. "
89+
"Using " + retryAfter + " for the sleep duration");
9090
}
9191

92-
spdlog::warn("Error 429 - Too Many Requests. ws will sleep "
93-
"and retry after {} seconds",
94-
retryAfter);
92+
CoreLogger::warn("Error 429 - Too Many Requests. ws will sleep "
93+
"and retry after " + retryAfter + " seconds");
9594

9695
throttled = true;
9796
auto duration = std::chrono::seconds(seconds);

ixbots/ixbots/IXCobraToStatsdBot.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "IXStatsdClient.h"
1212
#include <chrono>
1313
#include <ixcobra/IXCobraConnection.h>
14-
#include <spdlog/spdlog.h>
14+
#include <ixcore/utils/IXCoreLogger.h>
1515
#include <sstream>
1616
#include <vector>
1717

@@ -120,14 +120,14 @@ namespace ix
120120
}
121121
else
122122
{
123-
spdlog::error("Gauge {} is not a numeric type", gauge);
123+
CoreLogger::error("Gauge " + gauge + " is not a numeric type");
124124
fatalCobraError = true;
125125
return false;
126126
}
127127

128128
if (verbose)
129129
{
130-
spdlog::info("{} - {} -> {}", id, attrName, x);
130+
CoreLogger::info(id + " - " + attrName + " -> " + std::to_string(x));
131131
}
132132

133133
if (!gauge.empty())

ixbots/ixbots/IXCobraToStdoutBot.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "IXQueueManager.h"
1111
#include <chrono>
1212
#include <iostream>
13-
#include <spdlog/spdlog.h>
1413
#include <sstream>
1514

1615
namespace ix

ixcobra/ixcobra/IXCobraMetricsThreadedPublisher.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace ix
7575
ss << "Subscription error: " << event->errMsg;
7676
}
7777

78-
ix::IXCoreLogger::Log(ss.str().c_str());
78+
CoreLogger::log(ss.str().c_str());
7979
});
8080
}
8181

@@ -100,7 +100,7 @@ namespace ix
100100
void CobraMetricsThreadedPublisher::configure(const CobraConfig& config,
101101
const std::string& channel)
102102
{
103-
ix::IXCoreLogger::Log(config.socketTLSOptions.getDescription().c_str());
103+
CoreLogger::log(config.socketTLSOptions.getDescription().c_str());
104104

105105
_channel = channel;
106106
_cobra_connection.configure(config);

0 commit comments

Comments
 (0)