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
LogDestination.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 LSST Corporation.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
29 
30 #include <boost/shared_ptr.hpp>
31 #include <boost/any.hpp>
32 
33 using namespace std;
34 
35 namespace lsst {
36 namespace pex {
37 namespace logging {
38 
39 //@cond
40 using boost::shared_ptr;
41 
42 /*
43  * @brief create a destination with a threshold.
44  * @param strm the output stream to send messages to. If the pointer
45  * id null, this LogDestination will act as a null-op
46  * destination.
47  * @param formatter the LogFormatter to use to format the messages
48  * @param threshold the minimum volume level required to pass a message
49  * to the stream. If not provided, it would be set
50  * to 0.
51  */
52 LogDestination::LogDestination(ostream *strm,
53  const shared_ptr<LogFormatter>& formatter,
54  int threshold)
55  : _threshold(threshold), _strm(strm), _frmtr(formatter)
56 { }
57 
58 /*
59  * create a copy
60  */
61 LogDestination::LogDestination(const LogDestination& that)
62  : _threshold(that._threshold), _strm(that._strm), _frmtr(that._frmtr)
63 { }
64 
65 /*
66  * delete this destination
67  */
68 LogDestination::~LogDestination() { }
69 
70 /*
71  * copy a destination into this one
72  */
73 LogDestination& LogDestination::operator=(const LogDestination& that) {
74  _threshold = that._threshold;
75  _strm = that._strm;
76  _frmtr = that._frmtr;
77  return *this;
78 }
79 
80 /*
81  * record a given log record to this destinations output stream. The
82  * record will be sent to the stream attached to this class if (a)
83  * there is actually an attached stream, (b) there is an attached
84  * formatter, and (c) the importance level associated with the
85  * record is equal to or greater than the threshold associated
86  * with this destination.
87  * @return true if the record was actually passed to the
88  * associated stream.
89  */
90 bool LogDestination::write(const LogRecord& rec) {
91  if (_strm != 0 && _frmtr.get() != 0 &&
92  rec.getImportance() >= _threshold)
93  {
94  _frmtr->write(_strm, rec);
95  return true;
96  }
97  return false;
98 }
99 
100 //@endcond
101 }}} // end lsst::pex::logging
102 
definition of the LogRecord, RecordProperty and Prop classes
definition of the LogDestination class