Java Code Examples for org.productivity.java.syslog4j.Syslog#createInstance()
The following examples show how to use
org.productivity.java.syslog4j.Syslog#createInstance() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractLog4jSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
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); }
Example 2
Source File: SyslogParameterTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
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)); }
Example 3
Source File: SyslogCreateAndDestroyTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
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) { // } }
Example 4
Source File: PooledTCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
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); }
Example 5
Source File: PooledSSLTCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
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); }
Example 6
Source File: MaxActiveSocketsTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
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; }
Example 7
Source File: MaxQueueSizeTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
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)); }
Example 8
Source File: FreshConnectionIntervalTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
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); }
Example 9
Source File: NonPersistentTCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void setUp() throws Exception { TCPNetSyslogConfig config = new TCPNetSyslogConfig(); config.setPersistentConnection(false); Syslog.createInstance(instanceName,config); super.setUp(); }
Example 10
Source File: SplitSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void setUp() { if (!Syslog.exists("split")) { SplitSyslogConfig config = new SplitSyslogConfig(); Syslog.createInstance("split", config); } }
Example 11
Source File: MultipleSyslogCreateTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
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); }
Example 12
Source File: TCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
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"); }
Example 13
Source File: SSLTCPNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
protected void setupSslClient() throws Exception { SSLTCPNetSyslogConfig config = new SSLTCPNetSyslogConfig("127.0.0.1",10514); SSLConfigUtil.configure(config); Syslog.createInstance("sslTcp",config); }
Example 14
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testTCPSession() { SyslogServerConfigIF serverConfig = new TCPNetSyslogServerConfig(9999); TCPSessionHandler handler1 = new TCPSessionHandler("a"); serverConfig.addEventHandler(handler1); TCPSessionHandler handler2 = new TCPSessionHandler("b"); serverConfig.addEventHandler(handler2); SyslogServerIF server = SyslogServer.createThreadedInstance("tcp_session",serverConfig); SyslogUtility.sleep(100); assertTrue(handler1.initialized); assertTrue(handler2.initialized); SyslogConfigIF config = new TCPNetSyslogConfig(); config.setPort(9999); TCPNetSyslogServer tcpServer = (TCPNetSyslogServer) server; SyslogIF syslog1 = Syslog.createInstance("tcp_session_1",config); syslog1.info("1"); syslog1.info("2"); SyslogUtility.sleep(100); assertEquals(1,tcpServer.getSessions().size()); SyslogIF syslog2 = Syslog.createInstance("tcp_session_2",config); syslog2.info("3"); syslog2.info("4"); syslog1.info("5"); syslog1.info("6"); syslog2.info("7"); syslog2.info("8"); SyslogUtility.sleep(100); assertEquals(2,tcpServer.getSessions().size()); syslog1.shutdown(); syslog2.shutdown(); SyslogServer.destroyInstance("tcp_session"); try { SyslogServer.getInstance("tcp_session"); fail(); } catch (SyslogRuntimeException sre) { // } assertEquals(4,handler1.eventCount[0]); assertEquals(0,handler1.eventCount[1]); assertEquals(4,handler1.eventCount[2]); assertEquals(0,handler1.eventCount[3]); assertEquals(0,handler2.eventCount[0]); assertEquals(4,handler2.eventCount[1]); assertEquals(0,handler2.eventCount[2]); assertEquals(4,handler2.eventCount[3]); assertEquals(1,handler1.closeCount[0]); assertEquals(0,handler1.closeCount[1]); assertEquals(1,handler1.closeCount[2]); assertEquals(0,handler1.closeCount[3]); assertEquals(0,handler2.closeCount[0]); assertEquals(1,handler2.closeCount[1]); assertEquals(0,handler2.closeCount[2]); assertEquals(1,handler2.closeCount[3]); SyslogUtility.sleep(100); assertTrue(handler1.destroyed); assertTrue(handler2.destroyed); }
Example 15
Source File: MultipleSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 3 votes |
protected void setupMultipleConfig() { ((AbstractNetSyslogConfig) Syslog.getInstance("tcp").getConfig()).setPort(TEST_PORT); MultipleSyslogConfig config = new MultipleSyslogConfig(); config.addProtocol("tcp"); Syslog.createInstance("multipleTcp",config); }
Example 16
Source File: SyslogServerSessionTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void testUDPSession() { SyslogServerConfigIF serverConfig = new UDPNetSyslogServerConfig(9999); UDPSessionHandler handler1 = new UDPSessionHandler("a"); serverConfig.addEventHandler(handler1); UDPSessionHandler handler2 = new UDPSessionHandler("b"); serverConfig.addEventHandler(handler2); SyslogServer.createThreadedInstance("udp_session",serverConfig); SyslogUtility.sleep(100); assertTrue(handler1.initialized); assertTrue(handler2.initialized); SyslogConfigIF config = new UDPNetSyslogConfig(); config.setPort(9999); SyslogIF syslog1 = Syslog.createInstance("udp_session_1",config); syslog1.info("1"); syslog1.info("2"); SyslogIF syslog2 = Syslog.createInstance("udp_session_2",config); syslog2.info("3"); syslog2.info("4"); SyslogUtility.sleep(100); syslog1.shutdown(); syslog2.shutdown(); SyslogServer.destroyInstance("udp_session"); try { SyslogServer.getInstance("udp_session"); fail(); } catch (SyslogRuntimeException sre) { // } assertTrue(handler1.okay); assertTrue(handler2.okay); SyslogUtility.sleep(250); assertTrue(handler1.destroyed); assertTrue(handler2.destroyed); }