Cleaned up flow of code in qemu_set_log(), to simplify and clarify.

Also added some explanation of the reasoning behind the branches.

Signed-off-by: Robert Foley <robert.foley@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Message-Id: <20191118211528.3221-3-robert.foley@linaro.org>
This commit is contained in:
Robert Foley 2019-11-18 16:15:24 -05:00 committed by Alex Bennée
parent 0f516ca476
commit 045e8861df

View File

@ -54,12 +54,25 @@ static bool log_uses_own_buffers;
/* enable or disable low levels log */
void qemu_set_log(int log_flags)
{
bool need_to_open_file = false;
qemu_loglevel = log_flags;
#ifdef CONFIG_TRACE_LOG
qemu_loglevel |= LOG_TRACE;
#endif
if (!qemu_logfile &&
(is_daemonized() ? logfilename != NULL : qemu_loglevel)) {
/*
* In all cases we only log if qemu_loglevel is set.
* Also:
* If not daemonized we will always log either to stderr
* or to a file (if there is a logfilename).
* If we are daemonized,
* we will only log if there is a logfilename.
*/
if (qemu_loglevel && (!is_daemonized() || logfilename)) {
need_to_open_file = true;
}
if (qemu_logfile && !need_to_open_file) {
qemu_log_close();
} else if (!qemu_logfile && need_to_open_file) {
if (logfilename) {
qemu_logfile = fopen(logfilename, log_append ? "a" : "w");
if (!qemu_logfile) {
@ -93,10 +106,6 @@ void qemu_set_log(int log_flags)
log_append = 1;
}
}
if (qemu_logfile &&
(is_daemonized() ? logfilename == NULL : !qemu_loglevel)) {
qemu_log_close();
}
}
void qemu_log_needs_buffers(void)