@@ -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::DEBUG, " [Countly][start]" );
185186 this ->host = host;
186187 if (host.find (" http://" ) == 0 ) {
187188 use_https = false ;
@@ -369,6 +370,7 @@ void Countly::flushEvents(std::chrono::seconds timeout) {
369370
370371bool Countly::beginSession () {
371372 mutex.lock ();
373+ log (Countly::LogLevel::DEBUG, " [Countly] [beginSession]" );
372374 if (began_session) {
373375 mutex.unlock ();
374376 return true ;
@@ -408,6 +410,8 @@ bool Countly::beginSession() {
408410}
409411
410412bool Countly::updateSession () {
413+ log (Countly::LogLevel::DEBUG, " Countly::updateSession" );
414+
411415 mutex.lock ();
412416 if (!began_session) {
413417 mutex.unlock ();
@@ -486,7 +490,7 @@ bool Countly::updateSession() {
486490 mutex.unlock ();
487491 return false ;
488492 }
489- last_sent += duration ;
493+ last_sent = Countly::getTimestamp () ;
490494 }
491495
492496 mutex.unlock ();
@@ -530,6 +534,7 @@ bool Countly::updateSession() {
530534}
531535
532536bool Countly::endSession () {
537+ log (Countly::LogLevel::DEBUG, " [Countly] [endSession]" );
533538 const std::chrono::system_clock::time_point now = Countly::getTimestamp ();
534539 const auto timestamp = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch ());
535540 const auto duration = std::chrono::duration_cast<std::chrono::seconds>(getSessionDuration (now));
@@ -626,6 +631,7 @@ static size_t countly_curl_write_callback(void *data, size_t byte_size, size_t n
626631Countly::HTTPResponse Countly::sendHTTP (std::string path, std::string data) {
627632 bool use_post = always_use_post || (data.size () > COUNTLY_POST_THRESHOLD);
628633
634+ log (Countly::LogLevel::INFO, " [Countly] [sendHTTP] data: " + data);
629635 if (!salt.empty ()) {
630636 unsigned char checksum[SHA256_DIGEST_LENGTH];
631637 std::string salted_data = data + salt;
@@ -762,6 +768,8 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {
762768 curl_easy_setopt (curl, CURLOPT_POSTFIELDS, data.c_str ());
763769 }
764770
771+ log (Countly::LogLevel::INFO, " [Countly][sendHTTP] request: " + full_url_stream.str ());
772+
765773 std::string full_url = full_url_stream.str ();
766774 curl_easy_setopt (curl, CURLOPT_URL, full_url.c_str ());
767775
@@ -771,24 +779,26 @@ Countly::HTTPResponse Countly::sendHTTP(std::string path, std::string data) {
771779
772780 curl_code = curl_easy_perform (curl);
773781 if (curl_code == CURLE_OK) {
782+
774783 long status_code;
775784 curl_easy_getinfo (curl, CURLINFO_RESPONSE_CODE, &status_code);
776785 response.success = (status_code >= 200 && status_code < 300 );
777786 if (!body.empty ()) {
778787 response.data = json::parse (body);
779788 }
780789 }
781-
782790 curl_easy_cleanup (curl);
783791 }
784792#endif
793+ log (Countly::LogLevel::INFO, " [Countly][sendHTTP] response: " + response.data .dump ());
785794 return response;
786795#endif
796+
787797}
788798
789799std::chrono::system_clock::duration Countly::getSessionDuration (std::chrono::system_clock::time_point now) {
790800 mutex.lock ();
791- std::chrono::system_clock::duration duration = last_sent - now ;
801+ std::chrono::system_clock::duration duration = now - last_sent ;
792802 mutex.unlock ();
793803 return duration;
794804}
@@ -798,6 +808,7 @@ std::chrono::system_clock::duration Countly::getSessionDuration() {
798808}
799809
800810void Countly::updateLoop () {
811+ log (Countly::LogLevel::INFO, " [Countly][updateLoop]" );
801812 mutex.lock ();
802813 running = true ;
803814 mutex.unlock ();
0 commit comments