本文整理汇总了Java中org.productivity.java.syslog4j.Syslog.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Syslog.getInstance方法的具体用法?Java Syslog.getInstance怎么用?Java Syslog.getInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.productivity.java.syslog4j.Syslog
的用法示例。
在下文中一共展示了Syslog.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHashVerify
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testHashVerify() {
SyslogIF syslog = Syslog.getInstance("tcp");
HashSyslogMessageModifier modifier = HashSyslogMessageModifier.createMD5();
modifier.getConfig().setSuffix(null);
String message = "md5 hash Test 1212 ABAB";
String modifiedMessage = modifier.modify(syslog,0,0,message);
System.out.println(modifiedMessage);
if (!modifier.verify(message,"fqfK2PYV76Wv9yNQjLoVeg==")) {
fail();
}
if (!modifier.verify(message,Base64.decode("fqfK2PYV76Wv9yNQjLoVeg=="))) {
fail();
}
if (!modifier.verify(modifiedMessage)) {
fail();
}
assertFalse(modifier.verify(null));
}
示例2: testMacVerify
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testMacVerify() {
SyslogIF syslog = Syslog.getInstance("udp");
MacSyslogMessageModifier modifier = MacSyslogMessageModifier.createHmacMD5("fb7Jl0VGnzY5ehJCdeff7bSZ5Vk=");
modifier.getConfig().setPrefix(" ");
modifier.getConfig().setSuffix(null);
String message = "hmacmd5 Test 3434 DCDC";
String modifiedMessage = modifier.modify(syslog,0,0,message);
System.out.println(modifiedMessage);
if (!modifier.verify(message,"MfWJ4XhFiMlPwnFEJ401zA==")) {
fail();
}
if (!modifier.verify(message,Base64.decode("MfWJ4XhFiMlPwnFEJ401zA=="))) {
fail();
}
if (!modifier.verify(modifiedMessage)) {
fail();
}
}
示例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) {
//
}
}
示例4: getSyslog
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
protected SyslogIF getSyslog(String protocol) {
if (!Syslog.exists(protocol)) {
fail("Protocol \"" + protocol + "\" does not exist");
}
SyslogIF syslog = Syslog.getInstance(protocol);
if (!(syslog instanceof MultipleSyslog)) {
syslog.getConfig().setIdent(APP_ID);
}
if (!(syslog.getConfig() instanceof MultipleSyslogConfig)) {
syslog.getConfig().setPort(TEST_PORT);
}
return syslog;
}
示例5: testTruncate
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
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();
}
示例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;
}
示例7: LogUploadClient
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public LogUploadClient(String url, int port, LogInsightProtocol proto) {
this.url = url;
this.port = port;
this.proto = proto;
assert (!proto.equals(LogInsightProtocol.UNKNOWN));
if (proto.equals(LogInsightProtocol.SYSLOG_TCP)) {
syslog = Syslog.getInstance("tcp");
} else if (proto.equals(LogInsightProtocol.SYSLOG_UDP)) {
syslog = Syslog.getInstance("udp");
} else {
System.err.println(proto + " not supported. Exiting...");
System.exit(1);
}
syslog.getConfig().setHost(url);
syslog.getConfig().setPort(port);
}
示例8: execute
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public Result execute(Result previousResult, int nr)
{
Result result = previousResult;
result.setNrErrors(1);
result.setResult( false );
String servername=environmentSubstitute(getServerName());
if(Const.isEmpty(servername)) {
logError(BaseMessages.getString(PKG, "JobEntrySyslog.MissingServerName"));
}
String messageString=environmentSubstitute(getMessage());
if(Const.isEmpty(messageString)) {
logError(BaseMessages.getString(PKG, "JobEntrySyslog.MissingMessage"));
}
int nrPort=Const.toInt(environmentSubstitute(getPort()), SyslogDefs.DEFAULT_PORT);
SyslogIF syslog=null;
try {
String pattern=null;
if(isAddTimestamp()) {
// add timestamp to message
pattern= environmentSubstitute(getDatePattern());
if(Const.isEmpty(pattern)) {
logError(BaseMessages.getString(PKG, "JobEntrySyslog.DatePatternEmpty"));
throw new KettleException(BaseMessages.getString(PKG, "JobEntrySyslog.DatePatternEmpty"));
}
}
// Open syslog connection
// Set a Specific Host, then Log to It
syslog = Syslog.getInstance("udp");
syslog.getConfig().setHost(servername);
syslog.getConfig().setPort(nrPort);
syslog.getConfig().setFacility(getFacility());
syslog.getConfig().setSendLocalName(false);
syslog.getConfig().setSendLocalTimestamp(false);
SyslogDefs.sendMessage(syslog, SyslogDefs.getPriority(getPriority()),
messageString, isAddTimestamp(), pattern, isAddHostName());
// message was sent
result.setNrErrors(0);
result.setResult(true);
} catch(Exception e){
logError(BaseMessages.getString(PKG, "JobEntrySyslog.ErrorSendingMessage", e.toString())); //$NON-NLS-1$
} finally{
if(syslog!=null) syslog.shutdown();
}
return result;
}
示例9: log
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void log(int level, String message) {
for(int i=0; i<this.multipleSyslogConfig.getProtocols().size(); i++) {
String protocol = (String) this.multipleSyslogConfig.getProtocols().get(i);
SyslogIF syslog = Syslog.getInstance(protocol);
syslog.log(level,message);
}
}
示例10: flush
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
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();
}
}
示例11: shutdown
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void shutdown() 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.shutdown();
}
}
示例12: testSyslog4jBackLogHandler
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testSyslog4jBackLogHandler() {
SyslogIF udp = Syslog.getInstance("udp");
SyslogIF tcp = Syslog.getInstance("tcp");
SyslogBackLogHandlerIF syslog4j = new Syslog4jBackLogHandler("udp");
syslog4j.initialize();
syslog4j.log(tcp,SyslogConstants.LEVEL_INFO,"Log4j BackLog Test Message - IGNORE","really");
syslog4j.log(tcp,-1,"Log4j BackLog Test Message - IGNORE","really");
syslog4j.down(tcp,null);
syslog4j.up(tcp);
syslog4j = new Syslog4jBackLogHandler("udp",false);
syslog4j.log(tcp,SyslogConstants.LEVEL_INFO,"Log4j BackLog Test Message - IGNORE","really");
syslog4j.log(tcp,-1,"Log4j BackLog Test Message - IGNORE","really");
syslog4j.down(udp,null);
syslog4j.up(udp);
syslog4j = new Syslog4jBackLogHandler(udp);
syslog4j.log(tcp,SyslogConstants.LEVEL_INFO,"Log4j BackLog Test Message - IGNORE","really");
syslog4j.log(tcp,-1,"Log4j BackLog Test Message - IGNORE","really");
syslog4j = new Syslog4jBackLogHandler(udp,false);
syslog4j.log(tcp,SyslogConstants.LEVEL_INFO,"Log4j BackLog Test Message - IGNORE","really");
syslog4j.log(tcp,-1,"Log4j BackLog Test Message - IGNORE","really");
try {
syslog4j.log(Syslog.getInstance("udp"),SyslogConstants.LEVEL_INFO,"Log4j BackLog Test Message - IGNORE","really");
fail();
} catch (SyslogRuntimeException sre) {
//
}
}
示例13: testNonDefinedSyslogInstance
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public void testNonDefinedSyslogInstance() {
try {
Syslog.getInstance("not_defined");
fail("not_defined shouldn't exist");
} catch (SyslogRuntimeException sre) {
assertTrue(sre.getMessage().startsWith("Syslog protocol \"not_defined\" not defined; call Syslogger.createSyslogInstance(protocol,config) first or use one of the following instances: "));
}
}
示例14: SyslogMessageGenerator
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public SyslogMessageGenerator() {
syslog = Syslog.getInstance("udp");
syslog.getConfig().setUseStructuredData(false);
syslog.getConfig().setHost("localhost");
syslog.getConfig().setFacility(SyslogIF.FACILITY_LOCAL0);
count = DEFAULT_COUNT;
delay = DEFAULT_DELAY;
}
示例15: Syslog4jBackLogHandler
import org.productivity.java.syslog4j.Syslog; //导入方法依赖的package包/类
public Syslog4jBackLogHandler(String protocol) {
this.syslog = Syslog.getInstance(protocol);
}