From ca8d822ca488b1afa82f748604baeddfeec483c1 Mon Sep 17 00:00:00 2001 From: Daniel Xu Date: Fri, 29 Jan 2016 22:38:11 +0000 Subject: [PATCH] TS-4165 Logging breaks if changing log format TS wasn't calling `open_file()` on the LogFile it was trying to rotate away. This was occurring when an existing log file's formatting was changed in logs_xml.config and TS was restarted. The result was TS not updating/creating the updated log file. --- proxy/logging/LogObject.cc | 31 +++++++++++++++++++++---------- proxy/logging/LogObject.h | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/proxy/logging/LogObject.cc b/proxy/logging/LogObject.cc index dd272b635c7..3afe70d24a6 100644 --- a/proxy/logging/LogObject.cc +++ b/proxy/logging/LogObject.cc @@ -1024,16 +1024,17 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli "filename", filename); LogFile logfile(filename, NULL, LOG_FILE_ASCII, 0); - long time_now = LogUtils::timestamp(); - - if (logfile.roll(time_now - log_object->get_rolling_interval(), time_now) == 0) { - // an error happened while trying to roll the file - // - const char *msg = "Cannot roll log file %s to fix log " - "filename conflicts"; - - Error(msg, filename); - LogUtils::manager_alarm(LogUtils::LOG_ALARM_ERROR, msg, filename); + if (logfile.open_file() == LogFile::LOG_FILE_NO_ERROR) { + long time_now = LogUtils::timestamp(); + + if (logfile.roll(time_now - log_object->get_rolling_interval(), time_now) == 0) { + // an error happened while trying to roll the file + // + _filename_resolution_abort(filename); + retVal = CANNOT_SOLVE_FILENAME_CONFLICTS; + } + } else { + _filename_resolution_abort(filename); retVal = CANNOT_SOLVE_FILENAME_CONFLICTS; } } @@ -1043,6 +1044,16 @@ LogObjectManager::_solve_filename_conflicts(LogObject *log_object, int maxConfli return retVal; } +void +LogObjectManager::_filename_resolution_abort(const char *filename) +{ + const char *msg = "Cannot roll log file %s to fix log " + "conflicts (filename or log format): %s"; + const char *err = strerror(errno); + Error(msg, filename, err); + LogUtils::manager_alarm(LogUtils::LOG_ALARM_ERROR, msg, filename, err); +} + bool LogObjectManager::_has_internal_filename_conflict(const char *filename, LogObjectList &objects) diff --git a/proxy/logging/LogObject.h b/proxy/logging/LogObject.h index bfbb8a66889..4f73b6c57c6 100644 --- a/proxy/logging/LogObject.h +++ b/proxy/logging/LogObject.h @@ -379,6 +379,7 @@ class LogObjectManager static bool _has_internal_filename_conflict(const char *filename, LogObjectList &objects); int _solve_filename_conflicts(LogObject *log_obj, int maxConflicts); int _solve_internal_filename_conflicts(LogObject *log_obj, int maxConflicts, int fileNum = 0); + void _filename_resolution_abort(const char *fname); public: LogObjectManager();