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
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
lsst::ctrl::events::EventAppender Class Reference

log4cxx appender class which sends logging messages out on the event stream More...

#include <EventAppender.h>

Inheritance diagram for lsst::ctrl::events::EventAppender:

Public Member Functions

 EventAppender ()
 
 ~EventAppender ()
 destructor More...
 
virtual void setOption (const LogString &option, const LogString &value)
 log4cxx methods for setting options; for this class options are BROKER - host name of event broker (required) PORT - port number on which the event broker is listening (optional) TOPIC - topic name on which to send logging messages (optional) More...
 
virtual void activateOptions (log4cxx::helpers::Pool &p)
 prepares EventAppender for use More...
 
void append (const spi::LoggingEventPtr &event, log4cxx::helpers::Pool &p)
 handles a log event. For this appender, this means sending an event to the logging topic. More...
 
void close ()
 shuts down the appender More...
 
bool requiresLayout () const
 this appender does not require a layout to format the text More...
 

Protected Member Functions

lsst::ctrl::events::EventTransmittergetTransmitter ()
 

Protected Attributes

lsst::ctrl::events::EventTransmitter_transmitter
 
LogString _broker
 
LogString _topic
 
int _port
 

Detailed Description

log4cxx appender class which sends logging messages out on the event stream

Definition at line 75 of file EventAppender.h.

Constructor & Destructor Documentation

lsst::ctrl::events::EventAppender::EventAppender ( )

Definition at line 62 of file EventAppender.cc.

lsst::ctrl::events::EventAppender::~EventAppender ( )

destructor

Definition at line 70 of file EventAppender.cc.

70  {
71  if (_transmitter != NULL)
72  delete _transmitter;
73  _transmitter = NULL;
74 }
lsst::ctrl::events::EventTransmitter * _transmitter

Member Function Documentation

void lsst::ctrl::events::EventAppender::activateOptions ( log4cxx::helpers::Pool &  p)
virtual

prepares EventAppender for use

Definition at line 88 of file EventAppender.cc.

89 {
90  if (_broker.empty()) {
91  LogLog::error((LogString) LOG4CXX_STR("Appender requires broker option to be specified"));
92  return;
93  }
94  try {
95  _transmitter = new EventTransmitter(_broker, _topic, _port);
96  } catch (pexExceptions::RuntimeError& rte) {
97  std::ostringstream msg;
98  msg << "Couldn't reach broker " << _broker << " at port " << _port;
99  LogLog::error((LogString) LOG4CXX_STR(msg.str()));
100  _transmitter = NULL;
101  }
102 }
lsst::ctrl::events::EventTransmitter * _transmitter
def error
Definition: log.py:108
void lsst::ctrl::events::EventAppender::append ( const spi::LoggingEventPtr &  event,
log4cxx::helpers::Pool &  p 
)

handles a log event. For this appender, this means sending an event to the logging topic.

Definition at line 116 of file EventAppender.cc.

116  {
117  PropertySet::Ptr psp(new PropertySet);
118 
119  psp->set("logger", event->getLoggerName());
120  psp->set("message", event->getMessage());
121  psp->set("timestamp", event->getTimeStamp());
122  psp->set("threadname", event->getThreadName());
123  psp->set("level", event->getLevel()->toInt());
124 
125  spi::LocationInfo location = event->getLocationInformation();
126 
127  PropertySet::Ptr loc(new PropertySet);
128  loc->set("filename", location.getFileName());
129  loc->set("classname", location.getClassName());
130  loc->set("methodname", location.getMethodName());
131  loc->set("linenumber", location.getLineNumber());
132 
133  psp->set("location", loc);
134 
136 
137  EventTransmitter *transmitter = getTransmitter();
138 
139  if (_transmitter == NULL)
140  return;
141 
142  try {
143  transmitter->publishEvent(e);
144  } catch (Exception& e) {
145  LogLog::error((LogString) LOG4CXX_STR("event transmitter failed"));
146  delete _transmitter;
147  _transmitter = NULL;
148  }
149 }
boost::shared_ptr< PropertySet > Ptr
Definition: PropertySet.h:90
lsst::ctrl::events::EventTransmitter * _transmitter
def error
Definition: log.py:108
lsst::ctrl::events::EventTransmitter * getTransmitter()
Representation of an LSST Event.
Definition: Event.h:62
Class for storing generic metadata.
Definition: PropertySet.h:82
void lsst::ctrl::events::EventAppender::close ( )

shuts down the appender

Definition at line 151 of file EventAppender.cc.

151  {
152  if (this->closed)
153  return;
154  this->closed = true;
155 }
EventTransmitter * lsst::ctrl::events::EventAppender::getTransmitter ( )
protected

Definition at line 105 of file EventAppender.cc.

105  {
106  if (_transmitter == NULL) {
107  try {
108  _transmitter = new EventTransmitter(_broker, _topic, _port);
109  } catch (Exception& e) {
110  }
111  }
112  return _transmitter;
113 }
lsst::ctrl::events::EventTransmitter * _transmitter
bool lsst::ctrl::events::EventAppender::requiresLayout ( ) const
inline

this appender does not require a layout to format the text

Returns
always returns false

Definition at line 119 of file EventAppender.h.

119 { return false; }
void lsst::ctrl::events::EventAppender::setOption ( const LogString &  option,
const LogString &  value 
)
virtual

log4cxx methods for setting options; for this class options are BROKER - host name of event broker (required) PORT - port number on which the event broker is listening (optional) TOPIC - topic name on which to send logging messages (optional)

Parameters
optionoption name
valueoption value

Definition at line 76 of file EventAppender.cc.

76  {
77  if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("BROKER"), LOG4CXX_STR("broker"))) {
78  _broker = value;
79  } else if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("PORT"), LOG4CXX_STR("port"))) {
80  _port = atoi(value.c_str());
81  } else if (StringHelper::equalsIgnoreCase(option, LOG4CXX_STR("TOPIC"), LOG4CXX_STR("topic"))) {
82  _topic = value;
83  } else {
84  AppenderSkeleton::setOption(option, value);
85  }
86 }

Member Data Documentation

LogString lsst::ctrl::events::EventAppender::_broker
protected

Definition at line 125 of file EventAppender.h.

int lsst::ctrl::events::EventAppender::_port
protected

Definition at line 127 of file EventAppender.h.

LogString lsst::ctrl::events::EventAppender::_topic
protected

Definition at line 126 of file EventAppender.h.

lsst::ctrl::events::EventTransmitter* lsst::ctrl::events::EventAppender::_transmitter
protected

Definition at line 123 of file EventAppender.h.


The documentation for this class was generated from the following files: