@@ -48,14 +48,14 @@ read_file (const char *file_name,
4848 FILE * file = fopen (file_name , "r" );
4949 if (file == NULL )
5050 {
51- jerry_port_errormsg ( "Error: failed to open file: %s\n" , file_name );
51+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: failed to open file: %s\n" , file_name );
5252 return NULL ;
5353 }
5454
5555 size_t bytes_read = fread (buffer , 1u , sizeof (buffer ), file );
5656 if (!bytes_read )
5757 {
58- jerry_port_errormsg ( "Error: failed to read file: %s\n" , file_name );
58+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: failed to read file: %s\n" , file_name );
5959 fclose (file );
6060 return NULL ;
6161 }
@@ -85,7 +85,7 @@ assert_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< f
8585 }
8686 else
8787 {
88- jerry_port_errormsg ( "Script error: assertion failed\n" );
88+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Script error: assertion failed\n" );
8989 exit (JERRY_STANDALONE_EXIT_CODE_FAIL );
9090 }
9191} /* assert_handler */
@@ -114,7 +114,6 @@ print_help (char *name)
114114 " --save-snapshot-for-eval FILE\n"
115115 " --exec-snapshot FILE\n"
116116 " --log-level [0-3]\n"
117- " --log-file FILE\n"
118117 " --abort-on-fail\n"
119118 "\n" ,
120119 name );
@@ -126,8 +125,10 @@ main (int argc,
126125{
127126 if (argc > JERRY_MAX_COMMAND_LINE_ARGS )
128127 {
129- jerry_port_errormsg ("Error: too many command line arguments: %d (JERRY_MAX_COMMAND_LINE_ARGS=%d)\n" ,
130- argc , JERRY_MAX_COMMAND_LINE_ARGS );
128+ jerry_port_log (JERRY_LOG_LEVEL_ERROR ,
129+ "Error: too many command line arguments: %d (JERRY_MAX_COMMAND_LINE_ARGS=%d)\n" ,
130+ argc ,
131+ JERRY_MAX_COMMAND_LINE_ARGS );
131132
132133 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
133134 }
@@ -154,9 +155,6 @@ main (int argc,
154155
155156 bool is_repl_mode = false;
156157
157- #ifdef JERRY_ENABLE_LOG
158- const char * log_file_name = NULL ;
159- #endif /* JERRY_ENABLE_LOG */
160158 for (i = 1 ; i < argc ; i ++ )
161159 {
162160 if (!strcmp ("-h" , argv [i ]) || !strcmp ("--help" , argv [i ]))
@@ -193,14 +191,14 @@ main (int argc,
193191
194192 if (save_snapshot_file_name_p != NULL )
195193 {
196- jerry_port_errormsg ( "Error: snapshot file name already specified\n" );
194+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: snapshot file name already specified\n" );
197195 print_usage (argv [0 ]);
198196 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
199197 }
200198
201199 if (++ i >= argc )
202200 {
203- jerry_port_errormsg ( "Error: no file specified for %s\n" , argv [i - 1 ]);
201+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: no file specified for %s\n" , argv [i - 1 ]);
204202 print_usage (argv [0 ]);
205203 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
206204 }
@@ -211,7 +209,7 @@ main (int argc,
211209 {
212210 if (++ i >= argc )
213211 {
214- jerry_port_errormsg ( "Error: no file specified for %s\n" , argv [i - 1 ]);
212+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: no file specified for %s\n" , argv [i - 1 ]);
215213 print_usage (argv [0 ]);
216214 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
217215 }
@@ -223,35 +221,21 @@ main (int argc,
223221 {
224222 if (++ i >= argc )
225223 {
226- jerry_port_errormsg ( "Error: no level specified for %s\n" , argv [i - 1 ]);
224+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: no level specified for %s\n" , argv [i - 1 ]);
227225 print_usage (argv [0 ]);
228226 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
229227 }
230228
231229 if (strlen (argv [i ]) != 1 || argv [i ][0 ] < '0' || argv [i ][0 ] > '3' )
232230 {
233- jerry_port_errormsg ( "Error: wrong format for %s\n" , argv [i - 1 ]);
231+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: wrong format for %s\n" , argv [i - 1 ]);
234232 print_usage (argv [0 ]);
235233 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
236234 }
237235
238236#ifdef JERRY_ENABLE_LOG
239237 flags |= JERRY_INIT_ENABLE_LOG ;
240238 jerry_debug_level = argv [i ][0 ] - '0' ;
241- #endif /* JERRY_ENABLE_LOG */
242- }
243- else if (!strcmp ("--log-file" , argv [i ]))
244- {
245- if (++ i >= argc )
246- {
247- jerry_port_errormsg ("Error: no file specified for %s\n" , argv [i - 1 ]);
248- print_usage (argv [0 ]);
249- return JERRY_STANDALONE_EXIT_CODE_FAIL ;
250- }
251-
252- #ifdef JERRY_ENABLE_LOG
253- flags |= JERRY_INIT_ENABLE_LOG ;
254- log_file_name = argv [i ];
255239#endif /* JERRY_ENABLE_LOG */
256240 }
257241 else if (!strcmp ("--abort-on-fail" , argv [i ]))
@@ -260,7 +244,7 @@ main (int argc,
260244 }
261245 else if (!strncmp ("-" , argv [i ], 1 ))
262246 {
263- jerry_port_errormsg ( "Error: unrecognized option: %s\n" , argv [i ]);
247+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Error: unrecognized option: %s\n" , argv [i ]);
264248 print_usage (argv [0 ]);
265249 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
266250 }
@@ -274,13 +258,15 @@ main (int argc,
274258 {
275259 if (files_counter != 1 )
276260 {
277- jerry_port_errormsg ("Error: --save-snapshot argument works with exactly one script\n" );
261+ jerry_port_log (JERRY_LOG_LEVEL_ERROR ,
262+ "Error: --save-snapshot argument works with exactly one script\n" );
278263 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
279264 }
280265
281266 if (exec_snapshots_count != 0 )
282267 {
283- jerry_port_errormsg ("Error: --save-snapshot and --exec-snapshot options can't be passed simultaneously\n" );
268+ jerry_port_log (JERRY_LOG_LEVEL_ERROR ,
269+ "Error: --save-snapshot and --exec-snapshot options can't be passed simultaneously\n" );
284270 return JERRY_STANDALONE_EXIT_CODE_FAIL ;
285271 }
286272 }
@@ -291,22 +277,6 @@ main (int argc,
291277 is_repl_mode = true;
292278 }
293279
294- #ifdef JERRY_ENABLE_LOG
295- if (log_file_name )
296- {
297- jerry_log_file = fopen (log_file_name , "w" );
298- if (jerry_log_file == NULL )
299- {
300- jerry_port_errormsg ("Error: failed to open log file: %s\n" , log_file_name );
301- return JERRY_STANDALONE_EXIT_CODE_FAIL ;
302- }
303- }
304- else
305- {
306- jerry_log_file = stdout ;
307- }
308- #endif /* JERRY_ENABLE_LOG */
309-
310280 jerry_init (flags );
311281
312282 jerry_value_t global_obj_val = jerry_get_global_object ();
@@ -321,7 +291,7 @@ main (int argc,
321291
322292 if (!is_assert_added )
323293 {
324- jerry_port_errormsg ( "Warning: failed to register 'assert' method." );
294+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Warning: failed to register 'assert' method." );
325295 }
326296
327297 jerry_value_t ret_value = jerry_create_undefined ();
@@ -466,14 +436,6 @@ main (int argc,
466436 jerry_release_value (print_function );
467437 }
468438
469- #ifdef JERRY_ENABLE_LOG
470- if (jerry_log_file && jerry_log_file != stdout )
471- {
472- fclose (jerry_log_file );
473- jerry_log_file = NULL ;
474- }
475- #endif /* JERRY_ENABLE_LOG */
476-
477439 int ret_code = JERRY_STANDALONE_EXIT_CODE_OK ;
478440
479441 if (jerry_value_has_error_flag (ret_value ))
@@ -489,7 +451,7 @@ main (int argc,
489451 assert (sz == err_str_size );
490452 err_str_buf [err_str_size ] = 0 ;
491453
492- jerry_port_errormsg ( "Script Error: unhandled exception: %s\n" , err_str_buf );
454+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Script Error: unhandled exception: %s\n" , err_str_buf );
493455
494456 jerry_release_value (err_str_val );
495457
0 commit comments