@@ -62,7 +62,7 @@ static size_t HeaderCallback(void *contents, size_t size, size_t nmemb, void *us
6262 mem->headerBuffer = (char *)realloc (mem->headerBuffer , mem->headerSize + downloadSize + 1 );
6363 if (mem->headerBuffer == NULL ) {
6464 /* out of memory! */
65- std::cout << " out of memory when downloading image\n " ;
65+ NativeJSLogger::log (WARN, " Out of memory when downloading image\n " ) ;
6666 return 0 ;
6767 }
6868
@@ -81,7 +81,7 @@ static size_t WriteMemoryCallback(void *contents, size_t size, size_t nmemb, voi
8181 mem->contentsBuffer = (char *)realloc (mem->contentsBuffer , mem->contentsSize + downloadSize + 1 );
8282 if (mem->contentsBuffer == NULL ) {
8383 /* out of memory! */
84- std::cout << " out of memory when downloading image\n " ;
84+ NativeJSLogger::log (WARN, " Out of memory when downloading image\n " ) ;
8585 return 0 ;
8686 }
8787
@@ -132,37 +132,37 @@ NativeJSRenderer::NativeJSRenderer(std::string waylandDisplay): mEngine(nullptr)
132132 if (embedThunderJS)
133133 {
134134 mEmbedThunderJS = true ;
135- std::cout << " thunderjs enabled via environment " << std::endl ;
135+ NativeJSLogger::log (INFO, " ThunderJS enabled via environment\n " ) ;
136136 }
137137 else
138138 {
139139 std::ifstream f (NATIVEJS_EMBED_THUNDERJS);
140140 if (f.good ())
141141 {
142142 mEmbedThunderJS = true ;
143- std::cout << " thunderjs enabled via file presence " << std::endl ;
143+ NativeJSLogger::log (INFO, " ThunderJS enabled via file presence\n " ) ;
144144 }
145145 }
146146
147147 std::ifstream f (NATIVEJS_EMBED_WEBBRIDGE);
148148 if (f.good ())
149149 {
150150 mEmbedRdkWebBridge = true ;
151- std::cout << " rdk webbridge enabled via file presence " << std::endl ;
151+ NativeJSLogger::log (INFO, " rdk WebBridge enabled via file presence\n " ) ;
152152 }
153153 char * enableWebSocketServer = getenv (" NATIVEJS_ENABLE_WEBSOCKET_SERVER" );
154154 if (enableWebSocketServer)
155155 {
156156 mEnableWebSocketServer = true ;
157- std::cout << " websocket server enabled via environment " << std::endl ;
157+ NativeJSLogger::log (INFO, " WebSocket server enabled via environment\n " ) ;
158158 }
159159 else
160160 {
161161 std::ifstream f (NATIVEJS_ENABLE_WEBSOCKET_SERVER);
162162 if (f.good ())
163163 {
164164 mEnableWebSocketServer = true ;
165- std::cout << " websocket server enabled via file presence " << std::endl ;
165+ NativeJSLogger::log (INFO, " WebSocket server enabled via file presence\n " ) ;
166166 }
167167 }
168168}
@@ -189,12 +189,12 @@ void NativeJSRenderer::setEnvForConsoleMode(ModuleSettings& moduleSettings)
189189 JavaScriptContext* context = new JavaScriptContext (features, " " , mEngine );
190190 if (!context)
191191 {
192- std::cout << " Context could not be initialized - exiting" << std::endl ;
193- return ;
192+ NativeJSLogger::log (ERROR, " Context could not be initialized - exiting\n " ) ;
193+ return ;
194194 }
195195 mConsoleState ->consoleContext = context;
196196
197- std::cout << " Running developer console..." << std::endl ;
197+ NativeJSLogger::log (INFO, " Running developer console...\n " ) ;
198198 std::thread consoleThread (&JsRuntime::NativeJSRenderer::runDeveloperConsole, this , std::ref (mConsoleState ->moduleSettings ));
199199 consoleThread.detach ();
200200
@@ -244,7 +244,7 @@ std::list<ApplicationDetails> NativeJSRenderer::getApplications()
244244 std::list<ApplicationDetails> runningApplication;
245245 if (mContextMap .empty ())
246246 {
247- std::cout<< " No application found.. " <<std::endl ;
247+ NativeJSLogger::log (WARN, " No application found..\n " ) ;
248248 }
249249 else {
250250 for (const auto & [key, value] : mContextMap )
@@ -308,7 +308,7 @@ void NativeJSRenderer::runApplicationInternal(ApplicationRequest& appRequest)
308308
309309 if (!url.empty ())
310310 {
311- std::cout<< " Before launching app" <<std::endl ;
311+ NativeJSLogger::log (INFO, " Before launching app\n " ) ;
312312 std::string urlPattern = url.substr (0 , 4 );
313313 if (urlPattern.compare (0 , 4 , " http" ) == 0 )
314314 {
@@ -319,21 +319,21 @@ void NativeJSRenderer::runApplicationInternal(ApplicationRequest& appRequest)
319319 return ;
320320 }
321321 IJavaScriptContext* context = mContextMap [id].context ;
322- std::cout << " nativeJS application thunder execution url " << url << " result " << ret << std::endl ;
322+ NativeJSLogger::log (INFO, " nativeJS application thunder execution url: %s, result: %d \n " , url, ret ? 1 : 0 ) ;
323323 ret = context->runScript (chunk.contentsBuffer , true , url, nullptr , true );
324- std::cout << " nativeJS application execution result " << ret << std::endl;
324+ NativeJSLogger::log (INFO, " nativeJS application execution result: %d \n " , ret ? 1 : 0 );
325325 }
326326 else
327327 {
328- std::cout << " about to launch local app " <<std::endl ;
328+ NativeJSLogger::log (INFO, " About to launch local app\n " ) ;
329329 IJavaScriptContext* context = mContextMap [id].context ;
330- std::cout << " running test application " << url << std::endl ;
330+ NativeJSLogger::log (INFO, " Running test application: %s \n " , url) ;
331331 bool ret = context->runFile (url.c_str (), nullptr , true );
332- std::cout << " test application execution result " << ret << std::endl ;
332+ NativeJSLogger::log (INFO, " Test application execution result: %d \n " , ret ? 1 : 0 ) ;
333333 }
334334 }
335335 else {
336- std::cout << " nativeJS application url not proper" << std::endl ;
336+ NativeJSLogger::log (WARN, " nativeJS application url not proper\n " ) ;
337337 return ;
338338 }
339339}
@@ -351,13 +351,13 @@ void NativeJSRenderer::runJavaScriptInternal(ApplicationRequest& appRequest)
351351 mContextMap [id].url = code;
352352 if (!code.empty ())
353353 {
354- std::cout<< " Running the JavaScript code " <<std::endl ;
354+ NativeJSLogger::log (INFO, " Running the JavaScript code\n " ) ;
355355 IJavaScriptContext* context = mContextMap [id].context ;
356356 std::string rawcode = code ;
357357 bool ret = context-> runScript (rawcode.c_str (),true ," JavaScriptCode" ,nullptr ,true );
358358 }
359359 else {
360- std::cout<< " Empty/ Invalid JavaScript Code" <<std::endl ;
360+ NativeJSLogger::log (ERROR, " Empty or Invalid JavaScript Code\n " ) ;
361361 }
362362}
363363
@@ -368,18 +368,18 @@ void NativeJSRenderer::terminateApplicationInternal(ApplicationRequest& AppReque
368368 if (mapEntry != mContextMap .end ())
369369 {
370370 JavaScriptContext* context = (JavaScriptContext*)mContextMap [id].context ;
371- std::cout<< " terminating the application with id " <<id<<std::endl ;
371+ NativeJSLogger::log (INFO, " Terminating the application with id: %d \n " , id) ;
372372 if (NULL != context) {
373- std::cout << " deleted context " <<std::endl ;
373+ NativeJSLogger::log (INFO, " Deleted context\n " ) ;
374374 delete context;
375375 }
376376 mContextMap .erase (mapEntry);
377- std::cout<< " Application is terminated" <<std::endl ;
377+ NativeJSLogger::log (INFO, " Application is terminated\n " ) ;
378378 }
379379
380380 else
381381 {
382- std::cout << " unable to find application" << id << " with url: " << mContextMap [id].url << std::endl ;
382+ NativeJSLogger::log (ERROR, " Unable to find application with id: %d and url: %s \n " , id, mContextMap [id].url ) ;
383383 return ;
384384 }
385385
@@ -430,7 +430,7 @@ void NativeJSRenderer::run()
430430 }
431431 else
432432 {
433- std::cerr<< " Invalid Request Type" <<std::endl ;
433+ NativeJSLogger::log (ERROR, " Invalid Request Type\n " ) ;
434434 }
435435
436436 }
@@ -499,8 +499,8 @@ void NativeJSRenderer::runDeveloperConsole(ModuleSettings moduleSettings)
499499{
500500 std::string input;
501501
502- std::cout << " \n JSRuntime Developer Console\n " ;
503- std::cout << " Type 'exit' or press CTRL+C and ENTER to quit.\n\n " ;
502+ NativeJSLogger::log (INFO, " \n JSRuntime Developer Console\n " ) ;
503+ NativeJSLogger::log (INFO, " Type 'exit' or press CTRL+C and ENTER to quit.\n " ) ;
504504
505505 signal (SIGINT, handleDevConsoleSigInt);
506506 while (consoleLoop) {
@@ -557,17 +557,17 @@ bool NativeJSRenderer::downloadFile(std::string& url, MemoryStruct& chunk)
557557 curl_easy_cleanup (curl);
558558 if ((res == 0 ) && (httpCode == 200 ))
559559 {
560- std::cout << " download operation success" << std::endl ;
561- ret = true ;
560+ NativeJSLogger::log (INFO, " Download operation success\n " ) ;
561+ ret = true ;
562562 }
563563 else
564564 {
565- std::cout << " download operation failed" << std::endl ;
565+ NativeJSLogger::log (ERROR, " Download operation failed\n " ) ;
566566 }
567567 }
568568 else
569569 {
570- std::cout << " unable to perform download " << std::endl ;
570+ NativeJSLogger::log (ERROR, " Unable to perform download\n " ) ;
571571 }
572572 return ret;
573573}
0 commit comments