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
ScreenLog.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 
28 
29 #include <iostream>
30 #include <boost/shared_ptr.hpp>
31 
32 using namespace std;
33 
34 namespace lsst {
35 namespace pex {
36 namespace logging {
37 
38 //@cond
39 using boost::shared_ptr;
41 
43 // ScreenLog
45 
46 /*
47  * create a Log that will write messages to a given file
48  * @param threshold the importance threshold to set for messages going
49  * to the screen.
50  * @param verbose if true, all message data properties will be printed
51  * to the screen. If false, only the Log name
52  * ("LOG") and the text comment ("COMMENT") will be
53  * printed.
54  * @param preamble a list of data properties that should be included
55  * with every recorded message to the Log. This
56  * constructor will automatically add a property
57  * ("LOG") giving the Log name.
58  */
59 ScreenLog::ScreenLog(const PropertySet& preamble, bool verbose, int threshold)
60  : Log(threshold), _screen(0), _screenFrmtr(0)
61 {
62  configure(verbose);
63  _preamble->combine(preamble.deepCopy());
64 }
65 
66 /*
67  * create a Log that will write messages to a given file
68  * @param threshold the importance threshold to set for messages going
69  * to the screen.
70  * @param verbose if true, all message data properties will be printed
71  * to the screen. If false, only the Log name
72  * ("LOG") and the text comment ("COMMENT") will be
73  * printed.
74  * @param preamble a list of data properties that should be included
75  * with every recorded message to the Log. This
76  * constructor will automatically add a property
77  * ("LOG") giving the Log name.
78  */
79 ScreenLog::ScreenLog(bool verbose, int threshold)
80  : Log(threshold), _screen(0), _screenFrmtr(0)
81 {
82  configure(verbose);
83 }
84 
85 void ScreenLog::configure(bool verbose) {
86  // note that the shared_ptr held by the screen LogDestination will
87  // handle the deletion of this pointer.
88  _screenFrmtr = new IndentedFormatter(verbose);
89  shared_ptr<LogFormatter> fmtr(_screenFrmtr);
90 
91  // note that the shared_ptr held by LogDestination list will
92  // handle the deletion of this pointer.
93  _screen = new LogDestination(&clog, fmtr, INHERIT_THRESHOLD);
94  shared_ptr<LogDestination> dest(_screen);
95  _destinations.push_back( dest );
96 }
97 
98 ScreenLog::~ScreenLog() { }
99 
100 /*
101  * copy another ScreenLog into this one
102  */
103 ScreenLog& ScreenLog::operator=(const ScreenLog& that) {
104  if (this == &that) return *this;
105 
106  dynamic_cast<Log*>(this)->operator=(that);
107  _screen = that._screen;
108  _screenFrmtr = that._screenFrmtr;
109  return *this;
110 }
111 
125 void ScreenLog::createDefaultLog(const PropertySet& preamble,
126  bool verbose, int threshold)
127 {
128  Log::setDefaultLog(new ScreenLog(preamble, verbose, threshold));
129 }
130 
131 /*
132  * create a new log and set it as the default Log
133  * @param preamble a list of data properties that should be included
134  * with every recorded message to the Log. This
135  * constructor will automatically add a property
136  * ("LOG") giving the Log name.
137  * @param threshold the importance threshold to set for messages going
138  * to the screen.
139  * @param verbose if true, all message data properties will be printed
140  * to the screen. If false, only the Log name
141  * ("LOG") and the text comment ("COMMENT") will be
142  * printed.
143  */
144 void ScreenLog::createDefaultLog(bool verbose, int threshold) {
145  Log::setDefaultLog(new ScreenLog(verbose, threshold));
146 }
147 
148 //@endcond
149 }}} // end lsst::pex::logging
150 
static void configure(void)
Definition: Log.cc:119
def configure
Definition: log.py:42
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:58
definition of the ScreenLog class
Class for storing generic metadata.
Definition: PropertySet.h:82
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70