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
DualLog.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 namespace lsst {
33 namespace pex {
34 namespace logging {
35 
36 //@cond
37 
38 using namespace std;
39 using boost::shared_ptr;
41 
43 // DualLog
45 
46 /*
47  * create a Log that will write messages to a given file
48  * @param filename the name of the file to send messages to. It will
49  * be opened in append mode.
50  * @param filethresh the importance threshold to set for the log file
51  * @param screenthresh the importance threshold to set for messages going
52  * to the screen.
53  * @param screenVerbose if true, all message data properties will be printed
54  * to the screen. If false, only the Log name
55  * ("LOG") and the text comment ("COMMENT") will be
56  * printed.
57  */
58 DualLog::DualLog(const PropertySet& preamble, const string& filename,
59  int filethresh, int screenthresh, bool screenVerbose)
60  : ScreenLog(preamble, screenVerbose, screenthresh)
61 {
62  _init(filename, filethresh);
63 }
64 
65 DualLog::DualLog(const string& filename,
66  int filethresh, int screenthresh, bool screenVerbose)
67  : ScreenLog(screenVerbose, screenthresh)
68 {
69  _init(filename, filethresh);
70 }
71 
72 void DualLog::_init(const string& filename, int filethresh) {
73 
74  // the DualLog destructor will close & destroy this.
75  fstrm = new ofstream(filename.c_str(), ios_base::app);
76 
77  shared_ptr<LogFormatter> fmtr(new NetLoggerFormatter());
78 
79  // note that the shared_ptr held by LogDestination list will
80  // handle the deletion of this pointer.
81  _file = new LogDestination(fstrm, fmtr, filethresh);
82  shared_ptr<LogDestination> dest(_file);
83  _destinations.push_back( dest );
84 }
85 
87  fstrm->close();
88  delete fstrm;
89 }
90 
91 void DualLog::createDefaultLog(const PropertySet& preamble,
92  const string& filename, int filethresh,
93  int screenthresh, bool screenVerbose)
94 {
95  Log::setDefaultLog(new DualLog(preamble, filename, filethresh,
96  screenthresh, screenVerbose));
97 }
98 
99 void DualLog::createDefaultLog(const string& filename, int filethresh,
100  int screenthresh, bool screenVerbose)
101 {
102  Log::setDefaultLog(new DualLog(filename, filethresh,
103  screenthresh, screenVerbose));
104 }
105 
106 //@endcond
107 }}} // end lsst::pex::logging
108 
static void setDefaultLog(Log *deflog)
std::ofstream * fstrm
Definition: DualLog.h:163
lsst::daf::base::PropertySet PropertySet
Definition: Wcs.cc:58
void _init(const std::string &filename, int filethresh)
static void createDefaultLog(const lsst::daf::base::PropertySet &preamble, const std::string &filename, int filethresh=Log::INHERIT_THRESHOLD, int screenthresh=0, bool screenVerbose=false)
DualLog(const lsst::daf::base::PropertySet &preamble, const std::string &filename, int filethresh=0, int screenthresh=0, bool screenVerbose=false)
Class for storing generic metadata.
Definition: PropertySet.h:82
std::list< boost::shared_ptr< LogDestination > > _destinations
Definition: Log.h:684
LogDestination * _file
Definition: DualLog.h:162