LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
TracingLog.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 #include "lsst/ctrl/events.h"
32 
33 #include <fstream>
34 
35 namespace lsst {
36 namespace pex {
37 namespace harness {
38 
40 
41 const std::string TracingLog::STATUS("STATUS");
42 const std::string TracingLog::START("start");
43 const std::string TracingLog::END("end");
44 
45 TracingLog::TracingLog(const logging::Log& parent, const std::string& name,
46  int tracelev, const std::string& funcName)
47  : Log(parent, name), _tracelev(tracelev), _funcName(funcName)
48 {
49  if (_funcName.length() == 0) _funcName = name;
51  const TracingLog *p = dynamic_cast<const TracingLog*>(&parent);
52  if (p) {
53  _tracelev = p->getTraceLevel();
54  }
55  else {
56  _tracelev = TRACE;
57  }
58  }
59 }
60 
62 
70 
71 TracingLog *setupHarnessLogging(const std::string& runId, int sliceId,
72  const std::string& eventBrokerHost,
73  const std::string& pipename,
74  const std::string& workerid,
75  std::ostream *messageStrm,
76  const std::string& logname)
77 {
78  if (eventBrokerHost.length() > 0) {
79  /* Move this to LogUtils.cc and only call for the Pipeline
80  Re-examine this for MPI Slices
81  EventSystem& eventSystem = EventSystem::getDefaultEventSystem();
82  eventSystem.createTransmitter(eventBrokerHost, "LSSTLogging");
83  */
84  EventLog::createDefaultLog(runId, sliceId);
85  }
86  Log& root = Log::getDefaultLog();
87  root.addPreambleProperty("PIPELINE", pipename);
88  root.addPreambleProperty("workerid", workerid);
89 
90  if (messageStrm != 0) {
91  boost::shared_ptr<LogFormatter> frmtr(new IndentedFormatter(true));
92  boost::shared_ptr<LogDestination>
93  dest(new LogDestination(messageStrm, frmtr, Log::DEBUG));
94  root.addDestination(dest);
95  }
96 
97  TracingLog *out = 0;
98  try {
99  out = new TracingLog(root, logname);
100  out->format(Log::INFO,
101  "Harness Logger initialized with message threshold = %i",
102  out->getThreshold());
103  return out;
104  }
105  catch (...) {
106  delete out;
107  throw;
108  }
109 }
110 
111 }}} // end lsst::pex::harness
static void createDefaultLog(const std::string runId, int slideId, const std::string hostId="", int threshold=Log::INFO)
creates a default log
Definition: EventLog.cc:131
defines the EventLog class
int getThreshold() const
Definition: Log.h:281
LogRec Rec
Definition: Log.h:838
an encapsulation of a logging stream that will filter messages based on their volume (importance) lev...
void format(int importance, const char *fmt,...)
static const std::string END
Definition: TracingLog.h:73
static const std::string START
Definition: TracingLog.h:67
a place to record messages and descriptions of the state of processing.
Definition: Log.h:154
static Log & getDefaultLog()
TracingLog(const logging::Log &parent, const std::string &name, int tracelev=TracingLog::TRACE, const std::string &funcName="")
Definition: TracingLog.cc:45
static const int INHERIT_THRESHOLD
Definition: Log.h:183
provides access to primary application interface classes for sending and receiving events...
void addDestination(std::ostream &destination, int threshold)
static const int INFO
Definition: Log.h:171
static const std::string STATUS
Definition: TracingLog.h:61
definition of the TracingLog class
BlockTimingLog * setupHarnessLogging(const std::string &runId, int sliceId, const std::string &eventBrokerHost, const std::string &pipename, const std::string &workerid, std::ostream *messageStrm, const std::string &logname, int resourceUsageFlags)
create and configure logging for a harness application
Definition: LogUtils.cc:168
static const int DEBUG
Definition: Log.h:163
void addPreambleProperty(const std::string &name, const T &val)
Definition: Log.h:694
Coordinate publishing and receiving events.
Definition: EventSystem.h:65
a Log for transmitting log messages as events.
Definition: EventLog.h:58
defines the EventSystem class
an abstract class for formatting log records into a text stream.
Definition: LogFormatter.h:73