LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 
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 setDefaultLog(Log *deflog)
def configure
Definition: log.py:42
void configure(bool verbose)
LogDestination * _screen
Definition: ScreenLog.h:144
static void createDefaultLog(bool verbose=false, int threshold=Log::INFO)
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:58
static const int INHERIT_THRESHOLD
Definition: Log.h:183
definition of the ScreenLog class
Class for storing generic metadata.
Definition: PropertySet.h:82
BriefFormatter * _screenFrmtr
Definition: ScreenLog.h:145
std::list< boost::shared_ptr< LogDestination > > _destinations
Definition: Log.h:684
virtual Ptr deepCopy(void) const
Definition: PropertySet.cc:70
ScreenLog(bool verbose=false, int threshold=Log::INFO)
ScreenLog & operator=(const ScreenLog &that)
Log(const int threshold=INFO, const std::string &name="")