Ejemplo n.º 1
0
 /**
  * Tests non-blocking behavior.
  */
 void testLocationInfoTrue() {
     BlockableVectorAppenderPtr blockableAppender = new BlockableVectorAppender();
     AsyncAppenderPtr async = new AsyncAppender();
     async->addAppender(blockableAppender);
     async->setBufferSize(5);
     async->setLocationInfo(true);
     async->setBlocking(false);
     Pool p;
     async->activateOptions(p);
     LoggerPtr rootLogger = Logger::getRootLogger();
     rootLogger->addAppender(async);
     {
         synchronized sync(blockableAppender->getBlocker());
         for (int i = 0; i < 100; i++) {
                LOG4CXX_INFO(rootLogger, "Hello, World");
                Thread::sleep(1);
         }
         LOG4CXX_ERROR(rootLogger, "That's all folks.");
     }
     async->close();
     const std::vector<spi::LoggingEventPtr>& events = blockableAppender->getVector();
     LOGUNIT_ASSERT(events.size() > 0);
     LoggingEventPtr initialEvent = events[0];
     LoggingEventPtr discardEvent = events[events.size() - 1];
     LOGUNIT_ASSERT(initialEvent->getMessage() == LOG4CXX_STR("Hello, World"));
     LOGUNIT_ASSERT(discardEvent->getMessage().substr(0,10) == LOG4CXX_STR("Discarded "));
     LOGUNIT_ASSERT_EQUAL(log4cxx::spi::LocationInfo::getLocationUnavailable().getClassName(), 
         discardEvent->getLocationInformation().getClassName()); 
 }
Ejemplo n.º 2
0
	void locationInfo()
	{
		XMLLayoutPtr xmlLayout = new XMLLayout();
		xmlLayout->setLocationInfo(true);
		root->addAppender(new FileAppender(xmlLayout, TEMP, false));
		common();
		
		XMLTimestampFilter xmlTimestampFilter;
		XMLLineAttributeFilter xmlLineAttributeFilter;
		XMLThreadFilter xmlThreadFilter;

		std::vector<Filter *> filters;
		filters.push_back(&xmlTimestampFilter);
		filters.push_back(&xmlLineAttributeFilter);
		filters.push_back(&xmlThreadFilter);
		
		try
		{
			Transformer::transform(TEMP, FILTERED, filters);
		}
		catch(UnexpectedFormatException& e)
		{
			tcout << _T("UnexpectedFormatException :") << e.getMessage() << std::endl;
			throw;
		}

		CPPUNIT_ASSERT(Compare::compare(FILTERED, _T("witness/xmlLayout.2")));
	}
Ejemplo n.º 3
0
	// not incuded in the tests for the moment !
	void holdTestMDCEscaped()
	{
		XMLLayoutPtr xmlLayout = new XMLLayout();
		root->addAppender(new FileAppender(xmlLayout, TEMP, false));
		
		MDC::clear();
		MDC::put(_T("blahAttribute"), _T("<blah value=\"blah\">"));
		MDC::put(_T("<blahKey value=\"blah\"/>"), _T("blahValue"));

		LOG4CXX_DEBUG(logger, _T("Hello"));
		
		MDC::clear();

		XMLTimestampFilter xmlTimestampFilter;
		XMLThreadFilter xmlThreadFilter;

		std::vector<Filter *> filters;
		filters.push_back(&xmlTimestampFilter);
		filters.push_back(&xmlThreadFilter);
		
		try
		{
			Transformer::transform(TEMP, FILTERED, filters);
		}
		catch(UnexpectedFormatException& e)
		{
			tcout << _T("UnexpectedFormatException :") << e.getMessage() << std::endl;
			throw;
		}

		CPPUNIT_ASSERT(Compare::compare(FILTERED, _T("witness/xmlLayout.mdc.2")));
	}
Ejemplo n.º 4
0
	void testNULL()
	{
		XMLLayoutPtr xmlLayout = new XMLLayout();
		root->addAppender(new FileAppender(xmlLayout, TEMP, false));
		
		LOG4CXX_DEBUG(logger, _T("hi"));
		LOG4CXX_DEBUG(logger, _T(""));
		
		XMLTimestampFilter xmlTimestampFilter;
		XMLThreadFilter xmlThreadFilter;

		std::vector<Filter *> filters;
		filters.push_back(&xmlTimestampFilter);
		filters.push_back(&xmlThreadFilter);
		
		try
		{
			Transformer::transform(TEMP, FILTERED, filters);
		}
		catch(UnexpectedFormatException& e)
		{
			tcout << _T("UnexpectedFormatException :") << e.getMessage() << std::endl;
			throw;
		}

		CPPUNIT_ASSERT(Compare::compare(FILTERED, _T("witness/xmlLayout.null")));
	}
Ejemplo n.º 5
0
	void testCDATA()
	{
		XMLLayoutPtr xmlLayout = new XMLLayout();
		xmlLayout->setLocationInfo(true);
		root->addAppender(new FileAppender(xmlLayout, TEMP, false));
		
		LOG4CXX_DEBUG(logger,
			_T("Message with embedded <![CDATA[<hello>hi</hello>]]>."));
		
		XMLTimestampFilter xmlTimestampFilter;
		XMLLineAttributeFilter xmlLineAttributeFilter;
		XMLThreadFilter xmlThreadFilter;

		std::vector<Filter *> filters;
		filters.push_back(&xmlTimestampFilter);
		filters.push_back(&xmlLineAttributeFilter);
		filters.push_back(&xmlThreadFilter);
		
		try
		{
			Transformer::transform(TEMP, FILTERED, filters);
		}
		catch(UnexpectedFormatException& e)
		{
			tcout << _T("UnexpectedFormatException :") << e.getMessage() << std::endl;
			throw;
		}

		CPPUNIT_ASSERT(Compare::compare(FILTERED, _T("witness/xmlLayout.3")));
	}
Ejemplo n.º 6
0
                        void LoggerUtil::configure() {
#ifdef HAVE_LOG4CXX
                            LoggerPtr rootLogger = Logger::getRootLogger();
                            
                            rootLogger->removeAllAppenders();
                            
                            rootLogger->addAppender(new ConsoleAppender(new PatternLayout("%d [%t] %-5p %c - %m%n")));
#endif
                        }
void BasicConfigurator::configure()
{
   LogManager::getLoggerRepository()->setConfigured(true);
   LoggerPtr root = Logger::getRootLogger();
        static const LogString TTCC_CONVERSION_PATTERN(LOG4CXX_STR("%r [%t] %p %c %x - %m%n"));
   LayoutPtr layout(new PatternLayout(TTCC_CONVERSION_PATTERN));
   AppenderPtr appender(new ConsoleAppender(layout));
   root->addAppender(appender);
}
Ejemplo n.º 8
0
 /**
  * Tests that a bad appender will switch async back to sync.
  */
 void testBadAppender() {
     AppenderPtr nullPointerAppender = new NullPointerAppender();
     AsyncAppenderPtr asyncAppender = new AsyncAppender();
     asyncAppender->addAppender(nullPointerAppender);
     asyncAppender->setBufferSize(5);
     Pool p;
     asyncAppender->activateOptions(p);
     LoggerPtr root = Logger::getRootLogger();
     root->addAppender(asyncAppender);
     LOG4CXX_INFO(root, "Message");
     Thread::sleep(10);
     try {
        LOG4CXX_INFO(root, "Message");
        LOGUNIT_FAIL("Should have thrown exception");
     } catch(NullPointerException& ex) {
     }
 }
Ejemplo n.º 9
0
        // this test checks whether it is possible to write to a closed AsyncAppender
        void closeTest() 
        {
                LoggerPtr root = Logger::getRootLogger();
                LayoutPtr layout = new SimpleLayout();
                VectorAppenderPtr vectorAppender = new VectorAppender();
                AsyncAppenderPtr asyncAppender = new AsyncAppender();
                asyncAppender->setName(LOG4CXX_STR("async-CloseTest"));
                asyncAppender->addAppender(vectorAppender);
                root->addAppender(asyncAppender);

                root->debug(LOG4CXX_TEST_STR("m1"));
                asyncAppender->close();
                root->debug(LOG4CXX_TEST_STR("m2"));

                const std::vector<spi::LoggingEventPtr>& v = vectorAppender->getVector();
                LOGUNIT_ASSERT_EQUAL((size_t) 1, v.size());
        }
Ejemplo n.º 10
0
void Server::setupLogging() {
	using namespace boost;
	using namespace log4cxx;
	using namespace log4cxx::helpers;
	using namespace log4cxx::xml;

	LoggerPtr rootLogger = Logger::getRootLogger();
	rootLogger->addAppender(new ConsoleAppender(new PatternLayout("%d | %5p | %m%n")));
	rootLogger->setLevel(Level::getDebug());

	bool directoryCreationFailed = false;
	bool configurationFileMissing = false;

	if (!filesystem::is_directory(LOGGING_DIRECTORY)) {
		system::error_code error;
		if (filesystem::create_directory(LOGGING_DIRECTORY, error)) {
			chmod(LOGGING_DIRECTORY.c_str(), S_IRWXU);
		}
		else {
			directoryCreationFailed = true;
		}
	}

	// sadly we cannot check whether we were successful or not :(
	if (filesystem::is_regular_file(LOGGING_CONFIGURATION_FILE) || filesystem::is_symlink(LOGGING_CONFIGURATION_FILE)) {
		DOMConfigurator::configureAndWatch(LOGGING_CONFIGURATION_FILE);
	}
	else {
		configurationFileMissing = true;
	}

	LOGi(std::setfill('-') << std::setw(90) << "");
	LOGi(SOFTWARE_NAME " " SOFTWARE_VERSION " for Tibia(R) " SOFTWARE_PROTOCOL);
	LOGi(X_PROJECT_URL);
	LOGi(std::setfill('-') << std::setw(90) << "");

	if (configurationFileMissing) {
		LOGe("Cannot find logging configuration file '" << LOGGING_CONFIGURATION_FILE << "'. Using defaults.");
	}
	if (directoryCreationFailed) {
		LOGe("Cannot create logging directory '" << LOGGING_DIRECTORY << "'. No log files will be written.");
	}
}
Ejemplo n.º 11
0
        // this test checks whether appenders embedded within an AsyncAppender are also
        // closed
        void test3()
        {
                size_t LEN = 200;
                LoggerPtr root = Logger::getRootLogger();
                VectorAppenderPtr vectorAppender = new VectorAppender();
                AsyncAppenderPtr asyncAppender = new AsyncAppender();
                asyncAppender->setName(LOG4CXX_STR("async-test3"));
                asyncAppender->addAppender(vectorAppender);
                root->addAppender(asyncAppender);

                for (size_t i = 0; i < LEN; i++) {
                        LOG4CXX_DEBUG(root, "message" << i);
                }

                asyncAppender->close();
                root->debug(LOG4CXX_TEST_STR("m2"));

                const std::vector<spi::LoggingEventPtr>& v = vectorAppender->getVector();
                LOGUNIT_ASSERT_EQUAL(LEN, v.size());
                LOGUNIT_ASSERT_EQUAL(true, vectorAppender->isClosed());
        }
Ejemplo n.º 12
0
void BasicConfigurator::configure(const AppenderPtr& appender)
{
    LoggerPtr root = Logger::getRootLogger();
    root->addAppender(appender);
}
Ejemplo n.º 13
0
void BasicConfigurator::configure()
{
    LoggerPtr root = Logger::getRootLogger();
    root->addAppender(new ConsoleAppender(
                          new PatternLayout(PatternLayout::TTCC_CONVERSION_PATTERN)));
}