diff --git a/ChangeLog b/ChangeLog index 9fb2193..13b33e4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,7 @@ * Version 1.2.0 released ========================= - Add GLog::is_open() and GLog::is_empty() methods (#1837) + Add GLog is_open(), is_empty() and written_size() methods (#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 6a02702..2139e4f 100644 --- a/NEWS +++ b/NEWS @@ -29,12 +29,14 @@ The following methods have been added: - GApplication::log_header3() - GLog::is_open() - GLog::is_empty() +- GLog::written_size() The following methods have been removed: - ... The following methods have been renamed: - GModelSpectralPlawPhotonFlux::flux(), was GModelSpectralPlaw2::integral() +- GLog::buffer_size(), was GLog::max_size() The parameters for the following methods have been changed: - GApplication::log_parameters() now has a mandatory GChatter argument @@ -78,6 +80,9 @@ a log file is actually empty (#1837). The GLog::size() method now returns the actual size of the log file, including the number of characters on disk. +The GLog::max_size() method has been renamed to GLog::buffer_size since this +is more explicit (#1837). + 5. Base module -------------- diff --git a/include/GLog.hpp b/include/GLog.hpp index 713ceb8..e743c62 100644 --- a/include/GLog.hpp +++ b/include/GLog.hpp @@ -55,7 +55,7 @@ * * The logger interface implements an internal character buffer that is * flushed once a maximum size parameter is exceeded. The buffer limit can - * be modified using the max_size() method; by default it is set to 8192 + * be modified using the buffer_size() method; by default it is set to 8192 * characters. The logger allows prepending of the current date and the task * name. ***************************************************************************/ @@ -85,6 +85,7 @@ public: // Methods void clear(void); long int size(void) const; + long int written_size(void) const; std::string classname(void) const; bool is_open(void) const; bool is_empty(void) const; @@ -96,7 +97,7 @@ public: void cout(const bool& flag); void cerr(const bool& flag); void name(const std::string& name); - void max_size(const int& size); + void buffer_size(const int& size); void indent(const int& indent); void chatter(const GChatter& chatter); void header0(const std::string& arg); @@ -107,7 +108,7 @@ public: const bool& cout(void) const; const bool& cerr(void) const; const std::string& name(void) const; - const int& max_size(void) const; + const int& buffer_size(void) const; const int& indent(void) const; const GChatter& chatter(void) const; const GFilename& filename(void) const; @@ -123,17 +124,18 @@ protected: void append(std::string arg); // Protected data members - int m_max_length; //!< Maximum buffer length - int m_indent; //!< Indentation of text - bool m_stdout; //!< Dump in standard output - bool m_stderr; //!< Dump in standard error - bool m_use_date; //!< Dump date in prefix - bool m_linestart; //!< Signals that buffer is at line start - FILE* m_file; //!< Log file pointer - GFilename m_filename; //!< Log file name - std::string m_name; //!< Name for prefix - std::string m_buffer; //!< Output string buffer - GChatter m_chatter; //!< Chattiness for print() method + int m_max_length; //!< Maximum buffer length + int m_indent; //!< Indentation of text + long int m_written_size; //!< Number of char's written though this logger + bool m_stdout; //!< Dump in standard output + bool m_stderr; //!< Dump in standard error + bool m_use_date; //!< Dump date in prefix + bool m_linestart; //!< Signals that buffer is at line start + FILE* m_file; //!< Log file pointer + GFilename m_filename; //!< Log file name + std::string m_name; //!< Name for prefix + std::string m_buffer; //!< Output string buffer + GChatter m_chatter; //!< Chattiness for print() method }; @@ -150,6 +152,18 @@ std::string GLog::classname(void) const /***********************************************************************//** + * @brief Return number of characters written through this logger + * + * @return Number of characters written. + ***************************************************************************/ +inline +long int GLog::written_size(void) const +{ + return (m_written_size); +} + + +/***********************************************************************//** * @brief Signal that log file is open * * @return True if log file is open, false otherwise. @@ -302,19 +316,15 @@ void GLog::name(const std::string& name) /***********************************************************************//** - * @brief Set the maximum buffer size - * - * @param[in] size Maximum buffer size. + * @brief Set the buffer size * - * Set the maximum number of characters allowed in the internal buffer before - * the buffer is flushed into the specified streams or file. + * @param[in] size Buffer size. * - * @todo No maximum buffer size checking is performed. This could be - * implemented but is not really crucial since the physical buffer size can - * indeed be larger than this maximum size. + * Set the number of characters allowed in the internal buffer before the + * buffer is flushed into the specified streams or file. ***************************************************************************/ inline -void GLog::max_size(const int& size) +void GLog::buffer_size(const int& size) { m_max_length = size; return; @@ -421,15 +431,15 @@ const std::string& GLog::name(void) const /***********************************************************************//** - * @brief Return the maximum buffer size + * @brief Return the buffer size * - * @return Maximum buffer size. + * @return Buffer size. * - * Returns the maximum number of characters allowed in the internal buffer + * Returns the number of characters that are allowed in the internal buffer * before the buffer is flushed into the specified streams or file. ***************************************************************************/ inline -const int& GLog::max_size(void) const +const int& GLog::buffer_size(void) const { return m_max_length; } diff --git a/pyext/GLog.i b/pyext/GLog.i index 4b2c5b1..a14ebff 100644 --- a/pyext/GLog.i +++ b/pyext/GLog.i @@ -46,6 +46,7 @@ public: // Methods void clear(void); long int size(void) const; + long int written_size(void) const; std::string classname(void) const; bool is_open(void) const; bool is_empty(void) const; @@ -57,7 +58,7 @@ public: void cout(const bool& flag); void cerr(const bool& flag); void name(const std::string& name); - void max_size(const int& size); + void buffer_size(const int& size); void indent(const int& indent); void chatter(const GChatter& chatter); void header0(const std::string& arg); @@ -68,7 +69,7 @@ public: const bool& cout(void) const; const bool& cerr(void) const; const std::string& name(void) const; - const int& max_size(void) const; + const int& buffer_size(void) const; const int& indent(void) const; const GChatter& chatter(void) const; const GFilename& filename(void) const; diff --git a/src/app/GApplication.cpp b/src/app/GApplication.cpp index 81e3dc2..31be7b6 100644 --- a/src/app/GApplication.cpp +++ b/src/app/GApplication.cpp @@ -348,28 +348,23 @@ void GApplication::logFileOpen(const bool& clobber) /***********************************************************************//** * @brief Close log file * - * Writer trailer into the log file and close application log file. - * - * The trailer is only written in case that there is some content in the - * log file. + * Close the log file. In case that some characters have been written + * through the logger a trailer will be appended to the logger before + * closing the log file. The trailer informs about the computation time + * used by the application. ***************************************************************************/ void GApplication::logFileClose(void) { - // Continue only if log file is open - if (log.is_open()) { - - // If log file is not empty then write the trailer into log file. - // This kluge avoids writing a trailer in an empty log file that - // is for example occuring in copy operations. - if (!log.is_empty()) { + // Continue only if log file is open and if something has been written + // through this logger. This avoid writing trailers for logger than + // have not been used. + if (log.is_open() && (log.written_size() > 0)) { - // Put line feed - log << std::endl; + // Write line feed before trailer into logger + log << std::endl; - // Write trailer into logger - log_trailer(); - - } // endif: logger was not empty + // Write trailer into logger + log_trailer(); // Close log file log.close(); diff --git a/src/app/GLog.cpp b/src/app/GLog.cpp index 5200d3e..19d2ce6 100644 --- a/src/app/GLog.cpp +++ b/src/app/GLog.cpp @@ -466,7 +466,6 @@ void GLog::clear(void) ***************************************************************************/ long int GLog::size(void) const { -std::cout << "GLog::size m_buffer.size()=" << m_buffer.size() << std::endl; // Determine the number of characters written to disk long int size = (m_file != NULL) ? std::ftell(m_file) : 0; @@ -542,17 +541,18 @@ void GLog::close(void) void GLog::init_members(void) { // Initialise members - m_max_length = 8192; - m_indent = 0; - m_stdout = false; - m_stderr = false; - m_use_date = false; - m_linestart = true; - m_file = NULL; + m_max_length = 8192; + m_indent = 0; + m_written_size = 0; + m_stdout = false; + m_stderr = false; + m_use_date = false; + m_linestart = true; + m_file = NULL; + m_chatter = NORMAL; m_filename.clear(); m_name.clear(); m_buffer.clear(); - m_chatter = NORMAL; // Return return; @@ -838,6 +838,9 @@ void GLog::append(std::string arg) // Add string to buffer m_buffer.append(arg); + // Increment written number of characters + m_written_size += arg.size(); + // Flush Buffer flush(); diff --git a/src/test/GTestSuite.cpp b/src/test/GTestSuite.cpp index 98e0bca..c24e2ad 100644 --- a/src/test/GTestSuite.cpp +++ b/src/test/GTestSuite.cpp @@ -898,7 +898,7 @@ void GTestSuite::init_members(void) // Set logger parameters cout(true); - m_log.max_size(1); + m_log.buffer_size(1); // Return return; diff --git a/src/test/GTestSuites.cpp b/src/test/GTestSuites.cpp index 875fcf6..a075449 100644 --- a/src/test/GTestSuites.cpp +++ b/src/test/GTestSuites.cpp @@ -550,7 +550,7 @@ void GTestSuites::init_members(void) m_log.clear(); // Set logger parameters - m_log.max_size(1); + m_log.buffer_size(1); m_log.cout(true); // Return diff --git a/test/test_GApplication.cpp b/test/test_GApplication.cpp index 5d3af7f..fda564f 100644 --- a/test/test_GApplication.cpp +++ b/test/test_GApplication.cpp @@ -147,6 +147,10 @@ void TestGApplication::test_GLog(void) test_value(log1.size(), 13, "Check logger 1 size in memory"); test_value(log2.size(), 15, "Check logger 2 size in memory"); + // Check the written sizes of the loggers. + test_value(log1.written_size(), 13, "Check logger 1 written size"); + test_value(log2.written_size(), 6, "Check logger 2 written size"); + // Flush both loggers. Each logger flushes what he has. log1.flush(true); log2.flush(true);