LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
LSSTDataManagementBasePackage
LogRecord.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
30 #ifndef LSST_PEX_LOGRECORD_H
31 #define LSST_PEX_LOGRECORD_H
32 
34 
35 #include <boost/shared_ptr.hpp>
36 #include <boost/format.hpp>
37 #include <string>
38 #include <sys/time.h>
39 
40 #define LSST_LP_COMMENT "COMMENT"
41 #define LSST_LP_TIMESTAMP "TIMESTAMP"
42 #define LSST_LP_DATE "DATE"
43 #define LSST_LP_LOG "LOG"
44 #define LSST_LP_LEVEL "LEVEL"
45 
46 namespace lsst {
47 namespace pex {
48 namespace logging {
49 
61 template <class T>
63 public:
64  typedef T ValueType;
65 
71  RecordProperty(const std::string& pname, const T& pvalue)
72  : name(pname), value(pvalue) { }
73 
77  void addTo(lsst::daf::base::PropertySet& set) { set.add(this->name, this->value); }
78 
79  const std::string name;
80  const T& value;
81 };
82 
83 /*
84  * a shorthand version of the RecordProperty class
85  */
86 template <class T>
87 class Prop : public RecordProperty<T> {
88 public:
89  Prop(const std::string& pname, const T& value)
90  : RecordProperty<T>(pname, value) { }
91 };
92 
99 class LogRecord {
100 public:
101 
114  LogRecord(int threshold, int importance, bool showAll=false);
115 
131  LogRecord(int threshold, int importance,
132  const lsst::daf::base::PropertySet& preamble, bool showAll=false);
133 
137  LogRecord(const LogRecord& that)
138  : _send(that._send), _showAll(that._showAll), _vol(that._vol), _data()
139  {
140  _data = that._data->deepCopy();
141  }
142 
146  virtual ~LogRecord();
147 
151  LogRecord& operator=(const LogRecord& that) {
152  _send = that._send;
153  _showAll = that._showAll;
154  _vol = that._vol;
155  _data = that._data;
156  return *this;
157  }
158 
165  void addComment(const std::string& comment) {
166  if (_send) _data->add(LSST_LP_COMMENT, comment);
167  }
168 
173  void addComment(const boost::format& comment) {
174  if (_send) addComment(comment.str());
175  }
176 
180  template <class T>
181  void addProperty(const RecordProperty<T>& property);
182 
186  template <class T>
187  void addProperty(const std::string& name, const T& val);
188 
194  void addProperties(const lsst::daf::base::PropertySet& props);
195 
202  addProperties(*props);
203  }
204 
209  const lsst::daf::base::PropertySet& getProperties() const { return data(); }
210 
216 
221  const lsst::daf::base::PropertySet& data() const { return *_data; }
222 
228 
233  size_t countParamNames() {
234  std::vector<std::string> names = data().paramNames(false);
235  return names.size();
236  }
237 
244  size_t countParamValues() const;
245 
250  int getImportance() const { return _vol; }
251 
257  bool willRecord() const { return _send; }
258 
265  bool willShowAll() const { return _showAll; }
266 
275  void setShowAll(bool yesno) { _showAll = yesno; }
276 
285  void setTimestamp();
286 
299  virtual void setDate();
300 
305  static long long utcnow();
306 
307 protected:
308  LogRecord() : _send(false), _vol(10), _data(new lsst::daf::base::PropertySet()) { }
309 
313  void _init() {
314  if (_send) {
315  _data->set("LEVEL", _vol);
316  setDate();
317  }
318  }
319 
320  bool _send; // true if this record should be sent to the log
321  bool _showAll; // true if there is preference to have all data displayed
322  int _vol; // the importance volume of this message
324 };
325 
326 template <class T>
328  if (_send) property.addTo(_data);
329 }
330 
331 template <class T>
332 void LogRecord::addProperty(const std::string& name, const T& val) {
333  if (_send) data().add(name, val);
334 }
335 
336 
337 
338 }}} // end lsst::pex::logging
339 
340 #endif // end LSST_PEX_LOGRECORD_H
lsst::daf::base::PropertySet & getProperties()
Definition: LogRecord.h:215
std::vector< std::string > paramNames(bool topLevelOnly=true) const
Definition: PropertySet.cc:142
table::Key< std::string > name
Definition: ApCorrMap.cc:71
void addComment(const std::string &comment)
Definition: LogRecord.h:165
void addProperties(const lsst::daf::base::PropertySet::Ptr &props)
Definition: LogRecord.h:201
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
static long long utcnow()
lsst::daf::base::PropertySet & data()
Definition: LogRecord.h:227
const lsst::daf::base::PropertySet & data() const
Definition: LogRecord.h:221
a container for constructing a single Log record
Definition: LogRecord.h:99
RecordProperty(const std::string &pname, const T &pvalue)
Definition: LogRecord.h:71
LogRecord(const LogRecord &that)
Definition: LogRecord.h:137
void addProperty(const RecordProperty< T > &property)
Definition: LogRecord.h:327
lsst::daf::base::PropertySet::Ptr _data
Definition: LogRecord.h:323
#define LSST_LP_COMMENT
Definition: LogRecord.h:40
void addComment(const boost::format &comment)
Definition: LogRecord.h:173
Class for storing generic metadata.
Definition: PropertySet.h:82
void addTo(lsst::daf::base::PropertySet &set)
Definition: LogRecord.h:77
Prop(const std::string &pname, const T &value)
Definition: LogRecord.h:89
size_t countParamValues() const
Interface for PropertySet class.
void setShowAll(bool yesno)
Definition: LogRecord.h:275
void add(std::string const &name, T const &value)
Definition: PropertySet.cc:619
a container for a named data property for a LogRecord
Definition: LogRecord.h:62
void addProperties(const lsst::daf::base::PropertySet &props)
const lsst::daf::base::PropertySet & getProperties() const
Definition: LogRecord.h:209
ImageT val
Definition: CR.cc:154
LogRecord & operator=(const LogRecord &that)
Definition: LogRecord.h:151