t0xa / gelfj

Graylog Extended Log Format (GELF) implementation in Java and log4j appender without any dependencies.
https://github.com/t0xa/gelfj/wiki
Other
187 stars 115 forks source link

[need_help] graylog2 appender not send data to host:port. #123

Open ghost opened 6 years ago

ghost commented 6 years ago

Hello. Need some help, please. I try make a blank project with only log4j usage with graylog2 appender. But in graylog2 i don't see messages and wireshark don't see a requests on TCP 12201.

pom.xml:

<groupId>test</groupId>
<artifactId>glog</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
    <dependency>
        <groupId>org.graylog2</groupId>
        <artifactId>gelfj</artifactId>
        <version>1.1.12</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
</dependencies>

log4j.properties:

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.conversionPattern=%d{ABSOLUTE} %5p %t %c{1}:%M:%L - %m%n
# Define the graylog2 destination
log4j.appender.graylog2=org.graylog2.log.GelfAppender
log4j.appender.graylog2.graylogHost=127.0.0.1
log4j.appender.graylog2.graylogPort=12201
log4j.appender.graylog2.originHost=localhost
log4j.appender.graylog2.facility=gelf-java
log4j.appender.graylog2.layout=org.apache.log4j.PatternLayout
log4j.appender.graylog2.extractStacktrace=true
log4j.appender.graylog2.addExtendedInformation=true
log4j.appender.graylog2.additionalFields={'environment': 'DEV', 'application': 'MyAPP'}

log4j.rootLogger=INFO, graylog2, stdout

Main.java:

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class Main {
    private static final Logger logger = LogManager.getLogger(Main.class.getName());

    public static void main(final String[] args) {
        logger.info("test");
    }
}

Where is i`m wrong?

Appender is loading in build process because if i specify wrong graylogHost i see error. But there is no error message if i specify wrong port. And (how i wrote upper) Wireshark not see a connect to localhost 12201. If i use netcat for send GELF message to 12201 - wireshark see it.

cbillowes commented 6 years ago

I am experiencing the same problem, did you have any luck resolving this issue?

gabohurtado commented 5 years ago

Hello, I just to have the same problem, try writing tcp: before the host, like log4j.appender.graylog2.graylogHost=tcp:127.0.0.1

The code verify that substring:

try { if (graylogHost != null && graylogHost.startsWith("tcp:")) { String tcpGraylogHost = graylogHost.substring(4); gelfSender = getGelfTCPSender(tcpGraylogHost, graylogPort); } else if (graylogHost != null && graylogHost.startsWith("udp:")) { String udpGraylogHost = graylogHost.substring(4); gelfSender = getGelfUDPSender(udpGraylogHost, graylogPort); } else if (amqpURI != null) { gelfSender = getGelfAMQPSender(amqpURI, amqpExchangeName, amqpRoutingKey, amqpMaxRetries); } else { gelfSender = getGelfUDPSender(graylogHost, graylogPort); } }

kell18 commented 3 years ago

Yeah, the reason is that you have to set prefix for graylogHost: tcp or udp. So it'd be for example tcp:127.0.0.1