@@ -48,14 +48,14 @@ read_file (const char *file_name,
48
48
FILE * file = fopen (file_name , "r" );
49
49
if (file == NULL )
50
50
{
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 );
52
52
return NULL ;
53
53
}
54
54
55
55
size_t bytes_read = fread (buffer , 1u , sizeof (buffer ), file );
56
56
if (!bytes_read )
57
57
{
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 );
59
59
fclose (file );
60
60
return NULL ;
61
61
}
@@ -85,7 +85,7 @@ assert_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< f
85
85
}
86
86
else
87
87
{
88
- jerry_port_errormsg ( "Script error: assertion failed\n" );
88
+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Script error: assertion failed\n" );
89
89
exit (JERRY_STANDALONE_EXIT_CODE_FAIL );
90
90
}
91
91
} /* assert_handler */
@@ -114,7 +114,6 @@ print_help (char *name)
114
114
" --save-snapshot-for-eval FILE\n"
115
115
" --exec-snapshot FILE\n"
116
116
" --log-level [0-3]\n"
117
- " --log-file FILE\n"
118
117
" --abort-on-fail\n"
119
118
"\n" ,
120
119
name );
@@ -126,8 +125,10 @@ main (int argc,
126
125
{
127
126
if (argc > JERRY_MAX_COMMAND_LINE_ARGS )
128
127
{
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 );
131
132
132
133
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
133
134
}
@@ -154,9 +155,6 @@ main (int argc,
154
155
155
156
bool is_repl_mode = false;
156
157
157
- #ifdef JERRY_ENABLE_LOG
158
- const char * log_file_name = NULL ;
159
- #endif /* JERRY_ENABLE_LOG */
160
158
for (i = 1 ; i < argc ; i ++ )
161
159
{
162
160
if (!strcmp ("-h" , argv [i ]) || !strcmp ("--help" , argv [i ]))
@@ -193,14 +191,14 @@ main (int argc,
193
191
194
192
if (save_snapshot_file_name_p != NULL )
195
193
{
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" );
197
195
print_usage (argv [0 ]);
198
196
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
199
197
}
200
198
201
199
if (++ i >= argc )
202
200
{
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 ]);
204
202
print_usage (argv [0 ]);
205
203
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
206
204
}
@@ -211,7 +209,7 @@ main (int argc,
211
209
{
212
210
if (++ i >= argc )
213
211
{
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 ]);
215
213
print_usage (argv [0 ]);
216
214
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
217
215
}
@@ -223,35 +221,21 @@ main (int argc,
223
221
{
224
222
if (++ i >= argc )
225
223
{
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 ]);
227
225
print_usage (argv [0 ]);
228
226
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
229
227
}
230
228
231
229
if (strlen (argv [i ]) != 1 || argv [i ][0 ] < '0' || argv [i ][0 ] > '3' )
232
230
{
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 ]);
234
232
print_usage (argv [0 ]);
235
233
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
236
234
}
237
235
238
236
#ifdef JERRY_ENABLE_LOG
239
237
flags |= JERRY_INIT_ENABLE_LOG ;
240
238
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 ];
255
239
#endif /* JERRY_ENABLE_LOG */
256
240
}
257
241
else if (!strcmp ("--abort-on-fail" , argv [i ]))
@@ -260,7 +244,7 @@ main (int argc,
260
244
}
261
245
else if (!strncmp ("-" , argv [i ], 1 ))
262
246
{
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 ]);
264
248
print_usage (argv [0 ]);
265
249
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
266
250
}
@@ -274,13 +258,15 @@ main (int argc,
274
258
{
275
259
if (files_counter != 1 )
276
260
{
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" );
278
263
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
279
264
}
280
265
281
266
if (exec_snapshots_count != 0 )
282
267
{
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" );
284
270
return JERRY_STANDALONE_EXIT_CODE_FAIL ;
285
271
}
286
272
}
@@ -291,22 +277,6 @@ main (int argc,
291
277
is_repl_mode = true;
292
278
}
293
279
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
-
310
280
jerry_init (flags );
311
281
312
282
jerry_value_t global_obj_val = jerry_get_global_object ();
@@ -321,7 +291,7 @@ main (int argc,
321
291
322
292
if (!is_assert_added )
323
293
{
324
- jerry_port_errormsg ( "Warning: failed to register 'assert' method." );
294
+ jerry_port_log ( JERRY_LOG_LEVEL_ERROR , "Warning: failed to register 'assert' method." );
325
295
}
326
296
327
297
jerry_value_t ret_value = jerry_create_undefined ();
@@ -466,14 +436,6 @@ main (int argc,
466
436
jerry_release_value (print_function );
467
437
}
468
438
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
-
477
439
int ret_code = JERRY_STANDALONE_EXIT_CODE_OK ;
478
440
479
441
if (jerry_value_has_error_flag (ret_value ))
@@ -489,7 +451,7 @@ main (int argc,
489
451
assert (sz == err_str_size );
490
452
err_str_buf [err_str_size ] = 0 ;
491
453
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 );
493
455
494
456
jerry_release_value (err_str_val );
495
457
0 commit comments