@@ -182,6 +182,7 @@ void Countly::setDeviceID(const std::string& value, bool same_user) {
182182
183183void Countly::start (const std::string& app_key, const std::string& host, int port, bool start_thread) {
184184 mutex.lock ();
185+ log (Countly::LogLevel::INFO, " [Countly][start]" );
185186 this ->host = host;
186187 if (host.find (" http://" ) == 0 ) {
187188 use_https = false ;
@@ -219,7 +220,12 @@ void Countly::start(const std::string& app_key, const std::string& host, int por
219220 mutex.unlock ();
220221}
221222
223+
224+ /* *
225+ * startOnCloud is deprecated and this is going to be removed in the future.
226+ */
222227void Countly::startOnCloud (const std::string& app_key) {
228+ log (Countly::LogLevel::WARNING, " [Countly][startOnCloud] 'startOnCloud' is deprecated, this is going to be removed in the future." );
223229 this ->start (app_key, " https://cloud.count.ly" , 443 );
224230}
225231
@@ -369,6 +375,7 @@ void Countly::flushEvents(std::chrono::seconds timeout) {
369375
370376bool Countly::beginSession () {
371377 mutex.lock ();
378+ log (Countly::LogLevel::INFO, " [Countly][beginSession]" );
372379 if (began_session) {
373380 mutex.unlock ();
374381 return true ;
@@ -408,6 +415,8 @@ bool Countly::beginSession() {
408415}
409416
410417bool Countly::updateSession () {
418+ log (Countly::LogLevel::INFO, " [Countly][updateSession]" );
419+
411420 mutex.lock ();
412421 if (!began_session) {
413422 mutex.unlock ();
@@ -486,6 +495,7 @@ bool Countly::updateSession() {
486495 mutex.unlock ();
487496 return false ;
488497 }
498+
489499 last_sent += duration;
490500 }
491501
@@ -505,7 +515,7 @@ bool Countly::updateSession() {
505515 return false ;
506516 }
507517
508- last_sent = Countly::getTimestamp () ;
518+ last_sent += duration ;
509519
510520#ifndef COUNTLY_USE_SQLITE
511521 event_queue.clear ();
@@ -530,6 +540,7 @@ bool Countly::updateSession() {
530540}
531541
532542bool Countly::endSession () {
543+ log (Countly::LogLevel::INFO, " [Countly][endSession]" );
533544 const std::chrono::system_clock::time_point now = Countly::getTimestamp ();
534545 const auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch ());
535546 const auto duration = std::chrono::duration_cast<std::chrono::seconds>(getSessionDuration (now));
@@ -626,6 +637,7 @@ static size_t countly_curl_write_callback(void *data, size_t byte_size, size_t n
626637Countly::HTTPResponse Countly::sendHTTP (std::string path, std::string data) {
627638 bool use_post = always_use_post || (data.size () > COUNTLY_POST_THRESHOLD);
628639
640+ log (Countly::LogLevel::DEBUG, " [Countly][sendHTTP] data: " + data);
629641 if (!salt.empty ()) {
630642 unsigned char checksum[SHA256_DIGEST_LENGTH];
631643 std::string salted_data = data + salt;
@@ -762,6 +774,8 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {
762774 curl_easy_setopt (curl, CURLOPT_POSTFIELDS, data.c_str ());
763775 }
764776
777+ log (Countly::LogLevel::DEBUG, " [Countly][sendHTTP] request: " + full_url_stream.str ());
778+
765779 std::string full_url = full_url_stream.str ();
766780 curl_easy_setopt (curl, CURLOPT_URL, full_url.c_str ());
767781
@@ -771,24 +785,26 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {
771785
772786 curl_code = curl_easy_perform (curl);
773787 if (curl_code == CURLE_OK) {
788+
774789 long status_code;
775790 curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status_code);
776791 response.success = (status_code >= 200 && status_code < 300 );
777792 if (!body.empty ()) {
778793 response.data = json::parse (body);
779794 }
780795 }
781-
782796 curl_easy_cleanup (curl);
783797 }
784798#endif
799+ log (Countly::LogLevel::DEBUG, " [Countly][sendHTTP] response: " + response.data .dump ());
785800 return response;
786801#endif
802+
787803}
788804
789805std::chrono::system_clock::duration Countly::getSessionDuration (std::chrono::system_clock::time_point now) {
790806 mutex.lock ();
791- std::chrono::system_clock::duration duration = last_sent - now ;
807+ std::chrono::system_clock::duration duration = now - last_sent ;
792808 mutex.unlock ();
793809 return duration;
794810}
@@ -798,6 +814,7 @@ std::chrono::system_clock::duration Countly::getSessionDuration() {
798814}
799815
800816void Countly::updateLoop () {
817+ log (Countly::LogLevel::DEBUG, " [Countly][updateLoop]" );
801818 mutex.lock ();
802819 running = true ;
803820 mutex.unlock ();
0 commit comments