Java Code Examples for org.productivity.java.syslog4j.SyslogIF#error()
The following examples show how to use
org.productivity.java.syslog4j.SyslogIF#error() .
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: SyslogDefs.java From hop with Apache License 2.0 | 4 votes |
public static void sendMessage( SyslogIF syslog, int priority, String message, boolean addTimestamp, String pattern, boolean addHostName ) { String messageString = message; // Do we need to add hostname? if ( addHostName ) { messageString = Const.getHostname() + " " + messageString; } // Do we need to add timestamp if ( addTimestamp ) { SimpleDateFormat dateFormat = new SimpleDateFormat( pattern ); dateFormat.setTimeZone( TimeZone.getDefault() ); messageString = dateFormat.format( Calendar.getInstance().getTime() ) + " : " + messageString; } // send message switch ( priority ) { case SyslogConstants.LEVEL_EMERGENCY: syslog.emergency( messageString ); break; case SyslogConstants.LEVEL_ALERT: syslog.alert( messageString ); break; case SyslogConstants.LEVEL_CRITICAL: syslog.critical( messageString ); break; case SyslogConstants.LEVEL_ERROR: syslog.error( messageString ); break; case SyslogConstants.LEVEL_WARN: syslog.warn( messageString ); break; case SyslogConstants.LEVEL_NOTICE: syslog.notice( messageString ); break; case SyslogConstants.LEVEL_INFO: syslog.info( messageString ); break; case SyslogConstants.LEVEL_DEBUG: syslog.debug( messageString ); break; default: break; } }
Example 2
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 3
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 4
Source File: SyslogDefs.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public static void sendMessage( SyslogIF syslog, int priority, String message, boolean addTimestamp, String pattern, boolean addHostName ) { String messageString = message; // Do we need to add hostname? if ( addHostName ) { messageString = Const.getHostname() + " " + messageString; } // Do we need to add timestamp if ( addTimestamp ) { SimpleDateFormat dateFormat = new SimpleDateFormat( pattern ); dateFormat.setTimeZone( TimeZone.getDefault() ); messageString = dateFormat.format( Calendar.getInstance().getTime() ) + " : " + messageString; } // send message switch ( priority ) { case SyslogConstants.LEVEL_EMERGENCY: syslog.emergency( messageString ); break; case SyslogConstants.LEVEL_ALERT: syslog.alert( messageString ); break; case SyslogConstants.LEVEL_CRITICAL: syslog.critical( messageString ); break; case SyslogConstants.LEVEL_ERROR: syslog.error( messageString ); break; case SyslogConstants.LEVEL_WARN: syslog.warn( messageString ); break; case SyslogConstants.LEVEL_NOTICE: syslog.notice( messageString ); break; case SyslogConstants.LEVEL_INFO: syslog.info( messageString ); break; case SyslogConstants.LEVEL_DEBUG: syslog.debug( messageString ); break; default: break; } }
Example 5
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 6
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); }