OPeNDAP Hyrax Back End Server (BES)  Updated for version 3.8.3
BESLog.h
Go to the documentation of this file.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 using std::ofstream ;
40 using std::ios ;
41 using std::ostream ;
42 using std::string ;
43 
44 #include "BESObj.h"
45 
87 class BESLog : public BESObj
88 {
89 private:
90  static BESLog * _instance ;
91  int _flushed ;
92  ofstream * _file_buffer ;
93  string _file_name ;
94  // Flag to indicate the object is not routing data to its associated stream
95  int _suspended ;
96  // Flag to indicate whether to log verbose messages
97  bool _verbose ;
98 protected:
99  BESLog();
100 
101  // Dumps the current system time.
102  void dump_time() ;
103 public:
104  ~BESLog();
105 
111  void suspend()
112  {
113  _suspended = 1 ;
114  }
115 
121  void resume()
122  {
123  _suspended = 0 ;
124  }
125 
132  void verbose_on()
133  {
134  _verbose = true ;
135  }
136 
142  void verbose_off()
143  {
144  _verbose = false ;
145  }
146 
162  bool is_verbose()
163  {
164  return _verbose ;
165  }
166 
168  typedef ios& (*p_ios_manipulator) (ios&);
170  typedef ostream& (*p_ostream_manipulator) (ostream&);
171 
172  BESLog& operator << (string&);
173  BESLog& operator << (const string&);
174  BESLog& operator << (char*);
175  BESLog& operator << (const char*);
176  BESLog& operator << (int);
177  BESLog& operator << (char);
178  BESLog& operator << (long);
179  BESLog& operator << (unsigned long);
180  BESLog& operator << (double);
181 
184 
185  virtual void dump( ostream &strm ) const ;
186 
187  static BESLog *TheLog() ;
188 
189  // I added this so that it's easy to route the BESDebug messages to the
190  // log file. This will enable the Admin Interface to display the contents
191  // of those debug messages when it displays the log file. jhrg
192  ostream *get_log_ostream() { return _file_buffer; }
193 };
194 
195 #endif // BESLog_h_
196 
~BESLog()
Cleans up the logging mechanism.
Definition: BESLog.cc:115
void verbose_off()
turns off verbose logging
Definition: BESLog.h:142
bool is_verbose()
Returns true if verbose logging is requested.
Definition: BESLog.h:162
void resume()
Resumes logging after being suspended.
Definition: BESLog.h:121
ostream &(* p_ostream_manipulator)(ostream &)
Defines a data type p_ostream_manipulator "pointer to function that takes ostream& and returns ostrea...
Definition: BESLog.h:170
BESLog & operator<<(string &)
Overloaded inserter that writes the specified string.
Definition: BESLog.cc:148
Base object for bes objects.
Definition: BESObj.h:52
void suspend()
Suspend logging of any information until resumed.
Definition: BESLog.h:111
ios &(* p_ios_manipulator)(ios &)
Defines a data type p_ios_manipulator "pointer to function that takes ios& and returns ios&"...
Definition: BESLog.h:168
void verbose_on()
turn on verbose logging
Definition: BESLog.h:132
virtual void dump(ostream &strm) const
dumps information about this object
Definition: BESLog.cc:326
static BESLog * TheLog()
Definition: BESLog.cc:347
void dump_time()
Protected method that dumps the date/time to the log file.
Definition: BESLog.cc:129
BESLog()
constructor that sets up logging for the application.
Definition: BESLog.cc:68
Provides a mechanism for applications to log information to an external file.
Definition: BESLog.h:87
ostream * get_log_ostream()
Definition: BESLog.h:192