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
LogEvent.cc
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008-2015 AURA/LSST.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <https://www.lsstcorp.org/LegalNotices/>.
23  */
24 
33 #include <iomanip>
34 #include <sstream>
35 #include <stdexcept>
36 #include <limits>
37 #include <cstring>
38 
40 #include "lsst/ctrl/events/Event.h"
44 #include "lsst/pex/exceptions.h"
45 
46 #include <log4cxx/helpers/stringhelper.h>
47 #include <log4cxx/helpers/pool.h>
48 #include <log4cxx/spi/location/locationinfo.h>
49 
50 using namespace log4cxx;
51 using namespace log4cxx::helpers;
52 
53 namespace pexExceptions = lsst::pex::exceptions;
54 
55 
56 using namespace std;
57 
58 namespace lsst {
59 namespace ctrl {
60 namespace events {
61 
62 const std::string LogEvent::LEVEL = "LEVEL";
63 const std::string LogEvent::LOGGER = "LOGGER";
64 const std::string LogEvent::MESSAGE = "MESSAGE";
65 const std::string LogEvent::TIMESTAMP = "TIMESTAMP";
66 const std::string LogEvent::THREADNAME = "THREADNAME";
67 const std::string LogEvent::FILENAME = "FILENAME";
68 const std::string LogEvent::CLASSNAME = "CLASSNAME";
69 const std::string LogEvent::METHODNAME = "METHODNAME";
70 const std::string LogEvent::LINENUMBER = "LINENUMBER";
71 const std::string LogEvent::LOCATION = "LOCATION";
72 
73 const std::string LogEvent::LOGGING_TOPIC = "Logging";
74 
79 LogEvent::LogEvent() : Event() {
80  _init();
81 }
82 
83 LogEvent::LogEvent(const log4cxx::spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) : Event() {
84  _init();
85 
86  _psp->set(TYPE, EventTypes::LOG);
87  _psp->set(LogEvent::LOGGER, event->getLoggerName());
88  _psp->set(LogEvent::LEVEL, event->getLevel()->toInt());
89 
90  _psp->set(LogEvent::MESSAGE, event->getMessage());
91  _psp->set(LogEvent::TIMESTAMP, event->getTimeStamp());
92  _psp->set(LogEvent::THREADNAME, event->getThreadName());
93 
94  spi::LocationInfo location = event->getLocationInformation();
95 
97  loc->set(LogEvent::FILENAME, location.getFileName());
98  loc->set(LogEvent::CLASSNAME, location.getClassName());
99  loc->set(LogEvent::METHODNAME, location.getMethodName());
100  loc->set(LogEvent::LINENUMBER, location.getLineNumber());
101 
102  _psp->set(LogEvent::LOCATION, loc);
103 }
104 
105 
109  _keywords.insert(LogEvent::LEVEL);
110  _keywords.insert(LogEvent::LOGGER);
111 }
112 
113 
118 LogEvent::LogEvent(cms::TextMessage *msg) : Event(msg) {
119  _init();
120 
121  _psp->set(LogEvent::LEVEL, msg->getIntProperty(LogEvent::LEVEL));
122  _psp->set(LogEvent::LOGGER, msg->getStringProperty(LogEvent::LOGGER));
123 
124 }
125 
129 void LogEvent::populateHeader(cms::TextMessage* msg) const {
131 
132  msg->setIntProperty(LogEvent::LEVEL, _psp->get<int>(LogEvent::LEVEL));
133  msg->setStringProperty(LogEvent::LOGGER, _psp->get<std::string>(LogEvent::LOGGER));
134 
135 }
136 
142  return _psp->get<int>(LogEvent::LEVEL);
143 }
144 
149 std::string LogEvent::getLogger() {
150  return _psp->get<std::string>(LogEvent::LOGGER);
151 }
152 
159 }
160 
165 }
166 
167 }}}
static const std::string LEVEL
Definition: LogEvent.h:67
static const std::string TIMESTAMP
Definition: LogEvent.h:71
static const std::string LOGGING_TOPIC
Definition: LogEvent.h:79
Include files required for standard LSST Exception handling.
PropertySet::Ptr _psp
Definition: Event.h:236
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
LogEvent()
Creates LogEvent which contains a PropertySet.
Definition: LogEvent.cc:79
defines EventTypes
std::string getLogger()
Retreive the log message.
Definition: LogEvent.cc:149
static const std::string METHODNAME
Definition: LogEvent.h:75
virtual ~LogEvent()
destructor
Definition: LogEvent.cc:164
static const std::string THREADNAME
Definition: LogEvent.h:72
static const std::string LOG
Definition: EventTypes.h:47
virtual void populateHeader(cms::TextMessage *msg) const
populate a cms::TextMessage header with properties
Definition: Event.cc:241
static const std::string MESSAGE
Definition: LogEvent.h:70
set< std::string > _keywords
Definition: Event.h:238
defines the Event class
int getLevel()
retreive the log level
Definition: LogEvent.cc:141
static const std::string CLASSNAME
Definition: LogEvent.h:74
defines the LogEvent class
virtual void populateHeader(cms::TextMessage *msg) const
Definition: LogEvent.cc:129
static const std::string TYPE
Definition: Event.h:66
Representation of an LSST Event.
Definition: Event.h:62
static const std::string LOGGER
Definition: LogEvent.h:68
Class for storing generic metadata.
Definition: PropertySet.h:82
std::string getLoggingTopic()
Retreive the log message.
Definition: LogEvent.cc:157
static const std::string FILENAME
Definition: LogEvent.h:73
Interface for PropertySet class.
defines the EventSystem class
static const std::string LOCATION
Definition: LogEvent.h:77
static const std::string LINENUMBER
Definition: LogEvent.h:76