我如何启用野蝇群日志记录到greylog -或者换句话说:日志记录是gelf格式的吗?已经有人这么做了吗?
在灰度日志市场上,似乎只有一些框架可以与log4j (gelfj)或logback一起使用,而不是jboss日志记录系统。从其他问题看,我假设不可能将thorntail配置为使用log4j登录(这无论如何都会让人感觉有些不对劲:通过jboss进行管道登录,登录到log4j,然后将其导入到gelf中。)
底层需求是,我希望停靠我的swarm应用程序,并使用greylog作为集中式日志记录。我知道我可以将docker配置为登录gelf,但这意味着我无法控制应用程序中扩展的gelf功能,对吧?
从thorntail/swarm实现集中化日志记录的首选方式是什么?
发布于 2019-03-31 17:39:16
是的,可以将日志发送到thorntail中的graylog,因为有些人已经为我们实现了与jboss兼容的gelf日志处理程序。一些限制是您所使用的日志记录框架。我不得不通过slf4j使用log4j记录器,并且没有花费更多的时间来运行jboss。也许你会发现如何做到这一点。
我在哪里可以为gelf获得一个jboss兼容的日志处理程序?
在这里,您可以找到支持gelf格式的jboss兼容日志处理程序的git存储库。
https://github.com/mp911de/logstash-gelf
如何配置日志处理程序?
有关此日志处理程序的文档,请参阅以下链接。
如何将其集成到thorntail中?
为此,您必须做一些工作。
1.将依赖项添加到pom.xml
<dependency>
<groupId>biz.paluch.logging</groupId>
<artifactId>logstash-gelf</artifactId>
<version>1.12.0</version>
<scope>provided</scope>
</dependency>2.创建自定义module.xml
src/main/resources/modules/biz/paluch/logging/main/module.xml
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.3" name="biz.paluch.logging">
<resources>
<artifact name="biz.paluch.logging:logstash-gelf:1.11.2" />
<artifact name="redis.clients:jedis:2.9.0" />
<artifact name="org.apache.commons:commons-pool2:2.4.3" />
</resources>
<dependencies>
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="javax.api" />
<module name="org.jboss.logmanager" />
</dependencies>
</module>3.配置thorntail以使用此日志处理程序
swarm:
jaeger:
logging:
file-handlers:
custom-handlers:
GELF-HTTP:
named-formatter: MY_LOG_PATTERN
attribute-class: biz.paluch.logging.gelf.wildfly.WildFlyGelfLogHandler
module: biz.paluch.logging
properties:
host: "http://graylog"
extractStackTrace: true
includeFullMdc: true
maximumMessageSize: 1048576
root-logger:
level: WARN
handlers:
- CONSOLE
- GELF-HTTP如何在我的应用程序中使用记录器?
import org.jboss.logging.Logger;
import org.slf4j.LoggerFactory;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Default;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
/**
* This produces and configures the logger.
*
* @author Thomas Herzog <herzog.thomas81@gmail.com>
* @since 06/08/18
*/
@ApplicationScoped
public class LoggerConfiguration {
@Produces
@Default
@Dependent
Logger createLogger(final InjectionPoint ip) {
if (ip.getBean() != null) {
return Logger.getLogger(ip.getBean().getBeanClass());
} else if (ip.getMember() != null) {
return Logger.getLogger(ip.getMember().getDeclaringClass());
} else {
return Logger.getLogger("default");
}
}
}https://stackoverflow.com/questions/50905307
复制相似问题