Nic*_*s K 0 java logging logback photon-os fluent-bit
我正在尝试将日志从基本的 java maven 项目发送到远程计算机上配置的 Fluent-bit。Fluent-bit 然后会将它们写入文件。这是我的基本java配置。
爪哇
private final static Logger logger = LoggerFactory.getLogger(App.class);
public static void main(String[] args) {
for (int i = 0; ; i++) {
logger.debug("Warn msg");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// do nothing now
}
}
}
Run Code Online (Sandbox Code Playgroud)
和 logback.xml
<appender name="fluentd" class="ch.qos.logback.more.appenders.DataFluentAppender">
<remoteHost>xx.xxx.xxx.xxx</remoteHost>
<port>7777</port>
<encoder>
<pattern>%message%n</pattern>
</encoder>
</appender>
<root level="DEBUG">
<appender-ref ref="fluentd" />
</root>
Run Code Online (Sandbox Code Playgroud)
Fluent位配置:
td-agent-bit.conf
[INPUT]
Name tcp
Listen xx.xxx.xxx.xxx
Port 7777
Parsers_File /etc/td-agent-bit/parsers.conf
Parser custom_parser
[OUTPUT]
Name file
Match *
Path /home/td-agent-bit/output.txt
Run Code Online (Sandbox Code Playgroud)
解析器配置文件
[PARSER]
Name custom_parser
Format regex
Regex .*
Run Code Online (Sandbox Code Playgroud)
当应用程序运行时,我不断收到以下异常
[2018/09/27 08:29:13] [跟踪] [in_tcp] read()=74 pre_len=370 now_len=444
[2018/09/27 08:29:13] [debug] [in_serial] 无效的 JSON 消息,跳过
但是当我尝试通过命令行测试配置时它可以工作
echo '{"key 1": 10, "key 2": "YYY"}' | nc xx.xxx.xxx.xxx 7777
Run Code Online (Sandbox Code Playgroud)
我没有收到任何异常,并且输出文件具有所有权限。远程机器也是基于光子操作系统的系统。
任何想法将不胜感激。
因此,经过一些研究和我在此处打开的票证后,我发现我使用了错误的插件。
所有java配置都是正确的。只需要对以下内容进行更改td-agent-bit.conf
[INPUT]
Name forward
Listen xx.xxx.xxx.xxx
Port 7777
Run Code Online (Sandbox Code Playgroud)
我们需要使用forward插件而不是tcp插件。该插件将侦听 7777 端口上的任何传入消息并将其重定向到文件。
请注意,TCP 输入插件仅接受 JSON 映射作为记录,而不接受转发协议那样的 msgpack。
| 归档时间: |
|
| 查看次数: |
9111 次 |
| 最近记录: |