简体   繁体   English

Logback 和 Graylog 无法在 Mac 上使用 syslog 进行通信

[英]Logback and Graylog cannot communicate on a Mac using syslog

I want to send logmessages from a Java application to Graylog, using slf4j on top of logback with a logback GELF-appender on one side and a Graylog GELF-input on the other.我想将日志消息从 Java 应用程序发送到 Graylog,在 logback 之上使用 slf4j,一侧使用 logback GELF-appender,另一侧使用 Graylog GELF-input。 To test it, i'm running Graylog in a Docker container (using Docker for Mac) and run my Java application locally.为了测试它,我在 Docker 容器中运行 Graylog(使用 Docker for Mac)并在本地运行我的 Java 应用程序。 The gist of my story is that the Graylog GELF-input does not receive anything from the Java application.我的故事的要点是 Graylog GELF 输入不会从 Java 应用程序接收任何内容。 Somehow the Java application and Graylog don't seem to be able to communicate.不知何故,Java 应用程序和 Graylog 似乎无法进行通信。 The same applies when i switch to a different appender/input combination (one based on syslog records).当我切换到不同的 appender/input 组合(一个基于 syslog 记录的组合)时,同样适用。 However, when echoing a message from the commandline to a different Graylog input, namely the RAW input that's listening to port 5555, that message is received fine.然而,从命令行到一个不同的Graylog输入,即原始输入是在听端口5555,该消息被接收的精细呼应的消息时。

Any idea what the problem is?知道问题是什么吗? This is my setup using GELF:这是我使用 GELF 的设置:

Java app: Java应用程序:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogDemo {

    public static void main(String[] args) {
        Logger logger = LoggerFactory.getLogger(LogDemo.class);
        logger.error("Hello World 2");
    }
}

pom.xml pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>logdemo</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>de.appelgriepsch.logback</groupId>
      <artifactId>logback-gelf-appender</artifactId>
      <version>1.5</version>
    </dependency>
  </dependencies>
</project>

logback.xml登录文件

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="GELF" class="de.appelgriepsch.logback.GelfAppender">
    <server>localhost</server>
    <port>12201</port>
    <protocol>TCP</protocol>
  </appender>

  <root level="error">
    <appender-ref ref="GELF"/>
  </root>
</configuration>

Graylog docker startup: Graylog docker 启动:

$ docker run --name mongo -d mongo:3
$ docker run --name elasticsearch \
    -e "http.host=0.0.0.0" \
    -e "ES_JAVA_OPTS=-Xms512m -Xmx512m" \
    -d docker.elastic.co/elasticsearch/elasticsearch-oss:6.8.10
$ docker run --link mongo --link elasticsearch \
    -p 9000:9000 -p 12201:12201 -p 1514:1514 -p 5555:5555 \
    -e GRAYLOG_HTTP_EXTERNAL_URI="http://127.0.0.1:9000/" \
    -d graylog/graylog:3.3

Graylog GELF tcp input (running): Graylog GELF tcp 输入(正在运行):

bind_address: 0.0.0.0
decompress_size_limit: 8388608
max_message_size: 2097152
number_worker_threads: 4
override_source: <empty>
port: 12201
recv_buffer_size: 1048576
tcp_keepalive: false
tls_cert_file: <empty>
tls_client_auth: disabled
tls_client_auth_cert_file: <empty>
tls_enable: false
tls_key_file: <empty>
tls_key_password:********
use_null_delimiter: true

As stated, when i run the java app and Graylog is running as a Docker container in the background, Graylog does not receive the logmessage i sent.如上所述,当我运行 Java 应用程序并且 Graylog 在后台作为 Docker 容器运行时,Graylog 没有收到我发送的日志消息。 However, when i type the following on my commandline (using Terminal on Mac), the message IS received by the Graylog RAW input:但是,当我在命令行上键入以下内容时(在 Mac 上使用终端),Graylog RAW 输入接收到消息:

$ echo "Testmessage" | nc localhost 5555

Does somebody got a clue what i'm doing wrong?有人知道我做错了什么吗?

I found a solution, though i'm not sure what the exact cause of the problem was.我找到了解决方案,但我不确定问题的确切原因是什么。 The solution was to use a different Gelf appender.解决方案是使用不同的 Gelf appender。 Instead of the one i mentioned above, i'm now using the following one:而不是我上面提到的一个,我现在使用以下一个:

<dependency>
  <groupId>de.siegmar</groupId>
  <artifactId>logback-gelf</artifactId>
  <version>2.2.0</version>
</dependency>

That did the trick, but as i said, i'm unsure why the one i used earlier did not work.那确实奏效了,但正如我所说,我不确定为什么我之前使用的那个不起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM