예제 #1
0
void AsyncAppender::append(const spi::LoggingEventPtr& event)
{
	// Set the NDC and thread name for the calling thread as these
	// LoggingEvent fields were not set at event creation time.
	event->getNDC();
	// Get a copy of this thread's MDC.
	event->getMDCCopy();
	
/*	if(locationInfo)
	{
		event.getLocationInformation();
	}*/
	
	synchronized sync(bf);

	while(bf->isFull())
	{
		//LOGLOG_DEBUG(_T("Waiting for free space in buffer, ")
		//	 << bf->length());
		bf->wait();
	}

	bf->put(event);
	if(bf->wasEmpty())
	{
		//LOGLOG_DEBUG(_T("Notifying dispatcher to process events."));
		bf->notify();
	}
}
예제 #2
0
void SocketAppender::append(const spi::LoggingEventPtr& event, log4cxx::helpers::Pool& p) {
    if (oos != 0) {
        LogString ndcVal;
        event->getNDC(ndcVal);
        event->getThreadName();
        // Get a copy of this thread's MDC.
        event->getMDCCopy();
        try {
           event->write(*oos, p);
           oos->flush(p);
        } catch(std::exception& e) {
           oos = 0;
           LogLog::warn(LOG4CXX_STR("Detected problem with connection: "), e);
           if (getReconnectionDelay() > 0) {
               fireConnector();
           }
        }
    }
}
void SocketHubAppender::append(const spi::LoggingEventPtr& event, Pool& p)
{

        // if no open connections, exit now
        if(streams.empty())
        {
                return;
        }
        
        LogString ndcVal;
        event->getNDC(ndcVal);
        event->getThreadName();
        // Get a copy of this thread's MDC.
        event->getMDCCopy();
       

        // loop through the current set of open connections, appending the event to each
        std::vector<ObjectOutputStreamPtr>::iterator it = streams.begin();
        std::vector<ObjectOutputStreamPtr>::iterator itEnd = streams.end();
        while(it != itEnd)
        {
                // list size changed unexpectedly? Just exit the append.
                if (*it == 0)
                {
                        break;
                }

                try
                {
                        event->write(**it, p);
                        (*it)->flush(p);
                        it++;
                }
                catch(std::exception& e)
                {
                        // there was an io exception so just drop the connection
                        it = streams.erase(it);
                        LogLog::debug(LOG4CXX_STR("dropped connection"), e);
                }
        }
}
예제 #4
0
void AsyncAppender::append(const spi::LoggingEventPtr& event, Pool& p) {
#if APR_HAS_THREADS
       //
        //   if dispatcher has died then
        //      append subsequent events synchronously
        //
        if (!dispatcher.isAlive() || bufferSize <= 0) {
            synchronized sync(appenders->getMutex());
            appenders->appendLoopOnAppenders(event, p);
            return;
        }

        // Set the NDC and thread name for the calling thread as these
        // LoggingEvent fields were not set at event creation time.
        LogString ndcVal;
        event->getNDC(ndcVal);
        event->getThreadName();
        // Get a copy of this thread's MDC.
        event->getMDCCopy();


        {
             synchronized sync(bufferMutex);
             while(true) {
                 int previousSize = buffer.size();
                 if (previousSize < bufferSize) {
                     buffer.push_back(event);
                     if (previousSize == 0) {
                        bufferNotEmpty.signalAll();
                     }
                     break;
                 }

                //
                //   Following code is only reachable if buffer is full
                //
                //
                //   if blocking and thread is not already interrupted
                //      and not the dispatcher then
                //      wait for a buffer notification
                bool discard = true;
                if (blocking
                    && !Thread::interrupted()
                    && !dispatcher.isCurrentThread()) {
                    try {
                        bufferNotFull.await(bufferMutex);
                        discard = false;
                    } catch (InterruptedException& e) {
                        //
                        //  reset interrupt status so
                        //    calling code can see interrupt on
                        //    their next wait or sleep.
                        Thread::currentThreadInterrupt();
                    }
                }

                //
                //   if blocking is false or thread has been interrupted
                //   add event to discard map.
                //
                if (discard) {
                    LogString loggerName = event->getLoggerName();
                    DiscardMap::iterator iter = discardMap->find(loggerName);
                    if (iter == discardMap->end()) {
                        DiscardSummary summary(event);
                        discardMap->insert(DiscardMap::value_type(loggerName, summary));
                    } else {
                        (*iter).second.add(event);
                    }
                    break;
                }
            }
        }
#else
        synchronized sync(appenders->getMutex());
        appenders->appendLoopOnAppenders(event, p);
#endif
  }
예제 #5
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);        
}