bes  Updated for version 3.17.4
BESLog.h
1 // BESLog.h
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // pwest Patrick West <pwest@ucar.edu>
31 // jgarcia Jose Garcia <jgarcia@ucar.edu>
32 
33 #ifndef BESLog_h_
34 #define BESLog_h_ 1
35 
36 #include <fstream>
37 #include <string>
38 
39 // Note that the BESLog::operator<<() methods will prefix output with
40 // the time and PID by checking for the flush and endl stream operators.
41 #define LOG(x) do { *(BESLog::TheLog()) << x ; } while( 0 )
42 #define VERBOSE(x) do { if (BESLog::TheLog()->is_verbose()) *(BESLog::TheLog()) << x ; } while( 0 )
43 
44 #include "BESObj.h"
45 
87 class BESLog: public BESObj {
88 private:
89  static BESLog * _instance;
90  int _flushed;
91  std::ofstream * _file_buffer;
92  std::string _file_name;
93  // Flag to indicate the object is not routing data to its associated stream
94  int _suspended;
95  // Flag to indicate whether to log verbose messages
96  bool _verbose;
97 protected:
98  BESLog();
99 
100  // Dumps the current system time.
101  void dump_time();
102 public:
103  ~BESLog();
104 
110  void suspend()
111  {
112  _suspended = 1;
113  }
114 
120  void resume()
121  {
122  _suspended = 0;
123  }
124 
131  void verbose_on()
132  {
133  _verbose = true;
134  }
135 
141  void verbose_off()
142  {
143  _verbose = false;
144  }
145 
161  bool is_verbose()
162  {
163  return _verbose;
164  }
165 
167  typedef std::ios& (*p_ios_manipulator)(std::ios&);
169  typedef std::ostream& (*p_ostream_manipulator)(std::ostream&);
170 
171  BESLog& operator <<(std::string&);
172  BESLog& operator <<(const std::string&);
173  BESLog& operator <<(char*);
174  BESLog& operator <<(const char*);
175  BESLog& operator <<(int);
176  BESLog& operator <<(char);
177  BESLog& operator <<(long);
178  BESLog& operator <<(unsigned long);
179  BESLog& operator <<(double);
180 
183 
184  virtual void dump(std::ostream &strm) const;
185 
186  static BESLog *TheLog();
187 
188  // I added this so that it's easy to route the BESDebug messages to the
189  // log file. This will enable the Admin Interface to display the contents
190  // of those debug messages when it displays the log file. jhrg
191  std::ostream *get_log_ostream()
192  {
193  return _file_buffer;
194  }
195 };
196 
197 #endif // BESLog_h_
198 
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESLog.cc:294
~BESLog()
Cleans up the logging mechanism.
Definition: BESLog.cc:104
BESLog & operator<<(std::string &)
Overloaded inserter that writes the specified string.
Definition: BESLog.cc:138
void verbose_off()
turns off verbose logging
Definition: BESLog.h:141
bool is_verbose()
Returns true if verbose logging is requested.
Definition: BESLog.h:161
void resume()
Resumes logging after being suspended.
Definition: BESLog.h:120
Base object for bes objects.
Definition: BESObj.h:52
void suspend()
Suspend logging of any information until resumed.
Definition: BESLog.h:110
void verbose_on()
turn on verbose logging
Definition: BESLog.h:131
std::ostream &(* p_ostream_manipulator)(std::ostream &)
Defines a data type p_std::ostream_manipulator "pointer to function that takes std::ostream& and retu...
Definition: BESLog.h:169
void dump_time()
Protected method that dumps the date/time to the log file.
Definition: BESLog.cc:117
BESLog()
constructor that sets up logging for the application.
Definition: BESLog.cc:66
Provides a mechanism for applications to log information to an external file.
Definition: BESLog.h:87
std::ios &(* p_ios_manipulator)(std::ios &)
Defines a data type p_ios_manipulator "pointer to function that takes ios& and returns ios&"...
Definition: BESLog.h:167