Matt-Esch commented on code in PR #200: URL: https://github.com/apache/pulsar-client-node/pull/200#discussion_r841559559
########## src/Client.cc: ########## @@ -40,14 +41,43 @@ static const std::string CFG_TLS_ALLOW_INSECURE = "tlsAllowInsecureConnection"; static const std::string CFG_STATS_INTERVAL = "statsIntervalInSeconds"; static const std::string CFG_LOG = "log"; +LogCallback *Client::logCallback = nullptr; + +void Client::SetLogHandler(const Napi::CallbackInfo &info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + Napi::Value jsFunction = info[0]; + + if (jsFunction.IsNull()) { + if (Client::logCallback != nullptr) { + Client::logCallback->callback.Release(); + delete Client::logCallback; + Client::logCallback = nullptr; + } + } else if (jsFunction.IsFunction()) { + Napi::ThreadSafeFunction logFunction = + Napi::ThreadSafeFunction::New(env, jsFunction.As<Napi::Function>(), "Pulsar Logging", 0, 1); + logFunction.Unref(env); Review Comment: I found that setting the global log function without unrefing it keeps the process alive. This is to allow the process to exit cleanly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org