7
7
#include " IXCobraBot.h"
8
8
9
9
#include " IXQueueManager.h"
10
+ #include < ixcobra/IXCobraConnection.h>
11
+ #include < ixcore/utils/IXCoreLogger.h>
12
+
10
13
#include < algorithm>
11
14
#include < chrono>
12
- #include < ixcobra/IXCobraConnection.h>
13
- #include < spdlog/spdlog.h>
14
15
#include < sstream>
15
16
#include < thread>
16
17
#include < vector>
@@ -34,10 +35,10 @@ namespace ix
34
35
Json::FastWriter jsonWriter;
35
36
std::atomic<uint64_t > sentCount (0 );
36
37
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 );
41
42
std::atomic<bool > stop (false );
42
43
std::atomic<bool > throttled (false );
43
44
std::atomic<bool > fatalCobraError (false );
@@ -58,11 +59,17 @@ namespace ix
58
59
// as those are used externally, so we need to introduce
59
60
// our own counters
60
61
//
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
+
66
73
receivedCountPerSecs = receivedCount - receivedCountTotal;
67
74
sentCountPerSecs = sentCount - receivedCountTotal;
68
75
@@ -73,7 +80,7 @@ namespace ix
73
80
std::this_thread::sleep_for (duration);
74
81
}
75
82
76
- spdlog ::info (" timer thread done" );
83
+ CoreLogger ::info (" timer thread done" );
77
84
};
78
85
79
86
std::thread t1 (timer);
@@ -93,7 +100,7 @@ namespace ix
93
100
94
101
if (currentState == state)
95
102
{
96
- spdlog ::error (" no messages received or sent for 1 minute, exiting" );
103
+ CoreLogger ::error (" no messages received or sent for 1 minute, exiting" );
97
104
exit (1 );
98
105
}
99
106
state = currentState;
@@ -102,7 +109,7 @@ namespace ix
102
109
std::this_thread::sleep_for (duration);
103
110
}
104
111
105
- spdlog ::info (" heartbeat thread done" );
112
+ CoreLogger ::info (" heartbeat thread done" );
106
113
};
107
114
108
115
std::thread t2 (heartbeat);
@@ -124,19 +131,19 @@ namespace ix
124
131
// That might be too noisy
125
132
if (verbose)
126
133
{
127
- spdlog ::info (" cobra bot: sending succesfull" );
134
+ CoreLogger ::info (" cobra bot: sending succesfull" );
128
135
}
129
136
++sentCount;
130
137
}
131
138
else
132
139
{
133
- spdlog ::error (" cobra bot: error sending" );
140
+ CoreLogger ::error (" cobra bot: error sending" );
134
141
}
135
142
136
143
if (stop) break ;
137
144
}
138
145
139
- spdlog ::info (" sender thread done" );
146
+ CoreLogger ::info (" sender thread done" );
140
147
};
141
148
142
149
std::thread t3 (sender);
@@ -158,22 +165,23 @@ namespace ix
158
165
&sentCount](const CobraEventPtr& event) {
159
166
if (event->type == ix::CobraEventType::Open)
160
167
{
161
- spdlog ::info (" Subscriber connected" );
168
+ CoreLogger ::info (" Subscriber connected" );
162
169
163
170
for (auto && it : event->headers )
164
171
{
165
- spdlog ::info (" {}: {} " , it. first , it.second );
172
+ CoreLogger ::info (it. first + " :: " + it.second );
166
173
}
167
174
}
168
175
else if (event->type == ix::CobraEventType::Closed)
169
176
{
170
- spdlog ::info (" Subscriber closed: {}" , event->errMsg );
177
+ CoreLogger ::info (" Subscriber closed: {}" + event->errMsg );
171
178
}
172
179
else if (event->type == ix::CobraEventType::Authenticated)
173
180
{
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);
177
185
conn.subscribe (channel,
178
186
filter,
179
187
subscriptionPosition,
@@ -189,9 +197,8 @@ namespace ix
189
197
&sentCount](const Json::Value& msg, const std::string& position) {
190
198
if (verbose)
191
199
{
192
- spdlog::info (" Subscriber received message {} -> {}" ,
193
- position,
194
- jsonWriter.write (msg));
200
+ CoreLogger::info (" Subscriber received message "
201
+ + position + " -> " + jsonWriter.write (msg));
195
202
}
196
203
197
204
subscriptionPosition = position;
@@ -217,50 +224,50 @@ namespace ix
217
224
// That might be too noisy
218
225
if (verbose)
219
226
{
220
- spdlog ::info (" cobra bot: sending succesfull" );
227
+ CoreLogger ::info (" cobra bot: sending succesfull" );
221
228
}
222
229
++sentCount;
223
230
}
224
231
else
225
232
{
226
- spdlog ::error (" cobra bot: error sending" );
233
+ CoreLogger ::error (" cobra bot: error sending" );
227
234
}
228
235
}
229
236
});
230
237
}
231
238
else if (event->type == ix::CobraEventType::Subscribed)
232
239
{
233
- spdlog ::info (" Subscriber: subscribed to channel {} " , event->subscriptionId );
240
+ CoreLogger ::info (" Subscriber: subscribed to channel " + event->subscriptionId );
234
241
}
235
242
else if (event->type == ix::CobraEventType::UnSubscribed)
236
243
{
237
- spdlog ::info (" Subscriber: unsubscribed from channel {} " , event->subscriptionId );
244
+ CoreLogger ::info (" Subscriber: unsubscribed from channel " + event->subscriptionId );
238
245
}
239
246
else if (event->type == ix::CobraEventType::Error)
240
247
{
241
- spdlog ::error (" Subscriber: error {} " , event->errMsg );
248
+ CoreLogger ::error (" Subscriber: error " + event->errMsg );
242
249
}
243
250
else if (event->type == ix::CobraEventType::Published)
244
251
{
245
- spdlog ::error (" Published message hacked: {} " , event->msgId );
252
+ CoreLogger ::error (" Published message hacked: " + std::to_string ( event->msgId ) );
246
253
}
247
254
else if (event->type == ix::CobraEventType::Pong)
248
255
{
249
- spdlog ::info (" Received websocket pong: {} " , event->errMsg );
256
+ CoreLogger ::info (" Received websocket pong: " + event->errMsg );
250
257
}
251
258
else if (event->type == ix::CobraEventType::HandshakeError)
252
259
{
253
- spdlog ::error (" Subscriber: Handshake error: {} " , event->errMsg );
260
+ CoreLogger ::error (" Subscriber: Handshake error: " + event->errMsg );
254
261
fatalCobraError = true ;
255
262
}
256
263
else if (event->type == ix::CobraEventType::AuthenticationError)
257
264
{
258
- spdlog ::error (" Subscriber: Authentication error: {} " , event->errMsg );
265
+ CoreLogger ::error (" Subscriber: Authentication error: " + event->errMsg );
259
266
fatalCobraError = true ;
260
267
}
261
268
else if (event->type == ix::CobraEventType::SubscriptionError)
262
269
{
263
- spdlog ::error (" Subscriber: Subscription error: {} " , event->errMsg );
270
+ CoreLogger ::error (" Subscriber: Subscription error: " + event->errMsg );
264
271
fatalCobraError = true ;
265
272
}
266
273
});
0 commit comments