diff --git a/ChangeLog b/ChangeLog index ad61609..c540b8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2016-08-04 +2016-08-05 * Version 1.2.0 released ========================= + Add GLog::is_open() method (#1837) Fix invalid pointer problem in GLog copies (#1823) Fix GSkyMap::publish() bug for empty sky maps (#1835) Fix loss of application name and version (#1835) diff --git a/NEWS b/NEWS index 1c9ee61..3ad2514 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.2.0 -4 August 2016 +5 August 2016 1. Introduction @@ -27,6 +27,7 @@ The following methods have been added: - GApplication::log_header1() - GApplication::log_header2() - GApplication::log_header3() +- GLog::is_open() The following methods have been removed: - ... @@ -69,6 +70,9 @@ pointer in the second instance became invalid. This has been fixed by duplicating the file descriptor and opening the log file in the copied instance using the duplicated descriptor. This solves the problems (#1823). +A GLog::is_open() method has been added to assess whether a log file is +actually opened (#1837). + 5. Base module -------------- diff --git a/README.md b/README.md index 99af9c1..08e5f1b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ GammaLib information ==================== -* Version: 1.2.0.dev1 (4 August 2016) +* Version: 1.2.0.dev1 (5 August 2016) * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) diff --git a/include/GLog.hpp b/include/GLog.hpp index 96c3db2..0723fdf 100644 --- a/include/GLog.hpp +++ b/include/GLog.hpp @@ -86,6 +86,7 @@ public: void clear(void); int size(void) const; std::string classname(void) const; + bool is_open(void) const; void open(const GFilename& filename, const bool& clobber = false); void close(void); void flush(const bool& force = false); @@ -147,6 +148,18 @@ std::string GLog::classname(void) const /***********************************************************************//** + * @brief Signal that log file is open + * + * @return True if log file is open, false otherwise. + ***************************************************************************/ +inline +bool GLog::is_open(void) const +{ + return (m_file != NULL); +} + + +/***********************************************************************//** * @brief Write string as centred header into logger * * @param[in] arg Header string. diff --git a/pyext/GLog.i b/pyext/GLog.i index ae62837..a36d332 100644 --- a/pyext/GLog.i +++ b/pyext/GLog.i @@ -47,6 +47,7 @@ public: void clear(void); int size(void) const; std::string classname(void) const; + bool is_open(void) const; void open(const GFilename& filename, const bool& clobber = false); void close(void); void flush(const bool& force = false); diff --git a/src/app/GApplication.cpp b/src/app/GApplication.cpp index b5a4100..6f13ae7 100644 --- a/src/app/GApplication.cpp +++ b/src/app/GApplication.cpp @@ -332,7 +332,10 @@ void GApplication::logFileOpen(const bool& clobber) // Initialise the application logger log.open(log_filename(), clobber); - } + // Write header into log file + log_header(); + + } // endif: file name was not empty // Set logger chattiness set_log_chatter(); @@ -349,11 +352,16 @@ void GApplication::logFileOpen(const bool& clobber) ***************************************************************************/ void GApplication::logFileClose(void) { - // Put trailer in log file - log_trailer(); + // Continue only if log file is open + if (log.is_open()) { + + // Write trailer into log file + log_trailer(); - // Close log file - log.close(); + // Close log file + log.close(); + + } // endif: log file was open // Return return; @@ -872,11 +880,8 @@ void GApplication::free_members(void) // Save application parameters m_pars.save(par_filename()); - // Put trailer in log file - log_trailer(); - // Close log file - log.close(); + logFileClose(); // Return return; diff --git a/src/app/GLog.cpp b/src/app/GLog.cpp index 0e24512..44793c4 100644 --- a/src/app/GLog.cpp +++ b/src/app/GLog.cpp @@ -554,9 +554,18 @@ void GLog::init_members(void) * @brief Copy class members * * @param[in] log Logger. + * + * Copy all class members from @p log to the current logger instance. This + * method will flush the buffer of @p log before copying. ***************************************************************************/ void GLog::copy_members(const GLog& log) { + // Force flushing the buffer before doing the copy. This assures that the + // log file is left in a clean state, and in particular, that logging + // will be done in order. We have to circument const correctness for + // doing this. + const_cast(&log)->flush(true); + // Copy attributes m_max_length = log.m_max_length; m_indent = log.m_indent; @@ -644,6 +653,9 @@ void GLog::flush(const bool& force) } // endwhile: flush until empty + // And now flush the kernel buffer + std::fflush(m_file); + } // endif: flush was required // Return diff --git a/test/test_GApplication.cpp b/test/test_GApplication.cpp index c23389c..aa4af10 100644 --- a/test/test_GApplication.cpp +++ b/test/test_GApplication.cpp @@ -381,7 +381,6 @@ void TestGApplication::test_GApplication(void) "Check application log file name"); // Write something into the logfile and close it - app1.log_header(); app1.log_string(SILENT, "Silent", false); app1.log_string(TERSE, "Terse", false); app1.log_string(NORMAL, "Normal", false);