logging - Thorntail (wldfly swarm) 记录到 Greylog
问题描述
如何启用 wildfly swarm 日志记录到 graylog - 或者换句话说:以 gelf 格式登录?有人已经这样做了吗?
在 graylog 市场上似乎只有框架与 log4j ( gelfj ) 或 logback 一起工作,但不与 jboss 日志系统一起工作。从关于 SO 的其他问题来看,我认为不可能将 thorntail 配置为使用 log4j 登录(无论如何这都会感觉有些不对劲:通过 jboss 登录到 log4j 以将其汇集到 gelf 中。)
基本要求是我想 docker 我的 swarm 应用程序并使用 graylog 作为集中式日志记录。我知道我可以将 docker 配置为登录到 gelf,但这意味着我无法控制我的应用程序中的扩展 gelf 功能,对吧?
从 thorntail/swarm 实现集中日志记录的首选方法是什么?
解决方案
是的,可以将日志发送到 thorntail 中的 graylog,因为有些人已经为我们实现了一个 jboss 兼容的 gelf 日志处理程序。一些限制将是您使用的日志记录框架。我不得不通过 slf4j 使用 jboss 记录器,并且没有花更多时间让 log4j 运行。也许您会发现如何实现这一点。
我在哪里可以得到一个 jboss 兼容的 gelf 日志处理程序?
在这里,您可以找到支持 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.为thorntail创建自定义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");
}
}
}
推荐阅读
- tensorflow - 从 Keras 模型的 predict() 方法返回实例 ID 和预测
- reactjs - React EdiText - 使用 Enter 键提交
- java - 通过 JNI 创建和设置数组
- c# - 为什么没有支持的机制可用于使用 Xamarin.iOS 在 C# 中创建可从 Objective-C 调用的库。?
- gradle - Android 构建失败:无法解析配置“:debugCompileClasspath”的所有文件
- python-3.x - - 不支持的操作数类型:“str”和“int”:在比较爬网网站上的基本域名和子域名时
- c# - IEnumerable 上的自定义扩展方法
- java - 在java中的n-ary树中找到一个不包含最大子节点数的节点
- c++ - 打破 While 循环 C++
- javascript - 如何在 React 中从非 React 库中渲染 div 对象?