LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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 }}}
virtual void populateHeader(cms::TextMessage *msg) const
populate a cms::TextMessage header with properties
Definition: Event.cc:241
PropertySet::Ptr _psp
Definition: Event.h:236
static const std::string CLASSNAME
Definition: LogEvent.h:74
static const std::string FILENAME
Definition: LogEvent.h:73
static const std::string THREADNAME
Definition: LogEvent.h:72
defines EventTypes
static const std::string TYPE
Definition: Event.h:66
static const std::string LINENUMBER
Definition: LogEvent.h:76
static const std::string METHODNAME
Definition: LogEvent.h:75
LogEvent()
Creates LogEvent which contains a PropertySet.
Definition: LogEvent.cc:79
virtual void populateHeader(cms::TextMessage *msg) const
Definition: LogEvent.cc:129
static const std::string LOCATION
Definition: LogEvent.h:77
static const std::string TIMESTAMP
Definition: LogEvent.h:71
static const std::string LOG
Definition: EventTypes.h:47
static const std::string MESSAGE
Definition: LogEvent.h:70
std::string getLoggingTopic()
Retreive the log message.
Definition: LogEvent.cc:157
defines the Event class
virtual ~LogEvent()
destructor
Definition: LogEvent.cc:164
defines the LogEvent class
static const std::string LEVEL
Definition: LogEvent.h:67
std::string getLogger()
Retreive the log message.
Definition: LogEvent.cc:149
int getLevel()
retreive the log level
Definition: LogEvent.cc:141
Representation of an LSST Event.
Definition: Event.h:62
Class for storing generic metadata.
Definition: PropertySet.h:82
Interface for PropertySet class.
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
static const std::string LOGGER
Definition: LogEvent.h:68
static const std::string LOGGING_TOPIC
Definition: LogEvent.h:79
set< std::string > _keywords
Definition: Event.h:238
defines the EventSystem class
Include files required for standard LSST Exception handling.