use of org.graylog2.log.GelfAppender in project xian by happyyangyuan.
the class GelfLog4j1Init method addGelfAppender.
private static void addGelfAppender() {
GelfAppender appender = new GelfJsonAppender();
appender.setName(GELF_APPENDER_NAME);
if (EnvUtil.isLan()) {
appender.setGraylogHost(XianConfig.get("gelfInputLanUrl"));
} else {
appender.setGraylogHost(XianConfig.get("gelfInputInternetUrl"));
}
appender.setGraylogPort(XianConfig.getIntValue("gelfInputInternetUrl"));
appender.setFacility("gelf-java");
appender.setLayout(new PatternLayout() {
{
setConversionPattern("%p %m");
}
});
appender.setExtractStacktrace(true);
appender.setIncludeLocation(false);
JSONObject additionalFields = new JSONObject() {
{
put("environment", EnvUtil.getEnv());
put("application", EnvUtil.getApplication());
put("pid", JavaPIDUtil.getProcessName());
put("nodeId", LocalNodeManager.LOCAL_NODE_ID);
}
};
appender.setAddExtendedInformation(true);
appender.setAdditionalFields(additionalFields.toJSONString());
appender.setOriginHost(JavaPIDUtil.getHostname());
// 让以上设置生效
appender.activateOptions();
Logger.getRootLogger().addAppender(appender);
}
Aggregations