我试过这种方式但产生以下错误: -
log4j:ERROR Precision option (0) isn't a positive integer.
public class log4jExample {
private static Logger logger = Logger.getRootLogger();
public static void main(String[] args) {
try {
SyslogAppender syslogAppender = new SyslogAppender();
syslogAppender.setName("SYSLOG");
syslogAppender.setSyslogHost("localhost");
syslogAppender.setFacility("Local3");
syslogAppender.setHeader(true);
PatternLayout layout = new PatternLayout("%d{dd-MMM-yyyy HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n");
syslogAppender.setLayout(layout);
Category category = Category.getInstance(log4jExample.class.getName());//logger.getParent();
Throwable thrwo = new Throwable();
LoggingEvent event = new LoggingEvent("log4jExample.class", category, 1000, Priority.DEBUG, new Object(), thrwo);
syslogAppender.append(event);
logger.debug("LOG");
} catch (Exception ex) {
System.out.println("Exc " + ex);
}
}
}
属性文件:
log4j.rootLogger=INFO, SYSLOG log4j.appender.SYSLOG=org.apache.log4j.net.SyslogAppender log4j.appender.SYSLOG.SyslogHost=localhost log4j.appender.SYSLOG.Facility=Local3 log4j.appender.SYSLOG.Header=true log4j.appender.SYSLOG.layout=org.apache.log4j.PatternLayout log4j.appender.SYSLOG.layout.ConversionPattern=java %d{ISO8601} %p %t %c{0}.%M - %m%n
答案 0 :(得分:1)
它几乎告诉你出了什么问题:
Precision option (0) isn't a positive integer.
正如您在PatternLayout
documentation中所读到的那样,c
有一个精确说明符,您使用0
将其设置为%c{0}
。 0
不是正整数。将其更改为数字> = 1