diff --git a/bsd-user/main.c b/bsd-user/main.c
index 9f8683d..8733e82 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -34,7 +34,8 @@

  #include "envlist.h"

-#define DEBUG_LOGFILE "/tmp/qemu.log"
+#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log"
+static const char *debug_logfile = DEFAULTDEBUG_LOGFILE;

  int singlestep;
  #if defined(CONFIG_USE_GUEST_BASE)
@@ -690,10 +691,11 @@ static void usage(void)
             "-bsd type         select emulated BSD type 
FreeBSD/NetBSD/OpenBSD (default)\n"
             "\n"
             "Debug options:\n"
-           "-d options   activate log (logfile=%s)\n"
-           "-p pagesize  set the host page size to 'pagesize'\n"
-           "-singlestep  always run in singlestep mode\n"
-           "-strace      log system calls\n"
+           "-d options         activate log\n"
+           "-logfile filename  set log file name to 'filename' (default 
%s)\n"
+           "-p pagesize        set the host page size to 'pagesize'\n"
+           "-singlestep        always run in singlestep mode\n"
+           "-strace            log system calls\n"
             "\n"
             "Environment variables:\n"
             "QEMU_STRACE       Print system calls and arguments similar 
to the\n"
@@ -708,7 +710,7 @@ static void usage(void)
             TARGET_ARCH,
             interp_prefix,
             x86_stack_size,
-           DEBUG_LOGFILE);
+           debug_logfile);
      exit(1);
  }

@@ -741,13 +743,11 @@ int main(int argc, char **argv)
      char **target_environ, **wrk;
      envlist_t *envlist = NULL;
      bsd_type = target_openbsd;
+    int log_mask = 0;

      if (argc <= 1)
          usage();

-    /* init debug */
-    cpu_set_log_filename(DEBUG_LOGFILE);
-
      if ((envlist = envlist_create()) == NULL) {
          (void) fprintf(stderr, "Unable to allocate envlist\n");
          exit(1);
@@ -770,23 +770,23 @@ int main(int argc, char **argv)
          r++;
          if (!strcmp(r, "-")) {
              break;
+        } else if (!strcmp(r, "logfile")) {
+          debug_logfile = argv[optind++];
          } else if (!strcmp(r, "d")) {
-            int mask;
              const CPULogItem *item;

              if (optind >= argc)
                  break;

-            r = argv[optind++];
-            mask = cpu_str_to_log_mask(r);
-            if (!mask) {
+	    r = argv[optind++];
+            log_mask = cpu_str_to_log_mask(r);
+            if (!log_mask) {
                  printf("Log items (comma separated):\n");
                  for(item = cpu_log_items; item->mask != 0; item++) {
                      printf("%-10s %s\n", item->name, item->help);
                  }
                  exit(1);
              }
-            cpu_set_log(mask);
          } else if (!strcmp(r, "E")) {
              r = argv[optind++];
              if (envlist_setenv(envlist, r) != 0)
@@ -857,6 +857,12 @@ int main(int argc, char **argv)
          usage();
      filename = argv[optind];

+    /* init debug */
+    if (log_mask) {
+      cpu_set_log_filename(debug_logfile);
+      cpu_set_log(log_mask);
+    }
+
      /* Zero out regs */
      memset(regs, 0, sizeof(struct target_pt_regs));

diff --git a/darwin-user/main.c b/darwin-user/main.c
index 5fd314e..53989c2 100644
--- a/darwin-user/main.c
+++ b/darwin-user/main.c
@@ -29,7 +29,8 @@

  #include "qemu.h"

-#define DEBUG_LOGFILE "/tmp/qemu.log"
+#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log"
+static const char *debug_logfile = DEFAULTDEBUG_LOGFILE;

  #ifdef __APPLE__
  #include <crt_externs.h>
@@ -715,15 +716,16 @@ void usage(void)
             "-s size      set the stack size in bytes (default=%ld)\n"
             "\n"
             "debug options:\n"
-           "-d options   activate log (logfile='%s')\n"
-           "-g wait for gdb on port 1234\n"
-           "-p pagesize  set the host page size to 'pagesize'\n",
-           "-singlestep  always run in singlestep mode\n"
+           "-d options         activate log\n"
+           "-logfile filename  set log file name to 'filename' (default 
%s)\n"
+           "-g                 wait for gdb on port 1234\n"
+           "-p pagesize        set the host page size to 'pagesize'\n",
+           "-singlestep        always run in singlestep mode\n"
             TARGET_ARCH,
             TARGET_ARCH,
             interp_prefix,
             stack_size,
-           DEBUG_LOGFILE);
+           debug_logfile);
      exit(1);
  }

@@ -745,13 +747,11 @@ int main(int argc, char **argv)
      short use_gdbstub = 0;
      const char *r;
      const char *cpu_model;
+    int log_mask = 0;

      if (argc <= 1)
          usage();

-    /* init debug */
-    cpu_set_log_filename(DEBUG_LOGFILE);
-
      optind = 1;
      for(;;) {
          if (optind >= argc)
@@ -763,23 +763,23 @@ int main(int argc, char **argv)
          r++;
          if (!strcmp(r, "-")) {
              break;
+        } else if (!strcmp(r, "logfile")) {
+          debug_logfile = argv[optind++];
          } else if (!strcmp(r, "d")) {
-            int mask;
              CPULogItem *item;

          if (optind >= argc)
          break;

          r = argv[optind++];
-            mask = cpu_str_to_log_mask(r);
-            if (!mask) {
+            log_mask = cpu_str_to_log_mask(r);
+            if (!log_mask) {
                  printf("Log items (comma separated):\n");
                  for(item = cpu_log_items; item->mask != 0; item++) {
                      printf("%-10s %s\n", item->name, item->help);
                  }
                  exit(1);
              }
-            cpu_set_log(mask);
          } else if (!strcmp(r, "s")) {
              r = argv[optind++];
              stack_size = strtol(r, (char **)&r, 0);
@@ -821,6 +821,12 @@ int main(int argc, char **argv)
          usage();
      filename = argv[optind];

+    /* init debug */
+    if (log_mask) {
+      cpu_set_log_filename(debug_logfile);
+      cpu_set_log(log_mask);
+    }
+
      /* Zero out regs */
      memset(regs, 0, sizeof(struct target_pt_regs));

diff --git a/linux-user/main.c b/linux-user/main.c
index a6af2a5..56f78db 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -34,7 +34,8 @@

  #include "envlist.h"

-#define DEBUG_LOGFILE "/tmp/qemu.log"
+#define DEFAULTDEBUG_LOGFILE "/tmp/qemu.log"
+static const char *debug_logfile = DEFAULTDEBUG_LOGFILE;

  char *exec_path;

@@ -2454,10 +2455,11 @@ static void usage(void)
  #endif
             "\n"
             "Debug options:\n"
-           "-d options   activate log (logfile=%s)\n"
-           "-p pagesize  set the host page size to 'pagesize'\n"
-           "-singlestep  always run in singlestep mode\n"
-           "-strace      log system calls\n"
+           "-d options         activate logfile\n"
+           "-logfile filename  set log file name to 'filename' (default 
%s)\n"
+           "-p pagesize        set the host page size to 'pagesize'\n"
+           "-singlestep        always run in singlestep mode\n"
+           "-strace            log system calls\n"
             "\n"
             "Environment variables:\n"
             "QEMU_STRACE       Print system calls and arguments similar 
to the\n"
@@ -2472,7 +2474,7 @@ static void usage(void)
             TARGET_ARCH,
             interp_prefix,
             x86_stack_size,
-           DEBUG_LOGFILE);
+           debug_logfile);
      exit(1);
  }

@@ -2531,15 +2533,13 @@ int main(int argc, char **argv, char **envp)
      const char *argv0 = NULL;
      int i;
      int ret;
+    int log_mask = 0;

      if (argc <= 1)
          usage();

      qemu_cache_utils_init(envp);

-    /* init debug */
-    cpu_set_log_filename(DEBUG_LOGFILE);
-
      if ((envlist = envlist_create()) == NULL) {
          (void) fprintf(stderr, "Unable to allocate envlist\n");
          exit(1);
@@ -2562,23 +2562,23 @@ int main(int argc, char **argv, char **envp)
          r++;
          if (!strcmp(r, "-")) {
              break;
+        } else if (!strcmp(r, "logfile")) {
+          debug_logfile = argv[optind++];
          } else if (!strcmp(r, "d")) {
-            int mask;
              const CPULogItem *item;

  	    if (optind >= argc)
  		break;

  	    r = argv[optind++];
-            mask = cpu_str_to_log_mask(r);
-            if (!mask) {
+            log_mask = cpu_str_to_log_mask(r);
+            if (!log_mask) {
                  printf("Log items (comma separated):\n");
                  for(item = cpu_log_items; item->mask != 0; item++) {
                      printf("%-10s %s\n", item->name, item->help);
                  }
                  exit(1);
              }
-            cpu_set_log(mask);
          } else if (!strcmp(r, "E")) {
              r = argv[optind++];
              if (envlist_setenv(envlist, r) != 0)
@@ -2648,6 +2648,12 @@ int main(int argc, char **argv, char **envp)
      filename = argv[optind];
      exec_path = argv[optind];

+    /* init debug */
+    if (log_mask) {
+      cpu_set_log_filename(debug_logfile);
+      cpu_set_log(log_mask);
+    }
+
      /* Zero out regs */
      memset(regs, 0, sizeof(struct target_pt_regs));

diff --git a/qemu-doc.texi b/qemu-doc.texi
index 7b8488f..cc7f322 100644
--- a/qemu-doc.texi
+++ b/qemu-doc.texi
@@ -2066,7 +2066,9 @@ Debug options:

  @table @option
  @item -d
-Activate log (logfile=/tmp/qemu.log)
+Activate log
+@item -logfile filename
+Set log file name to 'filename' (defaut /tmp/qemu.log)
  @item -p pagesize
  Act as if the host page size was 'pagesize' bytes
  @item -g port
@@ -2188,7 +2190,9 @@ Debug options:

  @table @option
  @item -d
-Activate log (logfile=/tmp/qemu.log)
+Activate log
+@item -logfile filename
+Set log file name to 'filename' (defaut /tmp/qemu.log)
  @item -p pagesize
  Act as if the host page size was 'pagesize' bytes
  @item -singlestep
@@ -2252,7 +2256,9 @@ Debug options:

  @table @option
  @item -d
-Activate log (logfile=/tmp/qemu.log)
+Activate log
+@item -logfile filename
+Set log file name to 'filename' (defaut /tmp/qemu.log)
  @item -p pagesize
  Act as if the host page size was 'pagesize' bytes
  @item -singlestep
diff --git a/qemu-options.hx b/qemu-options.hx
index 8de71d6..97b21d3 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1648,10 +1648,17 @@ Shorthand for -gdb tcp::1234, i.e. open a 
gdbserver on TCP port 1234
  ETEXI

  DEF("d", HAS_ARG, QEMU_OPTION_d, \
-    "-d item1,...    output log to %s (use -d ? for a list of log 
items)\n")
+    "-d item1,...    output log (use -d ? for a list of log items)\n")
  STEXI
  @item -d
-Output log in /tmp/qemu.log
+Output log
+ETEXI
+
+DEF("logfile", HAS_ARG, QEMU_OPTION_logfile, \
+    "-logfile filename\n                Set log file name to 'filename' 
(defaut %s)\n")
+STEXI
+@item -logfile
+Set log file name to 'filename' (defaut /tmp/qemu.log)
