Java Code Examples for org.productivity.java.syslog4j.SyslogIF#flush()
The following examples show how to use
org.productivity.java.syslog4j.SyslogIF#flush() .
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: SplitSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void testTruncate() { setMessageLength(10); SyslogIF syslog = Syslog.getInstance("split"); syslog.getConfig().setTruncateMessage(true); syslog.info("T"); syslog.info("Test 1234"); syslog.info("Test 12345"); syslog.info("Test 654321"); syslog.info("Test 12345 For now is the time for all good men to come to the aid of their country"); assertSyslog(syslog,new String[] {"T", "Test 1234", "Test 12345", "Test 65432", "Test 12345" } ); syslog.flush(); }
Example 2
Source File: SplitSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
protected void assertSyslog(SyslogIF syslog, String[] expectedMessages) { SplitSyslog splitSyslog = (SplitSyslog) syslog; List lastMessages = splitSyslog.getLastMessages(); if (lastMessages.size() < 1) { fail("No messages received"); } for(int i=0; i<lastMessages.size(); i++) { String lastMessage = ((String) lastMessages.get(i)).substring(21 + this.localNameLength); assertEquals(expectedMessages[i],lastMessage); } syslog.flush(); }
Example 3
Source File: UDPPCISyslogMessageTest.java From syslog4j with GNU Lesser General Public License v2.1 | 6 votes |
public void testPCISyslogMessage() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); message = new PCISyslogMessage("a","b",new Date(),"c","d","e").createMessage(); syslog.info("[TEST] " + message); events.add("[TEST] " + message); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 4
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 5
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void testHTMLEntityEscapeMessageModifier() { SyslogMessageModifierIF messageModifier = new HTMLEntityEscapeSyslogMessageModifier(); String nullHtml = messageModifier.modify(null,0,0,null); assertNull(nullHtml); String emptyHtml = messageModifier.modify(null,0,0,""); assertEquals("",emptyHtml); // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); syslog.getConfig().addMessageModifier(HTMLEntityEscapeSyslogMessageModifier.createDefault()); // SEND HTML message = "[TEST] <html>&\"test\"&'" + "\t" + "</html>" + (char) 255; syslog.info(message); events.add("[TEST] <html>&"test"&'	</html>ÿ"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 6
Source File: MultipleSyslog.java From syslog4j with GNU Lesser General Public License v2.1 | 5 votes |
public void flush() throws SyslogRuntimeException { for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) { String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i); SyslogIF syslog = Syslog.getInstance(protocol); syslog.flush(); } }
Example 7
Source File: UnixSocketSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testUnixSyslog() { if (Boolean.getBoolean(SyslogConstants.DISABLE_UNIX_PROPERTY)) { assertTrue(true); return; } SyslogIF syslog = Syslog.getInstance(SyslogConstants.UNIX_SOCKET); UnixSocketSyslogConfig config = (UnixSocketSyslogConfig) syslog.getConfig(); config.setPath("/tmp/syslog4j.sock"); config.setType(UnixSocketSyslogConfig.SOCK_STREAM); syslog.info(this.getClass().getName() + ": unix_socket " + System.currentTimeMillis()); syslog.flush(); SyslogUtility.sleep(1000); }
Example 8
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 9
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void _testSendReceive(boolean sortEvents, boolean sortRecordedEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); for(int i=0; i<getMessageCount(); i++) { String message = "[TEST] " + i + " / " + System.currentTimeMillis(); syslog.info(message); events.add(message); } SyslogUtility.sleep(200); syslog.flush(); verifySendReceive(events,sortEvents,sortRecordedEvents); }
Example 10
Source File: UnixSyslogTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testUnixSyslog() { if (Boolean.getBoolean(SyslogConstants.DISABLE_UNIX_PROPERTY)) { assertTrue(true); return; } SyslogIF syslog = Syslog.getInstance(SyslogConstants.UNIX_SYSLOG); syslog.getConfig().setFacility(SyslogIF.FACILITY_KERN); syslog.error(this.getClass().getName() + ": unix_syslog " + System.currentTimeMillis()); syslog.flush(); syslog.shutdown(); AbstractSyslog abstractSyslog = (AbstractSyslog) syslog; assertNull(abstractSyslog.getWriter()); abstractSyslog.returnWriter(null); }
Example 11
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testMacWithKeys() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // HmacSHA1 SET UP Key key = createKey("fb7Jl0VGnzY5ehJCabcf7bSZ5Vk=","SHA1"); SyslogMessageModifierIF messageModifier = MacSyslogMessageModifier.createHmacSHA1(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA1 message = "[TEST] This Line Will Have an HmacSHA1 Hash"; syslog.info(message); events.add(message + " {6CIz39WE8wgxwpsqPievrtDWaXM=}"); // HmacSHA256 SET UP key = createKey("+v2mHoOx6QGLqYFa/Tx0J7BkXSK4HEVMtGHtG66vQ54=","SHA256"); syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA256(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA256 message = "[TEST] This Line Will Have an HmacSHA256 Hash"; syslog.info(message); events.add(message + " {sEpaXO6fvnO7szaJSjcqoIVl0C180/oWSP0rs6RFfB8=}"); // HmacSHA512 SET UP key = createKey("w5sn5tOHpk/jBTWAQ4doTlSbtE1GQZC2RCe2/ayTy67zscXFEdlT/Zwsm5GFrjOwxlZITrAaq+s2KFCNpBTDig==","SHA512"); syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA512(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA512 message = "[TEST] This Line Will Have an HmacSHA512 Hash"; syslog.info(message); events.add(message + " {Ddx+6JegzcifzT5H82BISGeGQ9FCA5biW51qItH9y95tJvFnFv+0+Tx/Kv0HAms2jv6iq08tlL7IFI1gMUWBtA==}"); // HmacMD5 SET UP syslog.getConfig().removeAllMessageModifiers(); key = createKey("fb7Jl0VGnzY5ehJCdeff7bSZ5Vk=","MD5"); messageModifier = MacSyslogMessageModifier.createHmacMD5(key); syslog.getConfig().addMessageModifier(messageModifier); // HmacMD5 message = "[TEST] This Line Will Have an HmacMD5 Hash"; syslog.info(message); events.add(message + " {Z+BBv07/AlQ55a6d88OuGg==}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 12
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testMac() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // HmacSHA1 SET UP String base64Key = "fb7Jl0VGnzY5ehJCabcf7bSZ5Vk="; SyslogMessageModifierIF messageModifier = MacSyslogMessageModifier.createHmacSHA1(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA1 message = "[TEST] This Line Will Have an HmacSHA1 Hash"; syslog.info(message); events.add(message + " {6CIz39WE8wgxwpsqPievrtDWaXM=}"); // HmacSHA256 SET UP base64Key = "+v2mHoOx6QGLqYFa/Tx0J7BkXSK4HEVMtGHtG66vQ54="; syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA256(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA256 message = "[TEST] This Line Will Have an HmacSHA256 Hash"; syslog.info(message); events.add(message + " {sEpaXO6fvnO7szaJSjcqoIVl0C180/oWSP0rs6RFfB8=}"); // HmacSHA512 SET UP base64Key = "w5sn5tOHpk/jBTWAQ4doTlSbtE1GQZC2RCe2/ayTy67zscXFEdlT/Zwsm5GFrjOwxlZITrAaq+s2KFCNpBTDig=="; syslog.getConfig().removeAllMessageModifiers(); messageModifier = MacSyslogMessageModifier.createHmacSHA512(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacSHA512 message = "[TEST] This Line Will Have an HmacSHA512 Hash"; syslog.info(message); events.add(message + " {Ddx+6JegzcifzT5H82BISGeGQ9FCA5biW51qItH9y95tJvFnFv+0+Tx/Kv0HAms2jv6iq08tlL7IFI1gMUWBtA==}"); // HmacMD5 SET UP syslog.getConfig().removeAllMessageModifiers(); base64Key = "fb7Jl0VGnzY5ehJCdeff7bSZ5Vk="; messageModifier = MacSyslogMessageModifier.createHmacMD5(base64Key); syslog.getConfig().addMessageModifier(messageModifier); // HmacMD5 message = "[TEST] This Line Will Have an HmacMD5 Hash"; syslog.info(message); events.add(message + " {Z+BBv07/AlQ55a6d88OuGg==}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 13
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testContinousChecksum() { try { new ChecksumSyslogMessageModifier(null); fail("Should not allow an empty config into a modifier"); } catch (SyslogRuntimeException sre) { assertTrue(true); } // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // CRC32 SET UP ChecksumSyslogMessageModifierConfig config = ChecksumSyslogMessageModifierConfig.createCRC32(); assertFalse(config.isContinuous()); config.setContinuous(true); assertTrue(config.isContinuous()); ChecksumSyslogMessageModifier modifier = new ChecksumSyslogMessageModifier(config); syslog.getConfig().addMessageModifier(modifier); // CRC32 Message #1 message = "[TEST] This Line Will Have a CRC32 Checksum 1"; syslog.info(message); events.add(message + " {6E2A9F99}"); // CRC32 Message #2 message = "[TEST] This Line Will Have a CRC32 Checksum 2"; syslog.info(message); events.add(message + " {7E736783}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 14
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testChecksum() { try { new ChecksumSyslogMessageModifier(null); fail("Should not allow an empty config into a modifier"); } catch (SyslogRuntimeException sre) { assertTrue(true); } // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // CRC32 SET UP syslog.getConfig().addMessageModifier(ChecksumSyslogMessageModifier.createCRC32()); // CRC32 message = "[TEST] This Line Will Have a CRC32 Checksum"; syslog.info(message); events.add(message + " {F8E7A4E4}"); // ADLER32 SET UP syslog.getConfig().removeAllMessageModifiers(); ChecksumSyslogMessageModifier adler32Modifier = ChecksumSyslogMessageModifier.createADLER32(); syslog.getConfig().addMessageModifier(adler32Modifier); // ADLER32 message = "[TEST] This Line Will Have an ADLER32 Checksum"; syslog.info(message); events.add(message + " {5AD70EE4}"); // ADLER32 SET UP with LOWER FIRST syslog.getConfig().insertMessageModifier(0,StringCaseSyslogMessageModifier.LOWER); // ADLER32 with LOWER FIRST message = "[TEST] This Line Will Have an ADLER32 Checksum"; syslog.info(message); events.add(message.toLowerCase() + " {8A1710A4}"); // ADLER32 adler32Modifier.getConfig().setChecksum(new Adler32()); message = "[TEST] This Line Will Have an ADLER32 Checksum 2"; syslog.info(message); events.add(message.toLowerCase() + " {ABD110F6}"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 15
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testSequential() { // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); // SET UP SequentialSyslogMessageModifier sequentialModifier = SequentialSyslogMessageModifier.createDefault(); syslog.getConfig().addMessageModifier(sequentialModifier); assertEquals(sequentialModifier.getConfig().getFirstNumber(),SequentialSyslogMessageModifierConfig.createDefault().getFirstNumber()); // ZERO message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #0000"); // ONE message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #0001"); // NINE THOUSAND NINE HUNDRED NIGHTY EIGHT sequentialModifier.setNextSequence(SyslogConstants.LEVEL_INFO,9998); message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #9998"); // NINE THOUSAND NINE HUNDRED NIGHTY NINE message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #9999"); // ZERO message = "[TEST] Sequence Test"; syslog.info(message); events.add(message + " #0000"); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 16
Source File: SyslogMessageModifierTest.java From syslog4j with GNU Lesser General Public License v2.1 | 4 votes |
public void testStringCase() { // CHECK OUT OF BOUNDS try { new StringCaseSyslogMessageModifier((byte) 3); fail("Should not be able to construct with an invalid byte value"); } catch (SyslogRuntimeException sre) { assertTrue(true); } // PREPARE List events = new ArrayList(); String message = null; String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); syslog.getConfig().removeAllMessageModifiers(); ArrayList list = new ArrayList(); ((AbstractSyslogConfig) syslog.getConfig()).setMessageModifiers(list); // UPPER SET UP list.add(StringCaseSyslogMessageModifier.UPPER); // UPPER message = "[TEST] abcDEF Abc deF eFg"; syslog.debug(message); events.add(message.toUpperCase()); // LOWER SET UP syslog.getConfig().removeAllMessageModifiers(); syslog.getConfig().addMessageModifier(StringCaseSyslogMessageModifier.LOWER); // LOWER message = "[TEST] ABCdef aBC DEf EfG"; syslog.warn(message); events.add(message.toLowerCase()); // VERIFY SyslogUtility.sleep(pause); syslog.flush(); verifySendReceive(events,false,false); }
Example 17
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void _testSendReceivePCIMessages(boolean sortEvents, boolean sortRecordedEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); PCISyslogMessage message = new PCISyslogMessage(); message.setUserId("[TEST]"); syslog.debug(message); events.add(message.createMessage()); syslog.info(message); events.add(message.createMessage()); syslog.notice(message); events.add(message.createMessage()); syslog.warn(message); events.add(message.createMessage()); syslog.error(message); events.add(message.createMessage()); syslog.critical(message); events.add(message.createMessage()); syslog.alert(message); events.add(message.createMessage()); syslog.emergency(message); events.add(message.createMessage()); syslog.log(SyslogConstants.LEVEL_INFO,message); events.add(message.createMessage()); SyslogUtility.sleep(100); syslog.flush(); verifySendReceive(events,sortEvents,sortRecordedEvents); }
Example 18
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void _testSendReceiveStructuredMessages(boolean sortEvents, boolean sortRecordedEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); this.server.getConfig().setUseStructuredData(true); Map m2 = new HashMap(); m2.put("foo","bar"); Map m1 = new HashMap(); m1.put("testa",m2); StructuredSyslogMessageIF message = new StructuredSyslogMessage("[TEST]",m1,"testb"); syslog.debug(message); events.add(message.createMessage()); syslog.info(message); events.add(message.createMessage()); syslog.notice(message); events.add(message.createMessage()); syslog.warn(message); events.add(message.createMessage()); syslog.error(message); events.add(message.createMessage()); syslog.critical(message); events.add(message.createMessage()); syslog.alert(message); events.add(message.createMessage()); syslog.emergency(message); events.add(message.createMessage()); syslog.log(SyslogConstants.LEVEL_INFO,message); events.add(message.createMessage()); syslog.log(SyslogConstants.LEVEL_INFO,message.createMessage()); events.add(message.createMessage()); SyslogUtility.sleep(100); syslog.flush(); verifySendReceive(events,sortEvents,sortRecordedEvents); this.server.getConfig().setUseStructuredData(false); }
Example 19
Source File: AbstractNetSyslog4jTest.java From syslog4j with GNU Lesser General Public License v2.1 | 2 votes |
public void _testThreadedSendReceive(int threads, boolean sortEvents, boolean sortRecordedEvents, List backLogEvents){ List events = new ArrayList(); String protocol = getClientProtocol(); SyslogIF syslog = getSyslog(protocol); for(int t=0; t<threads; t++) { List messageList = new ArrayList(); for(int i=0; i<getMessageCount(); i++) { String message = "[TEST] " + t + " / " + i + " / " + System.currentTimeMillis(); messageList.add(message); events.add(message); } Runnable r = new ClientThread(syslog,messageList); Thread thread = new Thread(r); thread.setName("Syslog: " + protocol + " [" + t + "]"); thread.start(); } SyslogUtility.sleep(100); syslog.flush(); if (backLogEvents != null) { List recordedEvents = this.recorderEventHandler.getRecordedEvents(); int haveCount = recordedEvents.size() + backLogEvents.size(); long startTime = System.currentTimeMillis(); while(haveCount < events.size()) { System.out.println("Count: " + haveCount + "/" + events.size()); SyslogUtility.sleep(250); haveCount = recordedEvents.size() + backLogEvents.size(); long currentTime = System.currentTimeMillis(); if ((currentTime - startTime) > 5000) { break; } } System.out.println("Sent Events: " + events.size()); System.out.println("BackLog Events: " + backLogEvents.size()); System.out.println("Recorded Events: " + recordedEvents.size()); if (backLogEvents.size() < 1) { fail("No backLog events received"); } if (recordedEvents.size() < 1) { fail("No recorded events received"); } if ((recordedEvents.size() + backLogEvents.size()) != events.size()) { fail("Lost some events"); } recordedEvents.addAll(backLogEvents); } verifySendReceive(events,sortEvents,sortRecordedEvents); }