当前位置: 首页>>代码示例>>Java>>正文


Java Syslog.createInstance方法代码示例

本文整理汇总了Java中org.productivity.java.syslog4j.Syslog.createInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Syslog.createInstance方法的具体用法?Java Syslog.createInstance怎么用?Java Syslog.createInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.productivity.java.syslog4j.Syslog的用法示例。


在下文中一共展示了Syslog.createInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUp

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void setUp() {
	UDPNetSyslogConfig config = new UDPNetSyslogConfig();
	
	assertTrue(config.isCacheHostAddress());
	config.setCacheHostAddress(false);
	assertFalse(config.isCacheHostAddress());
	
	assertTrue(config.isThrowExceptionOnInitialize());
	config.setThrowExceptionOnInitialize(false);
	assertFalse(config.isThrowExceptionOnInitialize());
	
	assertFalse(config.isThrowExceptionOnWrite());
	config.setThrowExceptionOnWrite(true);
	assertTrue(config.isThrowExceptionOnWrite());
	
	Syslog.createInstance("log4jUdp",config);
	
	String protocol = getServerProtocol();
	
	startServerThread(protocol);
	SyslogUtility.sleep(100);
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:23,代码来源:AbstractLog4jSyslog4jTest.java

示例2: testStructuredSyslogMessage

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testStructuredSyslogMessage() {
	SyslogConfigIF config = new UDPNetSyslogConfig();
	config.setUseStructuredData(true);
	assertTrue(config.isUseStructuredData());
	config.setUseStructuredData(false);
	assertFalse(config.isUseStructuredData());
	
	SyslogIF syslog = Syslog.createInstance("testStructuredSyslog",config);
	
	SyslogMessageProcessorIF messageProcessor = new StructuredSyslogMessageProcessor();
	syslog.setStructuredMessageProcessor(messageProcessor);
	assertEquals(messageProcessor,syslog.getStructuredMessageProcessor());
	
	SyslogMessageIF m1 = new StructuredSyslogMessage("test1",new HashMap(),"test2");
	SyslogMessageIF m2 = new StructuredSyslogMessage("test1",new HashMap(),"test2");
	SyslogMessageIF m3 = new StructuredSyslogMessage("test3",new HashMap(),"test2");
	SyslogMessageIF m4 = new StructuredSyslogMessage("test1",new HashMap(),"test4");
	
	assertFalse(m1.equals(null));
	assertFalse(m1.equals("Wrong Class"));
	assertTrue(m1.equals(m1));
	assertTrue(m2.equals(m2));
	
	assertFalse(m1.equals(m3));
	assertFalse(m1.equals(m4));
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:27,代码来源:SyslogParameterTest.java

示例3: testCreateAndDestroyByProtocol

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testCreateAndDestroyByProtocol() {
	UDPNetSyslogConfig config = new UDPNetSyslogConfig();
	config.setPort(999);
	
	SyslogIF syslog = Syslog.createInstance("udpToDestroy",config);

	assertEquals(SyslogMessageProcessor.getDefault(),syslog.getMessageProcessor());		
	SyslogMessageProcessorIF messageProcessor = new FakeMessageProcessor();
	syslog.setMessageProcessor(messageProcessor);
	assertEquals(messageProcessor,syslog.getMessageProcessor());	
	
	SyslogIF matchSyslog = Syslog.getInstance("udpToDestroy");
	
	assertEquals(syslog,matchSyslog);
	
	Syslog.destroyInstance("");
	Syslog.destroyInstance("udpToDestroy");
	
	try {
		Syslog.getInstance("udpToDestroy");
		fail("udpToDestroy should not exist");
		
	} catch (SyslogRuntimeException sre) {
		//
	}
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:27,代码来源:SyslogCreateAndDestroyTest.java

示例4: setupPoolConfig

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
protected void setupPoolConfig(boolean threaded, int maxActive, int maxWait) {
	PooledTCPNetSyslogConfig config = new PooledTCPNetSyslogConfig();
	
	config.setThreaded(threaded);
	config.setThrowExceptionOnWrite(true);
	config.setThrowExceptionOnInitialize(true);
	
	if (maxWait > 0) {
		config.setMaxWait(maxWait);
	}
	
	if (maxActive > 0) {
		config.setMaxActive(maxActive);
	}
		
	Syslog.createInstance("pooledTcp",config);
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:18,代码来源:PooledTCPNetSyslog4jTest.java

示例5: setupPoolConfig

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
protected void setupPoolConfig(boolean threaded, int maxActive, int maxWait) {
	PooledSSLTCPNetSyslogConfig config = new PooledSSLTCPNetSyslogConfig();

	config.setThreaded(threaded);
	config.setThrowExceptionOnWrite(true);
	config.setThrowExceptionOnInitialize(true);
	
	if (maxWait > 0) {
		config.setMaxWait(maxWait);
	}
	
	if (maxActive > 0) {
		config.setMaxActive(maxActive);
	}
		
	Syslog.createInstance("pooledSslTcp",config);
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:18,代码来源:PooledSSLTCPNetSyslog4jTest.java

示例6: SyslogClient

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
/**
 * Init class for server at url:port and the given protocol. The "prefix" String will be added to every message
 */
public SyslogClient(String url, int port, LogInsightProtocol proto, String prefix) throws Exception {
	checkParam(url, "url");
	checkParam(proto, "protocol");

	if (proto.equals(LogInsightProtocol.SYSLOG_TCP)) {
		syslog = Syslog.getInstance("tcp");
	} else if (proto.equals(LogInsightProtocol.SYSLOG_UDP)) {
		syslog = Syslog.getInstance("udp");
	} else if (proto.equals(LogInsightProtocol.SYSLOG_TLS)) {
		SSLTCPNetSyslogConfig syslogConfig = new SSLTCPNetSyslogConfig(url, port);
		syslog = Syslog.createInstance("sslTcp", syslogConfig);
	} else {
		throw new Exception("Protocol " + proto.toString() + " is not supported. Use one of " +
				LogInsightProtocol.SYSLOG_TCP + ", " + LogInsightProtocol.SYSLOG_UDP + 
	                        " or " + LogInsightProtocol.SYSLOG_TLS);
	}

	syslog.getConfig().setUseStructuredData(true);
	syslog.getConfig().setHost(url);
	syslog.getConfig().setPort(port);

	this.prefix = prefix;
}
 
开发者ID:BillRothVMware,项目名称:bora-strata-mar27,代码行数:27,代码来源:SyslogClient.java

示例7: createNorthboundInstance

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
/**
    * This is here, for now, until it can be properly wired and proper configuration can be created.
    * This allows generic 127.0.0.1:UDP/514 to work with OpenNMS having no configuration.  This is
    * trickery in its finest hour.
    */
   private void createNorthboundInstance() throws SyslogRuntimeException {
   	
   	LogUtils.infof(this, "Creating Syslog Northbound Instance:%s", m_destination.getName());
   	
   	String instName = m_destination.getName();
   	int facility = convertFacility(m_destination.getFacility());
   	SyslogProtocol protocol = m_destination.getProtocol();
   	SyslogConfigIF instanceConfiguration = createConfig(m_destination, protocol, facility);
   	instanceConfiguration.setIdent("OpenNMS");
   	instanceConfiguration.setCharSet(m_destination.getCharSet());
   	instanceConfiguration.setMaxMessageLength(m_destination.getMaxMessageLength());
   	instanceConfiguration.setSendLocalName(m_destination.isSendLocalName());
   	instanceConfiguration.setSendLocalTimestamp(m_destination.isSendLocalTime());
   	instanceConfiguration.setTruncateMessage(m_destination.isTruncateMessage());
   	instanceConfiguration.setUseStructuredData(SyslogConstants.USE_STRUCTURED_DATA_DEFAULT);

   	try {
   		Syslog.createInstance(instName, instanceConfiguration);
   	} catch (SyslogRuntimeException e) {
   		String msg = "Could not create northbound instance '%s': %s";
   		LogUtils.errorf(this, e, msg, instName, e);
   		throw e;
   	}

}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:31,代码来源:SyslogNorthbounder.java

示例8: _testMaxActiveSockets

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
protected int _testMaxActiveSockets(TCPNetSyslogServerConfigIF serverConfig) {
	Counter c = new Counter();
	
	serverConfig.setMaxActiveSockets(2);
	serverConfig.addEventHandler(c);
	
	SyslogServer.createThreadedInstance("tcp_maxactivesockets",serverConfig);
	
	TCPNetSyslogConfigIF config = new TCPNetSyslogConfig();
	config.setPort(8888);
		
	SyslogIF syslog1 = Syslog.createInstance("tcp_maxactivesockets1",config);
	syslog1.info("test1");
	syslog1.flush();
	SyslogUtility.sleep(200);
	
	SyslogIF syslog2 = Syslog.createInstance("tcp_maxactivesockets2",config);
	syslog2.info("test2");
	syslog2.flush();
	SyslogUtility.sleep(200);
	
	SyslogIF syslog3 = Syslog.createInstance("tcp_maxactivesockets3",config);
	syslog3.info("test3");
	syslog3.flush();
	SyslogUtility.sleep(200);

	syslog1.shutdown();
	SyslogUtility.sleep(200);

	Syslog.destroyInstance("tcp_maxactivesockets1");
	Syslog.destroyInstance("tcp_maxactivesockets2");
	Syslog.destroyInstance("tcp_maxactivesockets3");
	
	SyslogServer.destroyInstance("tcp_maxactivesockets");
	
	return c.counter;
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:38,代码来源:MaxActiveSocketsTest.java

示例9: testMaxQueueSize

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testMaxQueueSize() {
	int catchCount = 5;
	int maxQueueSize = 5;
	int messagesToSend = 15;
	int port = 7777;
	
	FakeSyslogServer server = new FakeSyslogServer(port,catchCount);
	Thread thread = new Thread(server);
	thread.start();
	
	BackLogCounter counter = new BackLogCounter();
	
	TCPNetSyslogConfigIF syslogConfig = new TCPNetSyslogConfig();
	syslogConfig.setPort(port);
	assertEquals(syslogConfig.getMaxQueueSize(),SyslogConstants.MAX_QUEUE_SIZE_DEFAULT);
	syslogConfig.setMaxQueueSize(maxQueueSize);
	syslogConfig.addBackLogHandler(counter);
	syslogConfig.addBackLogHandler(NullSyslogBackLogHandler.INSTANCE);
	
	SyslogIF syslog = Syslog.createInstance("maxQueueSizeTest",syslogConfig);
	
	for(int i=1; i<=messagesToSend; i++) {
		syslog.log(SyslogConstants.LEVEL_INFO,"test line " + i);
	}
	
	SyslogUtility.sleep(500);
	
	server.shutdown = true;

	SyslogUtility.sleep(500);

	System.out.println("Sent Messages:       " + messagesToSend);	
	System.out.println("Received Messages:   " + server.count);
	System.out.println("Backlogged Messages: " + counter.count);
	
	assertEquals(messagesToSend,(server.count+counter.count));
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:38,代码来源:MaxQueueSizeTest.java

示例10: testFreshConnectionInterval

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testFreshConnectionInterval() {
	TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig();
	serverConfig.setPort(8888);
	
	SocketCounter counter = new SocketCounter();
	serverConfig.addEventHandler(counter);
	
	SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_8888",serverConfig);

	SyslogUtility.sleep(100);

	TCPNetSyslogConfigIF config = new TCPNetSyslogConfig();
	config.setPort(8888);
	config.setFreshConnectionInterval(300);
	
	SyslogIF syslog = Syslog.createInstance("tcp_8888",config);

	for(int i=0; i<10; i++) {
		syslog.info("message " + i);
		SyslogUtility.sleep(100);
	}
	
	SyslogUtility.sleep(100);
	
	SyslogServer.destroyInstance(server);
	Syslog.destroyInstance(syslog);

	SyslogUtility.sleep(100);

	assertEquals("OpenCounter",3,counter.openCounter);
	assertEquals("EventCounter",10,counter.eventCounter);
	assertEquals("CloseCounter",3,counter.closeCounter);
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:34,代码来源:FreshConnectionIntervalTest.java

示例11: setUp

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void setUp() throws Exception {
	TCPNetSyslogConfig config = new TCPNetSyslogConfig();
	config.setPersistentConnection(false);
	
	Syslog.createInstance(instanceName,config);

	super.setUp();
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:9,代码来源:NonPersistentTCPNetSyslog4jTest.java

示例12: setUp

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void setUp() {
	if (!Syslog.exists("split")) {
		SplitSyslogConfig config = new SplitSyslogConfig();
		
		Syslog.createInstance("split", config);
	}
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:8,代码来源:SplitSyslogTest.java

示例13: testMultipleSyslog

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testMultipleSyslog() {
	FakeSyslogConfig config1 = new FakeSyslogConfig();
	FakeSyslog fake1 = (FakeSyslog) Syslog.createInstance("fake1", config1);

	FakeSyslogConfig config2 = new FakeSyslogConfig();
	FakeSyslog fake2 = (FakeSyslog) Syslog.createInstance("fake2", config2);

	MultipleSyslogConfig config = new MultipleSyslogConfig();
	config.addProtocol("fake1");
	config.addProtocol("fake2");
	
	SyslogIF syslog = Syslog.createInstance("multiple",config);
	
	assertEquals(0,fake1.total);
	assertEquals(0,fake2.total);
	
	syslog.debug("test");
	assertEquals(1,fake1.total);
	assertEquals(1,fake2.total);

	syslog.debug(new FakeSyslogMessage());
	assertEquals(1 + 2,fake1.total);
	assertEquals(1 + 2,fake2.total);

	syslog.info("test");
	assertEquals(1 + 2 + 4,fake1.total);
	assertEquals(1 + 2 + 4,fake2.total);
	
	syslog.info(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8,fake1.total);
	assertEquals(1 + 2 + 4 + 8,fake2.total);
	
	syslog.notice("test");
	assertEquals(1 + 2 + 4 + 8 + 16,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16,fake2.total);
	
	syslog.notice(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8 + 16 + 32,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32,fake2.total);

	syslog.warn("test");
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64,fake2.total);
	
	syslog.warn(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128,fake2.total);

	syslog.error("test");
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256,fake2.total);
	
	syslog.error(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512,fake2.total);

	syslog.critical("test");
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024,fake2.total);
	
	syslog.critical(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048,fake2.total);

	syslog.alert("test");
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096,fake2.total);
	
	syslog.alert(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192,fake2.total);

	syslog.emergency("test");
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384,fake2.total);
	
	syslog.emergency(new FakeSyslogMessage());
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 32768,fake1.total);
	assertEquals(1 + 2 + 4 + 8 + 16 + 32 + 64 + 128 + 256 + 512 + 1024 + 2048 + 4096 + 8192 + 16384 + 32768,fake2.total);
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:81,代码来源:MultipleSyslogCreateTest.java

示例14: testTimeout

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testTimeout() {
	TCPNetSyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig();
	serverConfig.setTimeout(150);
	serverConfig.setPort(7777);
	serverConfig.addEventHandler(new TimeoutHandler());

	TCPNetSyslogConfigIF clientConfig = new TCPNetSyslogConfig();
	clientConfig.setPort(7777);
	clientConfig.setThreaded(false);

	SyslogServer.createThreadedInstance("tcp_to",serverConfig);
	SyslogUtility.sleep(250);
	
	SyslogIF syslog = Syslog.createInstance("tcp_to",clientConfig);
	SyslogUtility.sleep(250);
	
	int mark = 0;
	
	for(int i=1; i<=10; i++) {
		if (i > 5) {
			mark--;
			
		} else {
			mark++;
		}
		
		int timeout = 35 * mark + 25;
		
		syslog.info("Test " + i + " (" + timeout + "ms) Should Timeout: " + (timeout > serverConfig.getTimeout() ? "yes" : "no"));
		SyslogUtility.sleep(timeout);
	}
	
	syslog.flush();
	SyslogUtility.sleep(200);
	
	SyslogServer.destroyInstance("tcp_to");
	
	SyslogUtility.sleep(200);
	
	Syslog.destroyInstance("tcp_to");
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:42,代码来源:TCPNetSyslog4jTest.java

示例15: setupSslClient

import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
protected void setupSslClient() throws Exception {
	SSLTCPNetSyslogConfig config = new SSLTCPNetSyslogConfig("127.0.0.1",10514);
	SSLConfigUtil.configure(config);
	Syslog.createInstance("sslTcp",config);
}
 
开发者ID:syslog4j,项目名称:syslog4j,代码行数:6,代码来源:SSLTCPNetSyslog4jTest.java


注:本文中的org.productivity.java.syslog4j.Syslog.createInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。