mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
logging: pass binary name not logfile name when enabling logging
Instead of having each caller pass in the desired logfile name, pass in the binary name instead. The logging code can then just derive a logfile name by appending ".log". Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
dab800bb8c
commit
80d387c62f
@ -532,7 +532,7 @@ virLockDaemonSetupLogging(virLockDaemonConfigPtr config,
|
||||
/* Define the default output. This is only applied if there was no setting
|
||||
* from either the config or the environment.
|
||||
*/
|
||||
if (virLogSetDefaultOutput("virtlockd.log", godaemon, privileged) < 0)
|
||||
if (virLogSetDefaultOutput("virtlockd", godaemon, privileged) < 0)
|
||||
return -1;
|
||||
|
||||
if (virLogGetNbOutputs() == 0)
|
||||
|
@ -467,7 +467,7 @@ virLogDaemonSetupLogging(virLogDaemonConfigPtr config,
|
||||
/* Define the default output. This is only applied if there was no setting
|
||||
* from either the config or the environment.
|
||||
*/
|
||||
if (virLogSetDefaultOutput("virtlogd.log", godaemon, privileged) < 0)
|
||||
if (virLogSetDefaultOutput("virtlogd", godaemon, privileged) < 0)
|
||||
return -1;
|
||||
|
||||
if (virLogGetNbOutputs() == 0)
|
||||
|
@ -597,7 +597,7 @@ daemonSetupLogging(struct daemonConfig *config,
|
||||
/* Define the default output. This is only applied if there was no setting
|
||||
* from either the config or the environment.
|
||||
*/
|
||||
if (virLogSetDefaultOutput("libvirtd.log", godaemon, privileged) < 0)
|
||||
if (virLogSetDefaultOutput("libvirtd", godaemon, privileged) < 0)
|
||||
return -1;
|
||||
|
||||
if (virLogGetNbOutputs() == 0)
|
||||
|
@ -175,7 +175,7 @@ virLogSetDefaultOutputToJournald(void)
|
||||
|
||||
|
||||
static int
|
||||
virLogSetDefaultOutputToFile(const char *filename, bool privileged)
|
||||
virLogSetDefaultOutputToFile(const char *binary, bool privileged)
|
||||
{
|
||||
int ret = -1;
|
||||
char *logdir = NULL;
|
||||
@ -183,8 +183,8 @@ virLogSetDefaultOutputToFile(const char *filename, bool privileged)
|
||||
|
||||
if (privileged) {
|
||||
if (virAsprintf(&virLogDefaultOutput,
|
||||
"%d:file:%s/log/libvirt/%s", virLogDefaultPriority,
|
||||
LOCALSTATEDIR, filename) < 0)
|
||||
"%d:file:%s/log/libvirt/%s.log", virLogDefaultPriority,
|
||||
LOCALSTATEDIR, binary) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (!(logdir = virGetUserCacheDirectory()))
|
||||
@ -197,8 +197,8 @@ virLogSetDefaultOutputToFile(const char *filename, bool privileged)
|
||||
}
|
||||
umask(old_umask);
|
||||
|
||||
if (virAsprintf(&virLogDefaultOutput, "%d:file:%s/%s",
|
||||
virLogDefaultPriority, logdir, filename) < 0)
|
||||
if (virAsprintf(&virLogDefaultOutput, "%d:file:%s/%s.log",
|
||||
virLogDefaultPriority, logdir, binary) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -211,19 +211,19 @@ virLogSetDefaultOutputToFile(const char *filename, bool privileged)
|
||||
|
||||
/*
|
||||
* virLogSetDefaultOutput:
|
||||
* @filename: the file that the output should be redirected to (only needed
|
||||
* when @godaemon equals true
|
||||
* @binary: the binary for which logging is performed. The log file name
|
||||
* will be derived from the binary name, with ".log" appended.
|
||||
* @godaemon: whether we're running daemonized
|
||||
* @privileged: whether we're running with root privileges or not (session)
|
||||
*
|
||||
* Decides on what the default output (journald, file, stderr) should be
|
||||
* according to @filename, @godaemon, @privileged. This function should be run
|
||||
* according to @binary, @godaemon, @privileged. This function should be run
|
||||
* exactly once at daemon startup, so no locks are used.
|
||||
*
|
||||
* Returns 0 on success, -1 in case of a failure.
|
||||
*/
|
||||
int
|
||||
virLogSetDefaultOutput(const char *filename, bool godaemon, bool privileged)
|
||||
virLogSetDefaultOutput(const char *binary, bool godaemon, bool privileged)
|
||||
{
|
||||
bool have_journald = access("/run/systemd/journal/socket", W_OK) >= 0;
|
||||
|
||||
@ -237,7 +237,7 @@ virLogSetDefaultOutput(const char *filename, bool godaemon, bool privileged)
|
||||
return virLogSetDefaultOutputToStderr();
|
||||
}
|
||||
|
||||
return virLogSetDefaultOutputToFile(filename, privileged);
|
||||
return virLogSetDefaultOutputToFile(binary, privileged);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user