Commit 2ee39e3bc71311e0867595969c35bb8f9127c4b3

Authored by Jürgen Knödlseder
1 parent 3f1b7ddb

Add GLog::is_open() method and flush logfile from kernel buffer (#1837).

ChangeLog
1   -2016-08-04
  1 +2016-08-05
2 2  
3 3 * Version 1.2.0 released
4 4 =========================
5 5  
  6 + Add GLog::is_open() method (#1837)
6 7 Fix invalid pointer problem in GLog copies (#1823)
7 8 Fix GSkyMap::publish() bug for empty sky maps (#1835)
8 9 Fix loss of application name and version (#1835)
... ...
1 1 New Features and Important Changes in GammaLib 1.2.0
2 2  
3   -4 August 2016
  3 +5 August 2016
4 4  
5 5  
6 6 1. Introduction
... ... @@ -27,6 +27,7 @@ The following methods have been added:
27 27 - GApplication::log_header1()
28 28 - GApplication::log_header2()
29 29 - GApplication::log_header3()
  30 +- GLog::is_open()
30 31  
31 32 The following methods have been removed:
32 33 - ...
... ... @@ -69,6 +70,9 @@ pointer in the second instance became invalid. This has been fixed by
69 70 duplicating the file descriptor and opening the log file in the copied
70 71 instance using the duplicated descriptor. This solves the problems (#1823).
71 72  
  73 +A GLog::is_open() method has been added to assess whether a log file is
  74 +actually opened (#1837).
  75 +
72 76  
73 77 5. Base module
74 78 --------------
... ...
README.md
1 1 GammaLib information
2 2 ====================
3   -* Version: 1.2.0.dev1 (4 August 2016)
  3 +* Version: 1.2.0.dev1 (5 August 2016)
4 4 * Author: Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu)
5 5  
6 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/)
... ...
include/GLog.hpp
... ... @@ -86,6 +86,7 @@ public:
86 86 void clear(void);
87 87 int size(void) const;
88 88 std::string classname(void) const;
  89 + bool is_open(void) const;
89 90 void open(const GFilename& filename, const bool& clobber = false);
90 91 void close(void);
91 92 void flush(const bool& force = false);
... ... @@ -147,6 +148,18 @@ std::string GLog::classname(void) const
147 148  
148 149  
149 150 /***********************************************************************//**
  151 + * @brief Signal that log file is open
  152 + *
  153 + * @return True if log file is open, false otherwise.
  154 + ***************************************************************************/
  155 +inline
  156 +bool GLog::is_open(void) const
  157 +{
  158 + return (m_file != NULL);
  159 +}
  160 +
  161 +
  162 +/***********************************************************************//**
150 163 * @brief Write string as centred header into logger
151 164 *
152 165 * @param[in] arg Header string.
... ...
pyext/GLog.i
... ... @@ -47,6 +47,7 @@ public:
47 47 void clear(void);
48 48 int size(void) const;
49 49 std::string classname(void) const;
  50 + bool is_open(void) const;
50 51 void open(const GFilename& filename, const bool& clobber = false);
51 52 void close(void);
52 53 void flush(const bool& force = false);
... ...
src/app/GApplication.cpp
... ... @@ -332,7 +332,10 @@ void GApplication::logFileOpen(const bool& clobber)
332 332 // Initialise the application logger
333 333 log.open(log_filename(), clobber);
334 334  
335   - }
  335 + // Write header into log file
  336 + log_header();
  337 +
  338 + } // endif: file name was not empty
336 339  
337 340 // Set logger chattiness
338 341 set_log_chatter();
... ... @@ -349,11 +352,16 @@ void GApplication::logFileOpen(const bool& clobber)
349 352 ***************************************************************************/
350 353 void GApplication::logFileClose(void)
351 354 {
352   - // Put trailer in log file
353   - log_trailer();
  355 + // Continue only if log file is open
  356 + if (log.is_open()) {
  357 +
  358 + // Write trailer into log file
  359 + log_trailer();
354 360  
355   - // Close log file
356   - log.close();
  361 + // Close log file
  362 + log.close();
  363 +
  364 + } // endif: log file was open
357 365  
358 366 // Return
359 367 return;
... ... @@ -872,11 +880,8 @@ void GApplication::free_members(void)
872 880 // Save application parameters
873 881 m_pars.save(par_filename());
874 882  
875   - // Put trailer in log file
876   - log_trailer();
877   -
878 883 // Close log file
879   - log.close();
  884 + logFileClose();
880 885  
881 886 // Return
882 887 return;
... ...
src/app/GLog.cpp
... ... @@ -554,9 +554,18 @@ void GLog::init_members(void)
554 554 * @brief Copy class members
555 555 *
556 556 * @param[in] log Logger.
  557 + *
  558 + * Copy all class members from @p log to the current logger instance. This
  559 + * method will flush the buffer of @p log before copying.
557 560 ***************************************************************************/
558 561 void GLog::copy_members(const GLog& log)
559 562 {
  563 + // Force flushing the buffer before doing the copy. This assures that the
  564 + // log file is left in a clean state, and in particular, that logging
  565 + // will be done in order. We have to circument const correctness for
  566 + // doing this.
  567 + const_cast<GLog*>(&log)->flush(true);
  568 +
560 569 // Copy attributes
561 570 m_max_length = log.m_max_length;
562 571 m_indent = log.m_indent;
... ... @@ -644,6 +653,9 @@ void GLog::flush(const bool&amp; force)
644 653  
645 654 } // endwhile: flush until empty
646 655  
  656 + // And now flush the kernel buffer
  657 + std::fflush(m_file);
  658 +
647 659 } // endif: flush was required
648 660  
649 661 // Return
... ...
test/test_GApplication.cpp
... ... @@ -381,7 +381,6 @@ void TestGApplication::test_GApplication(void)
381 381 "Check application log file name");
382 382  
383 383 // Write something into the logfile and close it
384   - app1.log_header();
385 384 app1.log_string(SILENT, "Silent", false);
386 385 app1.log_string(TERSE, "Terse", false);
387 386 app1.log_string(NORMAL, "Normal", false);
... ...