@@ -31,6 +31,8 @@ using json = nlohmann::json;
3131#endif
3232
3333Countly::Countly () {
34+ logger.reset (new cly::LoggerModule ());
35+
3436#if !defined(_WIN32) && !defined(COUNTLY_USE_CUSTOM_HTTP)
3537 curl_global_init (CURL_GLOBAL_ALL);
3638#endif
@@ -39,6 +41,8 @@ Countly::Countly() {
3941Countly::~Countly () {
4042 is_being_disposed = true ;
4143 stop ();
44+ logger.reset ();
45+
4246#if !defined(_WIN32) && !defined(COUNTLY_USE_CUSTOM_HTTP)
4347 curl_global_cleanup ();
4448#endif
@@ -61,9 +65,21 @@ void Countly::setSalt(const std::string& value) {
6165 mutex.unlock ();
6266}
6367
64- void Countly::setLogger (LoggerFunction fun) {
68+ void temp_log (cly::LogLevel level, const std::string& msg) {
69+ Countly::getInstance ().getLogger ()(Countly::LogLevel (level), msg);
70+ }
71+
72+ void Countly::setLogger (void (*fun)(Countly::LogLevel level, const std::string& message)) {
6573 mutex.lock ();
74+
6675 logger_function = fun;
76+ if (fun == nullptr ) {
77+ logger->setLogger (nullptr );
78+ }
79+ else {
80+ logger->setLogger (temp_log);
81+ }
82+
6783 mutex.unlock ();
6884}
6985
@@ -73,7 +89,7 @@ void Countly::setHTTPClient(HTTPClientFunction fun) {
7389 mutex.unlock ();
7490}
7591
76- void Countly::setSha256 (SHA256Function fun) {
92+ void Countly::setSha256 (cly:: SHA256Function fun) {
7793 mutex.lock ();
7894 sha256_function = fun;
7995 mutex.unlock ();
@@ -788,10 +804,8 @@ void Countly::setDatabasePath(const std::string& path) {
788804}
789805#endif
790806
791- void Countly::log (Countly::LogLevel level, const std::string& message) {
792- if (logger_function) {
793- logger_function (level, message);
794- }
807+ void Countly::log (LogLevel level, const std::string& message) {
808+ logger->log (cly::LogLevel (level), message);
795809}
796810
797811static size_t countly_curl_write_callback (void *data, size_t byte_size, size_t n_bytes, std::string *body) {
@@ -804,7 +818,7 @@ std::string Countly::calculateChecksum(const std::string& salt, const std::strin
804818 std::string salted_data = data + salt;
805819#ifdef COUNTLY_USE_CUSTOM_SHA256
806820 if (sha256_function == nullptr ) {
807- log (Countly:: LogLevel::FATAL, " Missing SHA 256 function" );
821+ log (LogLevel::FATAL, " Missing SHA 256 function" );
808822 return {};
809823 }
810824
0 commit comments