1717* limitations under the License.
1818**/
1919#include < JSRuntimeClient.h>
20+ #include < NativeJSLogger.h>
2021#include " jsc_lib.h"
2122#include < iostream>
2223#include < sstream>
@@ -58,7 +59,7 @@ bool JSRuntimeClient::run()
5859 WsClient::connection_ptr con = mEndPoint .get_connection (uri, ec);
5960 if (ec)
6061 {
61- std::cout << " Could not create connection because: " << ec.message () << std::endl ;
62+ NativeJSLogger::log (ERROR, " Could not create connection because: %s \n " , ec.message (). c_str ()) ;
6263 return false ;
6364 }
6465
@@ -75,12 +76,11 @@ bool JSRuntimeClient::run()
7576
7677bool JSRuntimeClient::send (const std::string &message)
7778{
78- std::cout << " Enter: " << __func__ << " : " << message << std::endl;
79-
79+ NativeJSLogger::log (INFO, " Enter: %s : %s\n " , __func__, message.c_str ());
8080 if (message.empty ())
8181 {
82- std::cout << " Can't send empty message\n " ;
83- return false ;
82+ NativeJSLogger::log (WARN, " Can't send empty message\n " ) ;
83+ return false ;
8484 }
8585
8686 try
@@ -89,15 +89,15 @@ bool JSRuntimeClient::send(const std::string &message)
8989 }
9090 catch (websocketpp::exception const &e)
9191 {
92- std::cout << " Send failure: " << e.what () << std::endl ;
92+ NativeJSLogger::log (ERROR, " Send failure: %s \n " , e.what ()) ;
9393 }
9494
9595 return true ;
9696}
9797
9898bool JSRuntimeClient::close ()
9999{
100- std::cout << " Enter: " << __func__ << std::endl ;
100+ NativeJSLogger::log (INFO, " Enter: %s \n " , __func__) ;
101101
102102 websocketpp::lib::error_code ec;
103103 mEndPoint .close (mConnectionHdl , websocketpp::close::status::going_away, " " , ec);
@@ -120,26 +120,26 @@ void JSRuntimeClient::setState(const std::string &state)
120120void JSRuntimeClient::onMessage (websocketpp::connection_hdl hdl, message_ptr msg)
121121{
122122 std::string msgstr = msg->get_payload ();
123- std::cout << " Enter: " << __func__ << " : " << msgstr << std::endl ;
123+ NativeJSLogger::log (INFO, " Enter: %s : %s \n " , __func__, msgstr. c_str ()) ;
124124
125125 CommandInterface<JSRuntimeClient>::onMessage (msgstr);
126126}
127127
128128void JSRuntimeClient::onOpen (websocketpp::connection_hdl hdl)
129129{
130- std::cout << " Enter: " << __func__ << std::endl ;
130+ NativeJSLogger::log (INFO, " Enter: %s \n " , __func__) ;
131131 setState (" open" );
132132}
133133
134134void JSRuntimeClient::onFail (websocketpp::connection_hdl hdl)
135135{
136- std::cout << " Enter: " << __func__ << std::endl ;
136+ NativeJSLogger::log (INFO, " Enter: %s \n " , __func__) ;
137137 setState (" fail" );
138138}
139139
140140void JSRuntimeClient::onClose (websocketpp::connection_hdl hdl)
141141{
142- std::cout << " Enter: " << __func__ << std::endl ;
142+ NativeJSLogger::log (INFO, " Enter: %s \n " , __func__) ;
143143 setState (" close" );
144144}
145145
@@ -150,15 +150,15 @@ int main(int argc, char **argv)
150150
151151 if (argc > 1 )
152152 {
153- std::cout << " Send input commands at ws://localhost:" << std::to_string (WS_SERVER_PORT) << std::endl ;
153+ NativeJSLogger::log (INFO, " Send input commands at ws://localhost:%s \n " , std::to_string (WS_SERVER_PORT). c_str ()) ;
154154 return -1 ;
155155 }
156156
157157 JSRuntimeClient *client = JSRuntimeClient::getInstance ();
158158 client->initialize (WS_SERVER_PORT);
159159 if (!client->run ())
160160 {
161- std::cout << " Unable to connect server" << std::endl ;
161+ NativeJSLogger::log (ERROR, " Unable to connect to server\n " ) ;
162162 return -1 ;
163163 }
164164
@@ -167,11 +167,11 @@ int main(int argc, char **argv)
167167 client->sendCommand (command, response);
168168 if (!response.empty ())
169169 {
170- std::cout << " Response: " << response << std::endl ;
170+ NativeJSLogger::log (INFO, " Response: %s \n " , response. c_str ()) ;
171171 }
172172 else
173173 {
174- std::cout << " Missing response" << std::endl ;
174+ NativeJSLogger::log (WARN, " Missing response\n " ) ;
175175 break ;
176176 }
177177 }
0 commit comments