1717#include < string.h>
1818
1919#include " jerry.h"
20+ #include " jrt/jrt.h"
2021
2122#include " plugins/io/init.h"
2223
@@ -130,6 +131,9 @@ main (int argc,
130131
131132 jerry_flag_t flags = JERRY_FLAG_EMPTY;
132133
134+ #ifdef JERRY_ENABLE_LOG
135+ const char *log_file_name = nullptr ;
136+ #endif /* JERRY_ENABLE_LOG */
133137 for (i = 1 ; i < argc; i++)
134138 {
135139 if (!strcmp (" -v" , argv[i]))
@@ -159,6 +163,36 @@ main (int argc,
159163 {
160164 flags |= JERRY_FLAG_SHOW_OPCODES;
161165 }
166+ else if (!strcmp (" --log-level" , argv[i]))
167+ {
168+ flags |= JERRY_FLAG_ENABLE_LOG;
169+ if (++i < argc && strlen (argv[i]) == 1 && argv[i][0 ] >=' 0' && argv[i][0 ] <= ' 3' )
170+ {
171+ #ifdef JERRY_ENABLE_LOG
172+ jerry_debug_level = argv[i][0 ] - ' 0' ;
173+ #endif /* JERRY_ENABLE_LOG */
174+ }
175+ else
176+ {
177+ printf (" Error: wrong format or invalid argument\n " );
178+ return JERRY_STANDALONE_EXIT_CODE_FAIL;
179+ }
180+ }
181+ else if (!strcmp (" --log-file" , argv[i]))
182+ {
183+ flags |= JERRY_FLAG_ENABLE_LOG;
184+ if (++i < argc)
185+ {
186+ #ifdef JERRY_ENABLE_LOG
187+ log_file_name = argv[i];
188+ #endif /* JERRY_ENABLE_LOG */
189+ }
190+ else
191+ {
192+ printf (" Error: wrong format of the arguments\n " );
193+ return JERRY_STANDALONE_EXIT_CODE_FAIL;
194+ }
195+ }
162196 else
163197 {
164198 file_names[files_counter++] = argv[i];
@@ -180,6 +214,22 @@ main (int argc,
180214 }
181215 else
182216 {
217+ #ifdef JERRY_ENABLE_LOG
218+ if (log_file_name)
219+ {
220+ jerry_log_file = fopen (log_file_name, " w" );
221+ if (jerry_log_file == nullptr )
222+ {
223+ printf (" Failed to open log file: %s\n " , log_file_name);
224+ return JERRY_STANDALONE_EXIT_CODE_FAIL;
225+ }
226+ }
227+ else
228+ {
229+ jerry_log_file = stdout;
230+ }
231+ #endif /* JERRY_ENABLE_LOG */
232+
183233 jerry_init (flags);
184234
185235 plugin_io_init ();
@@ -201,6 +251,14 @@ main (int argc,
201251
202252 jerry_cleanup ();
203253
254+ #ifdef JERRY_ENABLE_LOG
255+ if (jerry_log_file && jerry_log_file != stdout)
256+ {
257+ fclose (jerry_log_file);
258+ jerry_log_file = nullptr ;
259+ }
260+ #endif /* JERRY_ENABLE_LOG */
261+
204262 if (ret_code == JERRY_COMPLETION_CODE_OK)
205263 {
206264 return JERRY_STANDALONE_EXIT_CODE_OK;
0 commit comments