Commit 7c9f515a5b45cd4669551aab22bea57fed5ad780

Authored by Jürgen Knödlseder
1 parent 7018091c

Add GLog::written_size() and rename GLog::max_size() to GLog::buffer_size()

ChangeLog
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 * Version 1.2.0 released 3 * Version 1.2.0 released
4 ========================= 4 =========================
5 5
6 - Add GLog::is_open() and GLog::is_empty() methods (#1837) 6 + Add GLog is_open(), is_empty() and written_size() methods (#1837)
7 Fix invalid pointer problem in GLog copies (#1823) 7 Fix invalid pointer problem in GLog copies (#1823)
8 Fix GSkyMap::publish() bug for empty sky maps (#1835) 8 Fix GSkyMap::publish() bug for empty sky maps (#1835)
9 Fix loss of application name and version (#1835) 9 Fix loss of application name and version (#1835)
@@ -29,12 +29,14 @@ The following methods have been added: @@ -29,12 +29,14 @@ The following methods have been added:
29 - GApplication::log_header3() 29 - GApplication::log_header3()
30 - GLog::is_open() 30 - GLog::is_open()
31 - GLog::is_empty() 31 - GLog::is_empty()
  32 +- GLog::written_size()
32 33
33 The following methods have been removed: 34 The following methods have been removed:
34 - ... 35 - ...
35 36
36 The following methods have been renamed: 37 The following methods have been renamed:
37 - GModelSpectralPlawPhotonFlux::flux(), was GModelSpectralPlaw2::integral() 38 - GModelSpectralPlawPhotonFlux::flux(), was GModelSpectralPlaw2::integral()
  39 +- GLog::buffer_size(), was GLog::max_size()
38 40
39 The parameters for the following methods have been changed: 41 The parameters for the following methods have been changed:
40 - GApplication::log_parameters() now has a mandatory GChatter argument 42 - GApplication::log_parameters() now has a mandatory GChatter argument
@@ -78,6 +80,9 @@ a log file is actually empty (#1837). @@ -78,6 +80,9 @@ a log file is actually empty (#1837).
78 The GLog::size() method now returns the actual size of the log file, including 80 The GLog::size() method now returns the actual size of the log file, including
79 the number of characters on disk. 81 the number of characters on disk.
80 82
  83 +The GLog::max_size() method has been renamed to GLog::buffer_size since this
  84 +is more explicit (#1837).
  85 +
81 86
82 5. Base module 87 5. Base module
83 -------------- 88 --------------
include/GLog.hpp
@@ -55,7 +55,7 @@ @@ -55,7 +55,7 @@
55 * 55 *
56 * The logger interface implements an internal character buffer that is 56 * The logger interface implements an internal character buffer that is
57 * flushed once a maximum size parameter is exceeded. The buffer limit can 57 * flushed once a maximum size parameter is exceeded. The buffer limit can
58 - * be modified using the max_size() method; by default it is set to 8192 58 + * be modified using the buffer_size() method; by default it is set to 8192
59 * characters. The logger allows prepending of the current date and the task 59 * characters. The logger allows prepending of the current date and the task
60 * name. 60 * name.
61 ***************************************************************************/ 61 ***************************************************************************/
@@ -85,6 +85,7 @@ public: @@ -85,6 +85,7 @@ public:
85 // Methods 85 // Methods
86 void clear(void); 86 void clear(void);
87 long int size(void) const; 87 long int size(void) const;
  88 + long int written_size(void) const;
88 std::string classname(void) const; 89 std::string classname(void) const;
89 bool is_open(void) const; 90 bool is_open(void) const;
90 bool is_empty(void) const; 91 bool is_empty(void) const;
@@ -96,7 +97,7 @@ public: @@ -96,7 +97,7 @@ public:
96 void cout(const bool& flag); 97 void cout(const bool& flag);
97 void cerr(const bool& flag); 98 void cerr(const bool& flag);
98 void name(const std::string& name); 99 void name(const std::string& name);
99 - void max_size(const int& size); 100 + void buffer_size(const int& size);
100 void indent(const int& indent); 101 void indent(const int& indent);
101 void chatter(const GChatter& chatter); 102 void chatter(const GChatter& chatter);
102 void header0(const std::string& arg); 103 void header0(const std::string& arg);
@@ -107,7 +108,7 @@ public: @@ -107,7 +108,7 @@ public:
107 const bool& cout(void) const; 108 const bool& cout(void) const;
108 const bool& cerr(void) const; 109 const bool& cerr(void) const;
109 const std::string& name(void) const; 110 const std::string& name(void) const;
110 - const int& max_size(void) const; 111 + const int& buffer_size(void) const;
111 const int& indent(void) const; 112 const int& indent(void) const;
112 const GChatter& chatter(void) const; 113 const GChatter& chatter(void) const;
113 const GFilename& filename(void) const; 114 const GFilename& filename(void) const;
@@ -123,17 +124,18 @@ protected: @@ -123,17 +124,18 @@ protected:
123 void append(std::string arg); 124 void append(std::string arg);
124 125
125 // Protected data members 126 // Protected data members
126 - int m_max_length; //!< Maximum buffer length  
127 - int m_indent; //!< Indentation of text  
128 - bool m_stdout; //!< Dump in standard output  
129 - bool m_stderr; //!< Dump in standard error  
130 - bool m_use_date; //!< Dump date in prefix  
131 - bool m_linestart; //!< Signals that buffer is at line start  
132 - FILE* m_file; //!< Log file pointer  
133 - GFilename m_filename; //!< Log file name  
134 - std::string m_name; //!< Name for prefix  
135 - std::string m_buffer; //!< Output string buffer  
136 - GChatter m_chatter; //!< Chattiness for print() method 127 + int m_max_length; //!< Maximum buffer length
  128 + int m_indent; //!< Indentation of text
  129 + long int m_written_size; //!< Number of char's written though this logger
  130 + bool m_stdout; //!< Dump in standard output
  131 + bool m_stderr; //!< Dump in standard error
  132 + bool m_use_date; //!< Dump date in prefix
  133 + bool m_linestart; //!< Signals that buffer is at line start
  134 + FILE* m_file; //!< Log file pointer
  135 + GFilename m_filename; //!< Log file name
  136 + std::string m_name; //!< Name for prefix
  137 + std::string m_buffer; //!< Output string buffer
  138 + GChatter m_chatter; //!< Chattiness for print() method
137 }; 139 };
138 140
139 141
@@ -150,6 +152,18 @@ std::string GLog::classname(void) const @@ -150,6 +152,18 @@ std::string GLog::classname(void) const
150 152
151 153
152 /***********************************************************************//** 154 /***********************************************************************//**
  155 + * @brief Return number of characters written through this logger
  156 + *
  157 + * @return Number of characters written.
  158 + ***************************************************************************/
  159 +inline
  160 +long int GLog::written_size(void) const
  161 +{
  162 + return (m_written_size);
  163 +}
  164 +
  165 +
  166 +/***********************************************************************//**
153 * @brief Signal that log file is open 167 * @brief Signal that log file is open
154 * 168 *
155 * @return True if log file is open, false otherwise. 169 * @return True if log file is open, false otherwise.
@@ -302,19 +316,15 @@ void GLog::name(const std::string&amp; name) @@ -302,19 +316,15 @@ void GLog::name(const std::string&amp; name)
302 316
303 317
304 /***********************************************************************//** 318 /***********************************************************************//**
305 - * @brief Set the maximum buffer size  
306 - *  
307 - * @param[in] size Maximum buffer size. 319 + * @brief Set the buffer size
308 * 320 *
309 - * Set the maximum number of characters allowed in the internal buffer before  
310 - * the buffer is flushed into the specified streams or file. 321 + * @param[in] size Buffer size.
311 * 322 *
312 - * @todo No maximum buffer size checking is performed. This could be  
313 - * implemented but is not really crucial since the physical buffer size can  
314 - * indeed be larger than this maximum size. 323 + * Set the number of characters allowed in the internal buffer before the
  324 + * buffer is flushed into the specified streams or file.
315 ***************************************************************************/ 325 ***************************************************************************/
316 inline 326 inline
317 -void GLog::max_size(const int& size) 327 +void GLog::buffer_size(const int& size)
318 { 328 {
319 m_max_length = size; 329 m_max_length = size;
320 return; 330 return;
@@ -421,15 +431,15 @@ const std::string&amp; GLog::name(void) const @@ -421,15 +431,15 @@ const std::string&amp; GLog::name(void) const
421 431
422 432
423 /***********************************************************************//** 433 /***********************************************************************//**
424 - * @brief Return the maximum buffer size 434 + * @brief Return the buffer size
425 * 435 *
426 - * @return Maximum buffer size. 436 + * @return Buffer size.
427 * 437 *
428 - * Returns the maximum number of characters allowed in the internal buffer 438 + * Returns the number of characters that are allowed in the internal buffer
429 * before the buffer is flushed into the specified streams or file. 439 * before the buffer is flushed into the specified streams or file.
430 ***************************************************************************/ 440 ***************************************************************************/
431 inline 441 inline
432 -const int& GLog::max_size(void) const 442 +const int& GLog::buffer_size(void) const
433 { 443 {
434 return m_max_length; 444 return m_max_length;
435 } 445 }
pyext/GLog.i
@@ -46,6 +46,7 @@ public: @@ -46,6 +46,7 @@ public:
46 // Methods 46 // Methods
47 void clear(void); 47 void clear(void);
48 long int size(void) const; 48 long int size(void) const;
  49 + long int written_size(void) const;
49 std::string classname(void) const; 50 std::string classname(void) const;
50 bool is_open(void) const; 51 bool is_open(void) const;
51 bool is_empty(void) const; 52 bool is_empty(void) const;
@@ -57,7 +58,7 @@ public: @@ -57,7 +58,7 @@ public:
57 void cout(const bool& flag); 58 void cout(const bool& flag);
58 void cerr(const bool& flag); 59 void cerr(const bool& flag);
59 void name(const std::string& name); 60 void name(const std::string& name);
60 - void max_size(const int& size); 61 + void buffer_size(const int& size);
61 void indent(const int& indent); 62 void indent(const int& indent);
62 void chatter(const GChatter& chatter); 63 void chatter(const GChatter& chatter);
63 void header0(const std::string& arg); 64 void header0(const std::string& arg);
@@ -68,7 +69,7 @@ public: @@ -68,7 +69,7 @@ public:
68 const bool& cout(void) const; 69 const bool& cout(void) const;
69 const bool& cerr(void) const; 70 const bool& cerr(void) const;
70 const std::string& name(void) const; 71 const std::string& name(void) const;
71 - const int& max_size(void) const; 72 + const int& buffer_size(void) const;
72 const int& indent(void) const; 73 const int& indent(void) const;
73 const GChatter& chatter(void) const; 74 const GChatter& chatter(void) const;
74 const GFilename& filename(void) const; 75 const GFilename& filename(void) const;
src/app/GApplication.cpp
@@ -348,28 +348,23 @@ void GApplication::logFileOpen(const bool&amp; clobber) @@ -348,28 +348,23 @@ void GApplication::logFileOpen(const bool&amp; clobber)
348 /***********************************************************************//** 348 /***********************************************************************//**
349 * @brief Close log file 349 * @brief Close log file
350 * 350 *
351 - * Writer trailer into the log file and close application log file.  
352 - *  
353 - * The trailer is only written in case that there is some content in the  
354 - * log file. 351 + * Close the log file. In case that some characters have been written
  352 + * through the logger a trailer will be appended to the logger before
  353 + * closing the log file. The trailer informs about the computation time
  354 + * used by the application.
355 ***************************************************************************/ 355 ***************************************************************************/
356 void GApplication::logFileClose(void) 356 void GApplication::logFileClose(void)
357 { 357 {
358 - // Continue only if log file is open  
359 - if (log.is_open()) {  
360 -  
361 - // If log file is not empty then write the trailer into log file.  
362 - // This kluge avoids writing a trailer in an empty log file that  
363 - // is for example occuring in copy operations.  
364 - if (!log.is_empty()) { 358 + // Continue only if log file is open and if something has been written
  359 + // through this logger. This avoid writing trailers for logger than
  360 + // have not been used.
  361 + if (log.is_open() && (log.written_size() > 0)) {
365 362
366 - // Put line feed  
367 - log << std::endl; 363 + // Write line feed before trailer into logger
  364 + log << std::endl;
368 365
369 - // Write trailer into logger  
370 - log_trailer();  
371 -  
372 - } // endif: logger was not empty 366 + // Write trailer into logger
  367 + log_trailer();
373 368
374 // Close log file 369 // Close log file
375 log.close(); 370 log.close();
src/app/GLog.cpp
@@ -466,7 +466,6 @@ void GLog::clear(void) @@ -466,7 +466,6 @@ void GLog::clear(void)
466 ***************************************************************************/ 466 ***************************************************************************/
467 long int GLog::size(void) const 467 long int GLog::size(void) const
468 { 468 {
469 -std::cout << "GLog::size m_buffer.size()=" << m_buffer.size() << std::endl;  
470 // Determine the number of characters written to disk 469 // Determine the number of characters written to disk
471 long int size = (m_file != NULL) ? std::ftell(m_file) : 0; 470 long int size = (m_file != NULL) ? std::ftell(m_file) : 0;
472 471
@@ -542,17 +541,18 @@ void GLog::close(void) @@ -542,17 +541,18 @@ void GLog::close(void)
542 void GLog::init_members(void) 541 void GLog::init_members(void)
543 { 542 {
544 // Initialise members 543 // Initialise members
545 - m_max_length = 8192;  
546 - m_indent = 0;  
547 - m_stdout = false;  
548 - m_stderr = false;  
549 - m_use_date = false;  
550 - m_linestart = true;  
551 - m_file = NULL; 544 + m_max_length = 8192;
  545 + m_indent = 0;
  546 + m_written_size = 0;
  547 + m_stdout = false;
  548 + m_stderr = false;
  549 + m_use_date = false;
  550 + m_linestart = true;
  551 + m_file = NULL;
  552 + m_chatter = NORMAL;
552 m_filename.clear(); 553 m_filename.clear();
553 m_name.clear(); 554 m_name.clear();
554 m_buffer.clear(); 555 m_buffer.clear();
555 - m_chatter = NORMAL;  
556 556
557 // Return 557 // Return
558 return; 558 return;
@@ -838,6 +838,9 @@ void GLog::append(std::string arg) @@ -838,6 +838,9 @@ void GLog::append(std::string arg)
838 // Add string to buffer 838 // Add string to buffer
839 m_buffer.append(arg); 839 m_buffer.append(arg);
840 840
  841 + // Increment written number of characters
  842 + m_written_size += arg.size();
  843 +
841 // Flush Buffer 844 // Flush Buffer
842 flush(); 845 flush();
843 846
src/test/GTestSuite.cpp
@@ -898,7 +898,7 @@ void GTestSuite::init_members(void) @@ -898,7 +898,7 @@ void GTestSuite::init_members(void)
898 898
899 // Set logger parameters 899 // Set logger parameters
900 cout(true); 900 cout(true);
901 - m_log.max_size(1); 901 + m_log.buffer_size(1);
902 902
903 // Return 903 // Return
904 return; 904 return;
src/test/GTestSuites.cpp
@@ -550,7 +550,7 @@ void GTestSuites::init_members(void) @@ -550,7 +550,7 @@ void GTestSuites::init_members(void)
550 m_log.clear(); 550 m_log.clear();
551 551
552 // Set logger parameters 552 // Set logger parameters
553 - m_log.max_size(1); 553 + m_log.buffer_size(1);
554 m_log.cout(true); 554 m_log.cout(true);
555 555
556 // Return 556 // Return
test/test_GApplication.cpp
@@ -147,6 +147,10 @@ void TestGApplication::test_GLog(void) @@ -147,6 +147,10 @@ void TestGApplication::test_GLog(void)
147 test_value(log1.size(), 13, "Check logger 1 size in memory"); 147 test_value(log1.size(), 13, "Check logger 1 size in memory");
148 test_value(log2.size(), 15, "Check logger 2 size in memory"); 148 test_value(log2.size(), 15, "Check logger 2 size in memory");
149 149
  150 + // Check the written sizes of the loggers.
  151 + test_value(log1.written_size(), 13, "Check logger 1 written size");
  152 + test_value(log2.written_size(), 6, "Check logger 2 written size");
  153 +
150 // Flush both loggers. Each logger flushes what he has. 154 // Flush both loggers. Each logger flushes what he has.
151 log1.flush(true); 155 log1.flush(true);
152 log2.flush(true); 156 log2.flush(true);