Esempio n. 1
0
void LoggingSubsystem::initialize(Application& app)
{
	LoggingConfigurator configurator;
	configurator.configure(&app.config());
	std::string logger = app.config().getString("application.logger", "Application");
	app.setLogger(Logger::get(logger));
}
Esempio n. 2
0
void AnthaxiaApp::initialize(Application& self) {
    Settings::loadSettings("procsim.rc");

    Poco::AutoPtr<AbstractConfiguration> pConfig;
    if (Path("logging.cfg").isFile())
    {
        pConfig = new PropertyFileConfiguration("logging.cfg");
    } else
    {
        pConfig = new MapConfiguration();
    }
    LoggingConfigurator configurator;
    configurator.configure(pConfig);

    Poco::LogStream log_stream(Poco::Logger::get("core.AnthaxiaApp"));
    LOG_DEBUG("Logging initialized; continue initialization of the rest");

    addSubsystem( new PluginManager() );

    // Make sure the model control is instantiated
    (void)ModelControl::getInstance();
    // Make sure the service system is present
    (void)ServiceSystem::getServiceSystem();
    registerModelControlService();

    Application::initialize(self);
}
void LoggingConfiguratorTest::testConfigurator()
{
	static const std::string config =
		"logging.loggers.root.channel = c1\n"
		"logging.loggers.root.level = warning\n"
		"logging.loggers.l1.name = logger1\n"
		"logging.loggers.l1.channel.class = FileChannel\n"
		"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
		"logging.loggers.l1.channel.path = logfile.log\n"
		"logging.loggers.l1.level = information\n"
		"logging.loggers.l2.name = logger2\n"
		"logging.loggers.l2.channel.class = SplitterChannel\n"
		"logging.loggers.l2.channel.channel1 = c2\n"
		"logging.loggers.l2.channel.channel2 = c3\n"
		"logging.loggers.l2.level = debug\n"
		"logging.channels.c1.class = ConsoleChannel\n"
		"logging.channels.c1.formatter = f1\n"
		"logging.channels.c2.class = FileChannel\n"
		"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
		"logging.channels.c2.formatter.class = PatternFormatter\n"
		"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
		"logging.channels.c3.class = ConsoleChannel\n"
		"logging.channels.c3.pattern = %s: [%p] %t\n"
		"logging.formatters.f1.class = PatternFormatter\n"
		"logging.formatters.f1.pattern = %s-[%p] %t\n"
		"logging.formatters.f1.times = UTC\n";

	std::istringstream istr(config);
	AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);

	LoggingConfigurator configurator;
	configurator.configure(pConfig);
	
	Logger& root = Logger::get("");
	assert (root.getLevel() == Message::PRIO_WARNING);
	FormattingChannel* pFC = dynamic_cast<FormattingChannel*>(root.getChannel());
	assertNotNull (pFC);
#if defined(_WIN32)
	assertNotNull (dynamic_cast<Poco::WindowsConsoleChannel*>(pFC->getChannel()));
#else
	assertNotNull (dynamic_cast<ConsoleChannel*>(pFC->getChannel()));
#endif
	assertNotNull (dynamic_cast<PatternFormatter*>(pFC->getFormatter()));
	assert (static_cast<PatternFormatter*>(pFC->getFormatter())->getProperty("pattern") == "%s-[%p] %t");
	
	Logger& logger1 = Logger::get("logger1");
	assert (logger1.getLevel() == Message::PRIO_INFORMATION);
	pFC = dynamic_cast<FormattingChannel*>(logger1.getChannel());
	assertNotNull (pFC);
	assertNotNull (dynamic_cast<FileChannel*>(pFC->getChannel()));
	assertNotNull (dynamic_cast<PatternFormatter*>(pFC->getFormatter()));
	assert (static_cast<PatternFormatter*>(pFC->getFormatter())->getProperty("pattern") == "%s: [%p] %t");

	Logger& logger2 = Logger::get("logger2");
	assert (logger2.getLevel() == Message::PRIO_DEBUG);
	assertNotNull (dynamic_cast<SplitterChannel*>(logger2.getChannel()));	
}
Esempio n. 4
0
	int main(const std::vector<std::string>& args)
	{
		if (help){
			displayHelp();
		}else{
			ifstream istr;
			istr.open("initiator.properties");
			AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);
			LoggingConfigurator configurator;
			configurator.configure(pConfig);
			istr.close();

			// get parameters from configuration file
			unsigned short port = 102;//(unsigned short) config().getInt("SSAPEchoClient.port", 9977);
			perform();

		}
		return Application::EXIT_OK;
	}
void LoggingConfiguratorTest::testBadConfiguration4()
{
	// this is mainly testing for memory leaks in case of 
	// a bad configuration.
	
	static const std::string config =
		"logging.loggers.root.channel = c1\n"
		"logging.loggers.root.level = warning\n"
		"logging.loggers.l1.name = logger1\n"
		"logging.loggers.l1.channel.class = FileChannel\n"
		"logging.loggers.l1.channel.pattern = %s: [%p] %t\n"
		"logging.loggers.l1.channel.path = logfile.log\n"
		"logging.loggers.l1.level = information\n"
		"logging.loggers.l2.name = logger2\n"
		"logging.loggers.l2.channel.class = UnknownChannel\n"
		"logging.loggers.l2.level = debug\n"
		"logging.channels.c1.class = ConsoleChannel\n"
		"logging.channels.c1.formatter = f1\n"
		"logging.channels.c2.class = FileChannel\n"
		"logging.channels.c2.path = ${system.tempDir}/sample.log\n"
		"logging.channels.c2.formatter.class = PatternFormatter\n"
		"logging.channels.c2.formatter.pattern = %s: {%p} %t\n"
		"logging.channels.c2.formatter.unknown = FOO\n"
		"logging.channels.c3.class = ConsoleChannel\n"
		"logging.channels.c3.pattern = %s: [%p] %t\n"
		"logging.formatters.f1.class = PatternFormatter\n"
		"logging.formatters.f1.pattern = %s-[%p] %t\n"
		"logging.formatters.f1.times = UTC\n";

	std::istringstream istr(config);
	AutoPtr<PropertyFileConfiguration> pConfig = new PropertyFileConfiguration(istr);

	LoggingConfigurator configurator;
	try
	{
		configurator.configure(pConfig);
		fail("bad configuration - must throw");
	}
	catch (Poco::Exception&)
	{
	}
}