Commit e735b91cd44e5dafb83ed4158a4c6721c0b289aa
1 parent
15f82208
Allow changing log filename.
Close logfile when logging is disabled. git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3035 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
2 changed files
with
19 additions
and
1 deletions
exec.c
| ... | ... | @@ -152,6 +152,7 @@ static int io_mem_watch; |
| 152 | 152 | char *logfilename = "/tmp/qemu.log"; |
| 153 | 153 | FILE *logfile; |
| 154 | 154 | int loglevel; |
| 155 | +static int log_append = 0; | |
| 155 | 156 | |
| 156 | 157 | /* statistics */ |
| 157 | 158 | static int tlb_flush_count; |
| ... | ... | @@ -1160,7 +1161,7 @@ void cpu_set_log(int log_flags) |
| 1160 | 1161 | { |
| 1161 | 1162 | loglevel = log_flags; |
| 1162 | 1163 | if (loglevel && !logfile) { |
| 1163 | - logfile = fopen(logfilename, "w"); | |
| 1164 | + logfile = fopen(logfilename, log_append ? "wa" : "w"); | |
| 1164 | 1165 | if (!logfile) { |
| 1165 | 1166 | perror(logfilename); |
| 1166 | 1167 | _exit(1); |
| ... | ... | @@ -1174,12 +1175,22 @@ void cpu_set_log(int log_flags) |
| 1174 | 1175 | #else |
| 1175 | 1176 | setvbuf(logfile, NULL, _IOLBF, 0); |
| 1176 | 1177 | #endif |
| 1178 | + log_append = 1; | |
| 1179 | + } | |
| 1180 | + if (!loglevel && logfile) { | |
| 1181 | + fclose(logfile); | |
| 1182 | + logfile = NULL; | |
| 1177 | 1183 | } |
| 1178 | 1184 | } |
| 1179 | 1185 | |
| 1180 | 1186 | void cpu_set_log_filename(const char *filename) |
| 1181 | 1187 | { |
| 1182 | 1188 | logfilename = strdup(filename); |
| 1189 | + if (logfile) { | |
| 1190 | + fclose(logfile); | |
| 1191 | + logfile = NULL; | |
| 1192 | + } | |
| 1193 | + cpu_set_log(loglevel); | |
| 1183 | 1194 | } |
| 1184 | 1195 | |
| 1185 | 1196 | /* mask must never be zero, except for A20 change call */ | ... | ... |
monitor.c
| ... | ... | @@ -406,6 +406,11 @@ static void do_screen_dump(const char *filename) |
| 406 | 406 | vga_hw_screen_dump(filename); |
| 407 | 407 | } |
| 408 | 408 | |
| 409 | +static void do_logfile(const char *filename) | |
| 410 | +{ | |
| 411 | + cpu_set_log_filename(filename); | |
| 412 | +} | |
| 413 | + | |
| 409 | 414 | static void do_log(const char *items) |
| 410 | 415 | { |
| 411 | 416 | int mask; |
| ... | ... | @@ -1213,6 +1218,8 @@ static term_cmd_t term_cmds[] = { |
| 1213 | 1218 | "device filename", "change a removable medium" }, |
| 1214 | 1219 | { "screendump", "F", do_screen_dump, |
| 1215 | 1220 | "filename", "save screen into PPM image 'filename'" }, |
| 1221 | + { "logfile", "s", do_logfile, | |
| 1222 | + "filename", "output logs to 'filename'" }, | |
| 1216 | 1223 | { "log", "s", do_log, |
| 1217 | 1224 | "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" }, |
| 1218 | 1225 | { "savevm", "s?", do_savevm, | ... | ... |