Skip to content
Snippets Groups Projects
Commit d43f5da2 authored by Simon McVittie's avatar Simon McVittie
Browse files

logger: When we reopen a file, log an info message that says why


This would have made it considerably easier to spot that
commit 8f65507d "logger: Recreate output log files if they get deleted"
was reopening the log file more often than it should have been.

Signed-off-by: default avatarSimon McVittie <smcv@collabora.com>
parent 478c424c
No related branches found
No related tags found
1 merge request!743logger: Fix always re-opening files when --log-fd is used
This commit is part of merge request !743. Comments created here will be created in the context of that merge request.
......@@ -1220,17 +1220,26 @@ logger_process_complete_line (SrtLogger *self,
{
if (self->filename != NULL)
{
gboolean log_file_still_exists = FALSE;
const char *reason_to_reopen = NULL;
struct stat current_stat;
if (TEMP_FAILURE_RETRY (stat (self->filename, &current_stat)) == 0)
log_file_still_exists = _srt_is_same_stat (&current_stat,
&self->file_stat);
else if (errno != ENOENT)
_srt_log_warning ("Unable to stat log file: %s",
g_strerror (errno));
{
if (!_srt_is_same_stat (&current_stat, &self->file_stat))
reason_to_reopen = "File replaced";
}
else
{
int saved_errno = errno;
if (!log_file_still_exists)
if (saved_errno != ENOENT)
_srt_log_warning ("Unable to stat log file: %s",
g_strerror (saved_errno));
reason_to_reopen = g_strerror (saved_errno);
}
if (reason_to_reopen != NULL)
{
/* The log file is either deleted or replaced, probably by a
* developer who wanted to clear the logs out. Re-create it now
......@@ -1238,6 +1247,9 @@ logger_process_complete_line (SrtLogger *self,
glnx_autofd int new_fd = -1;
g_autoptr(GError) local_error = NULL;
g_info ("Re-opening \"%s\" because: %s",
self->filename, reason_to_reopen);
new_fd = TEMP_FAILURE_RETRY (open (self->filename,
OPEN_FLAGS,
0644));
......@@ -1260,6 +1272,7 @@ logger_process_complete_line (SrtLogger *self,
}
else
{
g_info ("Successfully re-opened \"%s\"", self->filename);
self->file_fd = glnx_steal_fd (&new_fd);
self->file_stat = current_stat;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment