about qemu log
Hi, all
If I use qemu command directly to run vm, bypass libvirt, how to configure qemu to assure that each vm has its own log file, like vmname.log? For example, VM: rhel7-net has its own log file, rhel7-net.log, VM:rhel7-stor has its own log file, rhel7-stor.log.
Thanks,
Zhang Haoyu
Quoted 5 lines · Zhang Haoyu
Hi, all
If I use qemu command directly to run vm, bypass libvirt, how to configure qemu to assure that each vm has its own log file, like vmname.log? For example, VM: rhel7-net has its own log file, rhel7-net.log,
VM:rhel7-stor has its own log file, rhel7-stor.log.
-D /path/to/unique/file/name.log
Or am I misunderstanding what you want?
Signature · 1 line
Alex Bennée
Quoted 8 lines
Quoted 5 lines
Hi, all
If I use qemu command directly to run vm, bypass libvirt, how to configure qemu to assure that each vm has its own log file, like vmname.log? For example, VM: rhel7-net has its own log file, rhel7-net.log,
VM:rhel7-stor has its own log file, rhel7-stor.log.-D /path/to/unique/file/name.log
-D option is to configure qemu_logfile for the output logs which are controlled by qmp command "logfile", which can be enabled/disabled on run time.
I want to configure the log file for the output of fprintf(stderr, fmt, ...), .etc,
i.e., how to redirect the output of fprintf(stderr, fmt, ...), or some other log-interface to a specified file?
I saw the configuration in qemuStateInitialize(), libvirt code, but now I run the vm directly through qemu command, bypass libvirt.
Thanks,
Zhang Haoyu
Quoted 1 line
Or am I misunderstanding what you want?
Am 25.07.2014 13:07, schrieb Zhang Haoyu:
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Hi, all
If I use qemu command directly to run vm, bypass libvirt, how to configure qemu to assure that each vm has its own log file, like vmname.log? For example, VM: rhel7-net has its own log file, rhel7-net.log,
VM:rhel7-stor has its own log file, rhel7-stor.log.
Quoted 6 lines
Quoted 2 lines
-D /path/to/unique/file/name.log
-D option is to configure
qemu_logfilefor the output logs which are controlled by qmp command "logfile", which can be enabled/disabled on run time.I want to configure the log file for the output of
fprintf(stderr, fmt, ...), .etc,
i.e., how to redirect the output offprintf(stderr, fmt, ...), or some other log-interface to a specified file?
In a shell you would write something like:
2> stderr.log
You may also want to toggle QEMU's -msg timestamp=on option.
Cheers,
Andreas
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Hi, all
If I use qemu command directly to run vm, bypass libvirt, how to configure qemu to assure that each vm has its own log file, like vmname.log? For example, VM: rhel7-net has its own log file, rhel7-net.log,
VM:rhel7-stor has its own log file, rhel7-stor.log.-D /path/to/unique/file/name.log
-D option is to configure
qemu_logfilefor the output logs which are controlled by qmp command "logfile", which can be enabled/disabled on run time.
Quoted 9 lines
Quoted 2 lines
I want to configure the log file for the output of
fprintf(stderr, fmt, ...), .etc,
i.e., how to redirect the output offprintf(stderr, fmt, ...), or some other log-interface to a specified file?In a shell you would write something like:
2> stderr.log
You may also want to toggle QEMU's -msg timestamp=on option.
I think the "-msg -msg timestamp=on" option will add timestamp to the output of error_report(fmt, ...), but where is the output? Which file saves the output?
And where is the output of fprintf(stderr, fmt, ...)?
Should I redirect of stderr to specified log file?
In libvirt code, when start a vm(qemuProcessStart), it will create a qemu log file named /var/log/libvirt/qemu/vmname.log, and redirect the stderr and stdout to file descriptor of this qemu log file.
But if I run a vm directly by qemu command, bypass libvirt, then how to configure qemu to assure that each vm has its own log file, and how to redirect the stderr, stdout to each vm's own log file?
Thanks,
Zhang Haoyu
Quoted 2 lines
Cheers,
Andreas
Re: [Qemu-devel] [questions]_about_qemu_log
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines
Hi, all
If I use qemu command directly to run vm, bypass libvirt, how to configure qemu to assure that each vm has its own log file, like vmname.log? For example, VM: rhel7-net has its own log file, rhel7-net.log,
VM:rhel7-stor has its own log file, rhel7-stor.log.-D /path/to/unique/file/name.log
-D option is to configure
qemu_logfilefor the output logs which are controlled by qmp command "logfile", which can be enabled/disabled on run time.I want to configure the log file for the output of
fprintf(stderr, fmt, ...), .etc,
i.e., how to redirect the output offprintf(stderr, fmt, ...), or some other log-interface to a specified file?
Quoted 8 lines
Quoted 6 lines
In a shell you would write something like:
2> stderr.log
You may also want to toggle QEMU's -msg timestamp=on option.
I think the "-msg -msg timestamp=on" option will add timestamp to the output of
error_report(fmt, ...), but where is the output? Which file saves the output?
If during the qmp operation, error_report will output to current monitor, but my concern is to stderr, which file saves the output?
Quoted 14 lines
And where is the output of
fprintf(stderr, fmt, ...)? Should I redirect of stderr to specified log file?In libvirt code, when start a vm(qemuProcessStart), it will create a qemu log file named
/var/log/libvirt/qemu/vmname.log, and redirect the stderr and stdout to file descriptor of this qemu log file.But if I run a vm directly by qemu command, bypass libvirt, then how to configure qemu to assure that each vm has its own log file, and how to redirect the stderr, stdout to each vm's own log file?
Thanks,
Zhang HaoyuQuoted 2 lines
Cheers,
Andreas
Quoted 8 lines · Zhang Haoyu
Quoted 6 lines
In a shell you would write something like:
2> stderr.log
You may also want to toggle QEMU's -msg timestamp=on option.
I think the "-msg -msg timestamp=on" option will add timestamp to the output of
error_report(fmt, ...), but where is the output? Which file saves the output?
The output is on qemu's stderr. You are in control of what that stderr is.
Quoted 1 line
And where is the output of
fprintf(stderr, fmt, ...)?
Also on stderr.
Quoted 1 line
Should I redirect of stderr to specified log file?
Yes, if you want that output going to a specified file.
Quoted 6 lines
In libvirt code, when start a vm(qemuProcessStart), it will create a qemu log file named
/var/log/libvirt/qemu/vmname.log, and redirect the stderr and stdout to file descriptor of this qemu log file.But if I run a vm directly by qemu command, bypass libvirt, then how to configure qemu to assure that each vm has its own log file, and how to redirect the stderr, stdout to each vm's own log file?
If you are going to bypass libvirt, then you have to do your own shell redirections (as mentioned above) to ensure that file descriptor 2 as inherited by qemu is whatever file you want errors logged in.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 1 line · Eric Blake
The output is on qemu's stderr. You are in control of what that stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.log
but we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Signature · 1 line
William
Quoted 9 lines · William Dauchy
Quoted 1 line · Eric Blake
The output is on qemu's stderr. You are in control of what that stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Well -D will log to file only loggable (i.e. qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to default qemu_log output to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).
There's plently of tree wide work to clean up the cases where stderr is used where qemu_log should be. If you are finding that log information is going to stderr instead of the log, patches would be welcome.
Regards,
Peter
Quoted 3 lines
--
William
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below, DEF("elogfile", HAS_ARG, QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default /var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.
Thanks,
Zhang Haoyu
Quoted 7 lines
There's plently of tree wide work to clean up the cases where stderr is used where
qemu_logshould be. If you are finding that log information is going to stderr instead of the log, patches would be welcome.Regards,
Peter
Quoted 17 lines · Zhang Haoyu
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).
Quoted 11 lines
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below, DEF("elogfile",
HAS_ARG,QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default /var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.
This sounds out-of-scope for QEMU to me and makes a standard flow non-standard. If prints are going to stderr where should be going elsewhere they probably should be fixed. Do you have specific examples of information going to stderr that you would rather go to a log (be it an error log or something else?).
Regards,
Peter
Quoted 12 lines
Thanks,
Zhang HaoyuQuoted 7 lines
There's plently of tree wide work to clean up the cases where stderr is used where
qemu_logshould be. If you are finding that log information is going to stderr instead of the log, patches would be welcome.Regards,
Peter
Quoted 29 lines
Quoted 17 lines
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).Quoted 11 lines
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below, DEF("elogfile",
HAS_ARG,QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default /var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.
Quoted 6 lines
This sounds out-of-scope for QEMU to me and makes a standard flow non-standard. If prints are going to stderr where should be going elsewhere they probably should be fixed. Do you have specific examples of information going to stderr that you would rather go to a log (be it an error log or something else?).
I use proxmox to manage vm, it dose not redirect qemu's stderr, and start vm with -daemonize option,
so the error log disappeared.
I want to redirect the error log of qemu to a specified logfile, if fault happened, I can use the error log to analyze the fault.
And, why qemu output the error log to stderr instead of a error logfile which can be configure? Thanks,
Zhang Haoyu
Quoted 13 lines
Regards,
PeterQuoted 10 lines
Thanks,
Zhang HaoyuQuoted 7 lines
There's plently of tree wide work to clean up the cases where stderr is used where
qemu_logshould be. If you are finding that log information is going to stderr instead of the log, patches would be welcome.Regards,
Peter
Quoted 39 lines · Zhang Haoyu
Quoted 33 lines
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that
stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).Quoted 14 lines
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below,
DEF("elogfile",HAS_ARG,QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default
/var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.Quoted 6 lines
This sounds out-of-scope for QEMU to me and makes a standard flow non-standard. If prints are going to stderr where should be going elsewhere they probably should be fixed. Do you have specific examples of information going to stderr that you would rather go to a log (be it an error log or something else?).
Quoted 8 lines
I use proxmox to manage vm, it dose not redirect qemu's stderr, and start vm with -daemonize option,
so the error log disappeared.
I want to redirect the error log of qemu to a specified logfile, if fault happened, I can use the error log to analyze the fault.And, why qemu output the error log to stderr instead of a error logfile which can be configure?
Because the code is a mess in that regard.
You don't fix that by redirecting stderr wholesale, because that just adds to the mess. You fix it at the root, one ill-advised fprintf() at a time, as Peter advises:
[...]
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There's plently of tree wide work to clean up the cases where stderr is used where
qemu_logshould be. If you are finding that log information is going to stderr instead of the log, patches would be welcome.
If you want to redirect stderr in the interim, do it in whatever runs QEMU.
Quoted 45 lines
Quoted 45 lines
Quoted 33 lines
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that
stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).Quoted 14 lines
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below,
DEF("elogfile",HAS_ARG,QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default
/var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.Quoted 6 lines
This sounds out-of-scope for QEMU to me and makes a standard flow non-standard. If prints are going to stderr where should be going elsewhere they probably should be fixed. Do you have specific examples of information going to stderr that you would rather go to a log (be it an error log or something else?).
I use proxmox to manage vm, it dose not redirect qemu's stderr, and start vm with -daemonize option,
so the error log disappeared.
I want to redirect the error log of qemu to a specified logfile, if fault happened, I can use the error log to analyze the fault.
Quoted 9 lines
Quoted 2 lines
And, why qemu output the error log to stderr instead of a error logfile which can be configure?
Because the code is a mess in that regard.
You don't fix that by redirecting stderr wholesale, because that just adds to the mess. You fix it at the root, one ill-advised
fprintf()at a time, as Peter advises:
Sorry, I'm afraid I misunderstand what you mean,
should I replace all of fprintf(stderr, ...) with qemu_log() ?
or only some cases where stderr is used where qemu_log should be, as Perter advises? If so, should I still need to redirect the stderr to specified logfile in qemu's parent shell/process ?
Thanks,
Zhang Haoyu
Quoted 8 lines
[...]
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
There's plently of tree wide work to clean up the cases where stderr is used where
qemu_logshould be. If you are finding that log information is going to stderr instead of the log, patches would be welcome.If you want to redirect stderr in the interim, do it in whatever runs QEMU.
Quoted 55 lines · Zhang Haoyu
Quoted 45 lines
Quoted 45 lines
Quoted 33 lines
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that
stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).Quoted 14 lines
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below,
DEF("elogfile",HAS_ARG,QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default
/var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.Quoted 6 lines
This sounds out-of-scope for QEMU to me and makes a standard flow non-standard. If prints are going to stderr where should be going elsewhere they probably should be fixed. Do you have specific examples of information going to stderr that you would rather go to a log (be it an error log or something else?).
I use proxmox to manage vm, it dose not redirect qemu's stderr, and start vm with -daemonize option,
so the error log disappeared.
I want to redirect the error log of qemu to a specified logfile, if fault happened, I can use the error log to analyze the fault.Quoted 9 lines
Quoted 2 lines
And, why qemu output the error log to stderr instead of a error logfile which can be configure?
Because the code is a mess in that regard.
You don't fix that by redirecting stderr wholesale, because that just adds to the mess. You fix it at the root, one ill-advised
fprintf()at a time, as Peter advises:
Quoted 4 lines
Sorry, I'm afraid I misunderstand what you mean,
should I replace all offprintf(stderr, ...)withqemu_log()? or only some cases where stderr is used whereqemu_logshould be, as Perter advises?
I didn't mean to suggest blind conversion from fprintf() to qemu_log(). Each instance of fprintf() needs to be reviewed before conversion. I think that's exactly Peter's advice, too.
Quoted 2 lines
If so, should I still need to redirect the stderr to specified logfile in qemu's parent shell/process ?
Probably. Libvirt does it.
Quoted 57 lines · Markus Armbruster
Quoted 55 lines · Zhang Haoyu
Quoted 54 lines
Quoted 39 lines
Quoted 33 lines
Quoted 18 lines
Quoted 10 lines
Quoted 9 lines
Quoted 1 line
The output is on qemu's stderr. You are in control of what that
stderr is.
I don't get why we can configure
-D /path/to/unique/file/name.logbut we also have to redirect stderr (I didn't checked if the daemonize option was closing it). What's the purpose of this logfile option?
Quoted 8 lines
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).Quoted 14 lines
Maybe we can introduce a new qemu option to specify a error logfile where stderr be redirected, like below,
DEF("elogfile",HAS_ARG,QEMU_OPTION_elogfile, \
"-elogfile logfile redirect stderr log to logfile(default
/var/log/qemu/<vm name>##.log)\n",
QEMU_ARCH_ALL)
STEXI
@item -elogfile @var{logfile}
@findex -elogfile
redirect stderr in @var{logfile}
ETEXI
then we can set the error log file through qemu command, /var/log/qemu/<vm name>##.log as default.Quoted 6 lines
This sounds out-of-scope for QEMU to me and makes a standard flow non-standard. If prints are going to stderr where should be going elsewhere they probably should be fixed. Do you have specific examples of information going to stderr that you would rather go to a log (be it an error log or something else?).
Quoted 8 lines
I use proxmox to manage vm, it dose not redirect qemu's stderr, and start vm with -daemonize option,
so the error log disappeared.
I want to redirect the error log of qemu to a specified logfile, if fault happened, I can use the error log to analyze the fault.And, why qemu output the error log to stderr instead of a error logfile which can be configure?
Because the code is a mess in that regard.
You don't fix that by redirecting stderr wholesale, because that just adds to the mess. You fix it at the root, one ill-advised
fprintf()at a time, as Peter advises:
Quoted 7 lines
Quoted 4 lines
Sorry, I'm afraid I misunderstand what you mean,
should I replace all offprintf(stderr, ...)withqemu_log()? or only some cases where stderr is used whereqemu_logshould be, as Perter advises?I didn't mean to suggest blind conversion from
fprintf()toqemu_log(). Each instance offprintf()needs to be reviewed before conversion.
Yes i'm afraid there is no quick one-shot fix to your problem. The best is the suggested workarounds using stderr redirection.
Quoted 3 lines
I
think that's exactly Peter's advice, too.
Correct.
Regards,
Peter
Quoted 5 lines
Quoted 2 lines
If so, should I still need to redirect the stderr to specified logfile in qemu's parent shell/process ?
Probably. Libvirt does it.
Quoted 7 lines · Peter Crosthwaite
Well -D will log to file only loggable (i.e.
qemu_log()) information (which has all sorts of options and switches). Stderr, is a little more static and should in theory be limited to genuine errors. But if you want a combined log of both you can simply omit -D to defaultqemu_logoutput to stderr. This gives you a combined log that you can redirect anywhere. To be honest, this is what I do as a matter of course (2> foo rather than -D foo).
understood; this make it incompatible with -daemonize option. there should be a possibility to detach the process and also redirect stderr somewhere.
Signature · 1 line
William
Quoted 3 lines · William Dauchy
this make it incompatible with -daemonize option.
there should be a possibility to detach the process and also redirect stderr somewhere.
I have done a quick and dirty patch for my own qemu binary so I can use daemonize and also redirect stderr to syslog.
include/sysemu/os-posix.h +1 -0
@@ -34,6 +34,7 @@ void os_setup_signal_handling(void);void os_daemonize (void );void os_setup_post (void );int os_mlock (void ); +void tolog (FILE **pfp);typedef struct timeval qemu_timeval ;#define qemu_gettimeofday (tp) gettimeofday(tp, NULL)
os-posix.c +26 -2
@@ -33,6 +33,8 @@#include <pwd.h> #include <grp.h> #include <libgen.h> +#include <stdio.h> +#include <syslog.h> /* Needed early for CONFIG_BSD etc. */ #include "config-host.h"
@@ -250,6 +252,28 @@ void os_daemonize(void) } } +static size_t writer (void *cookie,char const *data,size_t len) +{ +while (*data ==' ' ) { + ++data; + --len; + } + +syslog (LOG_DEBUG ,"%.*s" , len, data); +return len; +} + +static int noop (void ) {return 0 ;} +static cookie_io_functions_t log_fn = { + (void *) noop, (void *) writer, (void *) noop, (void *) noop +}; + +void tolog (FILE **pfp) +{ + *pfp =fopencookie (NULL ,"w" , log_fn); +setvbuf (*pfp,NULL , _IOLBF,0 ); +} +void os_setup_post (void ) {int fd =0 ;
@@ -280,8 +304,8 @@ void os_setup_post(void)if (daemonize) {dup2 (fd,0 ); -dup2 (fd,1 ); -dup2 (fd,2 ); +tolog (&stdout); +tolog (&stderr);close (fd); }
vl.c +4 -0
@@ -3969,6 +3970,10 @@ int main(int argc, char **argv, char **envp)loc_set_none ();os_daemonize (); +if (is_daemonized ()) { +tolog (&stdout); +tolog (&stderr); + }if (qemu_init_main_loop ()) {fprintf (stderr,"qemu_init_main_loop failed\n" );
Signature · 1 line
William