All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [questions] about qemu log
@ 2014-07-25  6:42 Zhang Haoyu
  2014-07-25 10:22 ` Alex Bennée
  0 siblings, 1 reply; 18+ messages in thread
From: Zhang Haoyu @ 2014-07-25  6:42 UTC (permalink / raw)
  To: qemu-devel

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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-07-25  6:42 [Qemu-devel] [questions] about qemu log Zhang Haoyu
@ 2014-07-25 10:22 ` Alex Bennée
  2014-07-25 11:07   ` Zhang Haoyu
  0 siblings, 1 reply; 18+ messages in thread
From: Alex Bennée @ 2014-07-25 10:22 UTC (permalink / raw)
  To: Zhang Haoyu; +Cc: qemu-devel


Zhang Haoyu writes:

> 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?

-- 
Alex Bennée

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-07-25 10:22 ` Alex Bennée
@ 2014-07-25 11:07   ` Zhang Haoyu
  2014-07-25 13:20     ` Andreas Färber
  0 siblings, 1 reply; 18+ messages in thread
From: Zhang Haoyu @ 2014-07-25 11:07 UTC (permalink / raw)
  To: Alex Bennée; +Cc: qemu-devel

>> 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

>Or am I misunderstanding what you want?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-07-25 11:07   ` Zhang Haoyu
@ 2014-07-25 13:20     ` Andreas Färber
  2014-07-26  2:28       ` Zhang Haoyu
  0 siblings, 1 reply; 18+ messages in thread
From: Andreas Färber @ 2014-07-25 13:20 UTC (permalink / raw)
  To: Zhang Haoyu; +Cc: Alex Bennée, qemu-devel

Am 25.07.2014 13:07, schrieb 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
>>
> -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?

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

-- 
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-07-25 13:20     ` Andreas Färber
@ 2014-07-26  2:28       ` Zhang Haoyu
  2014-07-26  3:03         ` [Qemu-devel] [questions]_about_qemu_log Zhang Haoyu
  2014-07-29 19:51         ` [Qemu-devel] [questions] about qemu log Eric Blake
  0 siblings, 2 replies; 18+ messages in thread
From: Zhang Haoyu @ 2014-07-26  2:28 UTC (permalink / raw)
  To: Andreas Färber; +Cc: Alex Bennée, qemu-devel

>>>> 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?
>
>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

>Cheers,
>Andreas

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions]_about_qemu_log
  2014-07-26  2:28       ` Zhang Haoyu
@ 2014-07-26  3:03         ` Zhang Haoyu
  2014-07-29 19:51         ` [Qemu-devel] [questions] about qemu log Eric Blake
  1 sibling, 0 replies; 18+ messages in thread
From: Zhang Haoyu @ 2014-07-26  3:03 UTC (permalink / raw)
  To: Zhang Haoyu, Andreas Färber; +Cc: Alex Bennée, qemu-devel

>>>>> 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?
>>
>>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?
>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
>
>>Cheers,
>>Andreas

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-07-26  2:28       ` Zhang Haoyu
  2014-07-26  3:03         ` [Qemu-devel] [questions]_about_qemu_log Zhang Haoyu
@ 2014-07-29 19:51         ` Eric Blake
  2014-08-05 20:48           ` William Dauchy
  1 sibling, 1 reply; 18+ messages in thread
From: Eric Blake @ 2014-07-29 19:51 UTC (permalink / raw)
  To: Zhang Haoyu, Andreas Färber; +Cc: Alex Bennée, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1363 bytes --]

On 07/25/2014 08:28 PM, Zhang Haoyu wrote:

>> 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.

> And where is the output of fprintf(stderr, fmt, ...)?

Also on stderr.

> Should I redirect of stderr to specified log file?

Yes, if you want that output going to a specified 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?

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.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 539 bytes --]

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-07-29 19:51         ` [Qemu-devel] [questions] about qemu log Eric Blake
@ 2014-08-05 20:48           ` William Dauchy
  2014-08-05 22:40             ` Peter Crosthwaite
  0 siblings, 1 reply; 18+ messages in thread
From: William Dauchy @ 2014-08-05 20:48 UTC (permalink / raw)
  To: Eric Blake; +Cc: Zhang Haoyu, Alex Bennée, Andreas Färber, qemu-devel

On Tue, Jul 29, 2014 at 9:51 PM, Eric Blake <eblake@redhat.com> wrote:
> 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?

-- 
William

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-05 20:48           ` William Dauchy
@ 2014-08-05 22:40             ` Peter Crosthwaite
  2014-08-06  1:23               ` Zhang Haoyu
  2014-08-06 10:43               ` William Dauchy
  0 siblings, 2 replies; 18+ messages in thread
From: Peter Crosthwaite @ 2014-08-05 22:40 UTC (permalink / raw)
  To: William Dauchy
  Cc: Alex Bennée, Zhang Haoyu, Andreas Färber, qemu-devel

On Wed, Aug 6, 2014 at 6:48 AM, William Dauchy <wdauchy@gmail.com> wrote:
> On Tue, Jul 29, 2014 at 9:51 PM, Eric Blake <eblake@redhat.com> wrote:
>> 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?
>

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

> --
> William
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-05 22:40             ` Peter Crosthwaite
@ 2014-08-06  1:23               ` Zhang Haoyu
  2014-08-06  2:49                 ` Peter Crosthwaite
  2014-08-06 10:43               ` William Dauchy
  1 sibling, 1 reply; 18+ messages in thread
From: Zhang Haoyu @ 2014-08-06  1:23 UTC (permalink / raw)
  To: Peter Crosthwaite, William Dauchy
  Cc: Alex Bennée, Andreas_Färber, qemu-devel

>>> 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?
>>
>
>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).
>
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

>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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06  1:23               ` Zhang Haoyu
@ 2014-08-06  2:49                 ` Peter Crosthwaite
  2014-08-06  3:41                   ` Zhang Haoyu
  0 siblings, 1 reply; 18+ messages in thread
From: Peter Crosthwaite @ 2014-08-06  2:49 UTC (permalink / raw)
  To: Zhang Haoyu
  Cc: qemu-devel, Alex Bennée, William Dauchy, Andreas_Färber

On Wed, Aug 6, 2014 at 11:23 AM, Zhang Haoyu <zhanghy@sangfor.com> wrote:
>>>> 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?
>>>
>>
>>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).
>>
> 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

> Thanks,
> Zhang Haoyu
>
>>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
>
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06  2:49                 ` Peter Crosthwaite
@ 2014-08-06  3:41                   ` Zhang Haoyu
  2014-08-06  6:20                     ` Markus Armbruster
  0 siblings, 1 reply; 18+ messages in thread
From: Zhang Haoyu @ 2014-08-06  3:41 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: qemu-devel, Alex Bennée, William Dauchy, Andreas_Färber

>>>>> 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?
>>>>
>>>
>>>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).
>>>
>> 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?).
>
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

>Regards,
>Peter
>
>> Thanks,
>> Zhang Haoyu
>>
>>>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

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06  3:41                   ` Zhang Haoyu
@ 2014-08-06  6:20                     ` Markus Armbruster
  2014-08-06  7:00                       ` Zhang Haoyu
  0 siblings, 1 reply; 18+ messages in thread
From: Markus Armbruster @ 2014-08-06  6:20 UTC (permalink / raw)
  To: Zhang Haoyu
  Cc: Peter Crosthwaite, Alex Bennée, qemu-devel,
	Andreas_Färber, William Dauchy

"Zhang Haoyu" <zhanghy@sangfor.com> writes:

>>>>>> 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?
>>>>>
>>>>
>>>>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).
>>>>
>>> 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?).
>>
> 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:

[...]
>>>>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.

If you want to redirect stderr in the interim, do it in whatever runs
QEMU.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06  6:20                     ` Markus Armbruster
@ 2014-08-06  7:00                       ` Zhang Haoyu
  2014-08-06  7:42                         ` Markus Armbruster
  0 siblings, 1 reply; 18+ messages in thread
From: Zhang Haoyu @ 2014-08-06  7:00 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Peter Crosthwaite, Alex Bennée, qemu-devel, William Dauchy,
	Andreas_Färber

>>>>>>> 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?
>>>>>>
>>>>>
>>>>>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).
>>>>>
>>>> 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?).
>>>
>> 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:
>

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

>[...]
>>>>>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.
>
>If you want to redirect stderr in the interim, do it in whatever runs
>QEMU.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06  7:00                       ` Zhang Haoyu
@ 2014-08-06  7:42                         ` Markus Armbruster
  2014-08-06 12:04                           ` Peter Crosthwaite
  0 siblings, 1 reply; 18+ messages in thread
From: Markus Armbruster @ 2014-08-06  7:42 UTC (permalink / raw)
  To: Zhang Haoyu
  Cc: Peter Crosthwaite, Alex Bennée, qemu-devel,
	Andreas_Färber, William Dauchy

"Zhang Haoyu" <zhanghy@sangfor.com> writes:

>>>>>>>> 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?
>>>>>>>
>>>>>>
>>>>>>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).
>>>>>>
>>>>> 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?).
>>>>
>>> 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:
>>
>
> 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?

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.

> If so, should I still need to redirect the stderr to specified logfile
> in qemu's parent shell/process ?

Probably.  Libvirt does it.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-05 22:40             ` Peter Crosthwaite
  2014-08-06  1:23               ` Zhang Haoyu
@ 2014-08-06 10:43               ` William Dauchy
  2014-08-06 20:42                 ` William Dauchy
  1 sibling, 1 reply; 18+ messages in thread
From: William Dauchy @ 2014-08-06 10:43 UTC (permalink / raw)
  To: Peter Crosthwaite
  Cc: Alex Bennée, Zhang Haoyu, Andreas Färber, qemu-devel

On Wed, Aug 6, 2014 at 12:40 AM, Peter Crosthwaite
<peter.crosthwaite@xilinx.com> wrote:
> 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).

understood; this make it incompatible with -daemonize option.
there should be a possibility to detach the process and also redirect
stderr somewhere.
-- 
William

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06  7:42                         ` Markus Armbruster
@ 2014-08-06 12:04                           ` Peter Crosthwaite
  0 siblings, 0 replies; 18+ messages in thread
From: Peter Crosthwaite @ 2014-08-06 12:04 UTC (permalink / raw)
  To: Markus Armbruster
  Cc: Zhang Haoyu, Alex Bennée, qemu-devel, William Dauchy,
	Andreas_Färber

On Wed, Aug 6, 2014 at 5:42 PM, Markus Armbruster <armbru@redhat.com> wrote:
> "Zhang Haoyu" <zhanghy@sangfor.com> writes:
>
>>>>>>>>> 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?
>>>>>>>>
>>>>>>>
>>>>>>>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).
>>>>>>>
>>>>>> 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?).
>>>>>
>>>> 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:
>>>
>>
>> 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?
>
> I didn't mean to suggest blind conversion from fprintf() to qemu_log().
> Each instance of fprintf() 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.

>  I
> think that's exactly Peter's advice, too.
>

Correct.

Regards,
Peter

>> If so, should I still need to redirect the stderr to specified logfile
>> in qemu's parent shell/process ?
>
> Probably.  Libvirt does it.
>

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: [Qemu-devel] [questions] about qemu log
  2014-08-06 10:43               ` William Dauchy
@ 2014-08-06 20:42                 ` William Dauchy
  0 siblings, 0 replies; 18+ messages in thread
From: William Dauchy @ 2014-08-06 20:42 UTC (permalink / raw)
  To: Zhang Haoyu
  Cc: Alex Bennée, Peter Crosthwaite, Andreas Färber, qemu-devel

On Wed, Aug 6, 2014 at 12:43 PM, William Dauchy <wdauchy@gmail.com> wrote:
> 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.

diff --git a/include/sysemu/os-posix.h b/include/sysemu/os-posix.h
index f131521..bf92ec1 100644
--- a/include/sysemu/os-posix.h
+++ b/include/sysemu/os-posix.h
@@ -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)
diff --git a/os-posix.c b/os-posix.c
index cb2a7f7..8d8d425 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -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);
     }
diff --git a/vl.c b/vl.c
index fe451aa..6b6b62c 100644
--- a/vl.c
+++ b/vl.c
@@ -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");

-- 
William

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2014-08-06 20:43 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-25  6:42 [Qemu-devel] [questions] about qemu log Zhang Haoyu
2014-07-25 10:22 ` Alex Bennée
2014-07-25 11:07   ` Zhang Haoyu
2014-07-25 13:20     ` Andreas Färber
2014-07-26  2:28       ` Zhang Haoyu
2014-07-26  3:03         ` [Qemu-devel] [questions]_about_qemu_log Zhang Haoyu
2014-07-29 19:51         ` [Qemu-devel] [questions] about qemu log Eric Blake
2014-08-05 20:48           ` William Dauchy
2014-08-05 22:40             ` Peter Crosthwaite
2014-08-06  1:23               ` Zhang Haoyu
2014-08-06  2:49                 ` Peter Crosthwaite
2014-08-06  3:41                   ` Zhang Haoyu
2014-08-06  6:20                     ` Markus Armbruster
2014-08-06  7:00                       ` Zhang Haoyu
2014-08-06  7:42                         ` Markus Armbruster
2014-08-06 12:04                           ` Peter Crosthwaite
2014-08-06 10:43               ` William Dauchy
2014-08-06 20:42                 ` William Dauchy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.