예제 #1
0
Filter::FilterDecision LevelRangeFilter::decide(
   const spi::LoggingEventPtr& event) const
{
   if (levelMin != 0 && !event->getLevel()->isGreaterOrEqual(levelMin))
   {
      // level of event is less than minimum
      return Filter::DENY;
   }

   if (levelMax != 0 && event->getLevel()->toInt() > levelMax->toInt())
   {
      // level of event is greater than maximum
      // Alas, there is no Level.isGreater method. and using
      // a combo of isGreaterOrEqual && !Equal seems worse than
      // checking the int values of the level objects..
      return Filter::DENY;
   }

   if (acceptOnMatch)
   {
      // this filter set up to bypass later filters and always return
      // accept if level in range
      return Filter::ACCEPT;
   }
   else
   {
      // event is ok for this filter; allow later filters to have a look..
      return Filter::NEUTRAL;
   }
}
void SimpleLayout::format(LogString& output,
   const spi::LoggingEventPtr& event,
   log4cxx::helpers::Pool&) const
{
        output.append(event->getLevel()->toString());
        output.append(LOG4CXX_STR(" - "));
        output.append(event->getRenderedMessage());
        output.append(LOG4CXX_EOL);
}
void SyslogAppender::append(const spi::LoggingEventPtr& event, Pool& p)
{
        if  (!isAsSevereAsThreshold(event->getLevel()))
                return;

        LogString msg;
        layout->format(msg, event, p);

// On the local host, we can directly use the system function 'syslog'
// if it is available
#if LOG4CXX_HAVE_SYSLOG
        if (sw == 0)
        {
                std::string sbuf;
                Transcoder::encode(msg, sbuf);

                // use of "%s" to avoid a security hole
                 ::syslog(syslogFacility | event->getLevel()->getSyslogEquivalent(),
                        "%s", sbuf.c_str());

                return;
        }
#endif

        // We must not attempt to append if sw is null.
        if(sw == 0)
        {
                errorHandler->error(LOG4CXX_STR("No syslog host is set for SyslogAppedender named \"")+
                        this->name+LOG4CXX_STR("\"."));
                return;
        }

        LogString sbuf(1, 0x3C /* '<' */);
        StringHelper::toString((syslogFacility | event->getLevel()->getSyslogEquivalent()), p, sbuf);
        sbuf.append(1, (logchar) 0x3E /* '>' */);
        if (facilityPrinting)
        {
                sbuf.append(facilityStr);
        }
        sbuf.append(msg);
        sw->write(sbuf);
}
예제 #4
0
   /**
    * {@inheritDoc}
    */
 void append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) {
       synchronized sync(blocker);
       VectorAppender::append(event, p);
         //
         //   if fatal, echo messages for testLoggingInDispatcher
         //
         if (event->getLevel() == Level::getInfo()) {
             LoggerPtr logger = Logger::getLoggerLS(event->getLoggerName());
             LOG4CXX_LOGLS(logger, Level::getError(), event->getMessage());
             LOG4CXX_LOGLS(logger, Level::getWarn(), event->getMessage());
             LOG4CXX_LOGLS(logger, Level::getInfo(), event->getMessage());
             LOG4CXX_LOGLS(logger, Level::getDebug(), event->getMessage());
         }
   }
void RH_LogEventAppender::append(const spi::LoggingEventPtr& event, Pool& p){
  if ( this->layout == NULL ) {
    LOG4CXX_ENCODE_CHAR(nameStr, name);
    std::string msg("No Layout set for the appender named [ ");
    msg.append(nameStr);
    msg.append(" ].");
	 
    LOG4CXX_DECODE_CHAR(msgL, msg);
    errorHandler->error(msgL);
    return;
  }
	 
  log4cxx::LogString fMsg;
	 
  this->layout->format(fMsg, event, p);
	 
  LOG4CXX_ENCODE_CHAR(fMsgStr, fMsg);

  // This is the message structure for a Redhawk logging event
  CF::LogEvent rh_event;
  LOG4CXX_ENCODE_CHAR(t1,prodId);
  rh_event.producerId = CORBA::string_dup(t1.c_str());
  LOG4CXX_ENCODE_CHAR(t2,prodName);
  rh_event.producerName = CORBA::string_dup(t2.c_str());
  LOG4CXX_ENCODE_CHAR(t3,prodFQN);
  rh_event.producerName_fqn = CORBA::string_dup(t3.c_str());

  CORBA::Long level=CF::LogLevels::FATAL;
  if ( event->getLevel() == log4cxx::Level::getError() )
    level=CF::LogLevels::ERROR;
  if ( event->getLevel() == log4cxx::Level::getWarn() )
    level=CF::LogLevels::WARN;
  if ( event->getLevel() == log4cxx::Level::getInfo() )
    level=CF::LogLevels::INFO;
  if ( event->getLevel() == log4cxx::Level::getDebug() )
    level=CF::LogLevels::DEBUG;
  if ( event->getLevel() == log4cxx::Level::getTrace() )
    level=CF::LogLevels::TRACE;
  if ( event->getLevel() == log4cxx::Level::getAll() )
    level=CF::LogLevels::ALL;
  rh_event.level = level;

  //timeStamp in LoggingEventPtr is in microseconds
  //need to convert to seconds for rh_event
  rh_event.timeStamp = event->getTimeStamp()/1000000;
  rh_event.msg = CORBA::string_dup(fMsg.c_str());
  
  // push log message to the event channel
  if ( _event_channel ) {
    if ( _event_channel->push(rh_event) != 0 ) {
      _LL_DEBUG( "RH_LogEventAppender::append EVENT CHANNEL, PUSH OPERATION FAILED.");
    }
 }
  
}
예제 #6
0
void AppenderSkeleton::doAppend(const spi::LoggingEventPtr& event, Pool& pool1)
{
        synchronized sync(mutex);


        if(closed)
        {
                LogLog::error(((LogString) LOG4CXX_STR("Attempted to append to closed appender named ["))
                      + name + LOG4CXX_STR("]."));
                return;
        }

        if(!isAsSevereAsThreshold(event->getLevel()))
        {
                return;
        }

        FilterPtr f = headFilter;


        while(f != 0)
        {
                 switch(f->decide(event))
                 {
                         case Filter::DENY:
                                 return;
                         case Filter::ACCEPT:
                                 f = 0;
                                 break;
                         case Filter::NEUTRAL:
                                 f = f->getNext();
                 }
        }

        append(event, pool1);
}
예제 #7
0
void XMLLayout::format(LogString& output,
     const spi::LoggingEventPtr& event,
     Pool& p) const
{
        output.append(LOG4CXX_STR("<log4j:event logger=\""));
        Transform::appendEscapingTags(output, event->getLoggerName());
        output.append(LOG4CXX_STR("\" timestamp=\""));
        StringHelper::toString(event->getTimeStamp()/1000L, p, output);
        output.append(LOG4CXX_STR("\" level=\""));
        Transform::appendEscapingTags(output, event->getLevel()->toString());
        output.append(LOG4CXX_STR("\" thread=\""));
        Transform::appendEscapingTags(output, event->getThreadName());
        output.append(LOG4CXX_STR("\">"));
        output.append(LOG4CXX_EOL);

        output.append(LOG4CXX_STR("<log4j:message><![CDATA["));
        // Append the rendered message. Also make sure to escape any
        // existing CDATA sections.
        Transform::appendEscapingCDATA(output, event->getRenderedMessage());
        output.append(LOG4CXX_STR("]]></log4j:message>"));
        output.append(LOG4CXX_EOL);

        LogString ndc;
        if(event->getNDC(ndc)) {
                output.append(LOG4CXX_STR("<log4j:NDC><![CDATA["));
                Transform::appendEscapingCDATA(output, ndc);
                output.append(LOG4CXX_STR("]]></log4j:NDC>"));
                output.append(LOG4CXX_EOL);
        }

        if(locationInfo)
        {
                output.append(LOG4CXX_STR("<log4j:locationInfo class=\""));
                const LocationInfo& locInfo = event->getLocationInformation();
                LOG4CXX_DECODE_CHAR(className, locInfo.getClassName());
                Transform::appendEscapingTags(output, className);
                output.append(LOG4CXX_STR("\" method=\""));
                LOG4CXX_DECODE_CHAR(method, locInfo.getMethodName());
                Transform::appendEscapingTags(output, method);
                output.append(LOG4CXX_STR("\" file=\""));
                LOG4CXX_DECODE_CHAR(fileName, locInfo.getFileName());
                Transform::appendEscapingTags(output, fileName);
                output.append(LOG4CXX_STR("\" line=\""));
                StringHelper::toString(locInfo.getLineNumber(), p, output);
                output.append(LOG4CXX_STR("\"/>"));
                output.append(LOG4CXX_EOL);
        }
        
        if (properties) {
            KeySet propertySet(event->getPropertyKeySet());
            KeySet keySet(event->getMDCKeySet());
            if (!(keySet.empty() && propertySet.empty())) {
                output.append(LOG4CXX_STR("<log4j:properties>"));
                output.append(LOG4CXX_EOL);
                for (KeySet::const_iterator i = keySet.begin();
                        i != keySet.end(); 
                        i++) {
                        LogString key(*i);
                        LogString value;
                        if(event->getMDC(key, value)) {
                            output.append(LOG4CXX_STR("<log4j:data name=\""));
                            Transform::appendEscapingTags(output, key);
                            output.append(LOG4CXX_STR("\" value=\""));
                            Transform::appendEscapingTags(output, value);
                            output.append(LOG4CXX_STR("\"/>"));
                            output.append(LOG4CXX_EOL);
                        }
                }
            for (KeySet::const_iterator i2 = propertySet.begin();
                        i2 != propertySet.end(); 
                        i2++) {
                        LogString key(*i2);
                        LogString value;
                        if(event->getProperty(key, value)) {
                            output.append(LOG4CXX_STR("<log4j:data name=\""));
                            Transform::appendEscapingTags(output, key);
                            output.append(LOG4CXX_STR("\" value=\""));
                            Transform::appendEscapingTags(output, value);
                            output.append(LOG4CXX_STR("\"/>"));
                            output.append(LOG4CXX_EOL);
                        }
                }
                output.append(LOG4CXX_STR("</log4j:properties>"));
                output.append(LOG4CXX_EOL);
            }
        }

        output.append(LOG4CXX_STR("</log4j:event>"));
        output.append(LOG4CXX_EOL);
        output.append(LOG4CXX_EOL);        
}