Rajan
Rajan

Reputation: 626

Remote logging over HTTP for java application

Folks, is there any way of remote logging via HTTP? (something like log4j which does remote logging over TCP)

thanks

Upvotes: 1

Views: 1857

Answers (5)

Roman Nikitchenko
Roman Nikitchenko

Reputation: 13036

It depends on what exact protocol do you need to support over HTTP(S) but I assume you are asking about RFC 5424 over HTTP(s) (through POST requests). In this case it seems log4j2 is the only out of the box solution for now (end of 2018).

HttpAppender with attached Rfc5424Layout can bring what you need:

https://logging.apache.org/log4j/2.x/manual/appenders.html https://logging.apache.org/log4j/2.x/manual/layouts.html

Currently I see Log4j2 2.11.1 and this solution works but in my case requires some customisation.

Upvotes: 0

NASAhorse
NASAhorse

Reputation: 103

You can do remote logging via HTTP or HTTPS using NXLog input and output modules (im_http and om_http).

The im_http module can be configured to accept HTTP or HTTPS connections. It expects HTTP POST requests from the client. The module will not close the connection while valid requests are received in order to operate in Keep-Alive mode. It will respond with HTTP/1.1 201 Created to each valid POST request. This acknowledgment ensures reliable message delivery.

The om_http module will connect to the specified URL in either plain HTTP or HTTPS mode. Each event is transferred in a single POST request. The module then waits for a response containing a successful status code (200, 201, or 202).

The modules are available on the Community Edition that is free https://nxlog.co/products/nxlog-community-edition/download

Upvotes: 0

Chamikara Samarasekara
Chamikara Samarasekara

Reputation: 373

Rsyslog is a popular central logging system. You can configure log4j to send log files to central logging system.

https://www.rsyslog.com/

This is the configuration for log4j.

 <Appenders>
    .............

     <Syslog name="syslog" format="RFC5424" host="myhost" port="514"
                protocol="UDP" appName="testlog4j" includeMDC="false" mdcId="testlog4j"
                facility="LOCAL0" enterpriseNumber="18060" newLine="false"
                messageId="Audit">
                <LoggerFields>
                      <KeyValuePair key="thread" value="%t"/>
                      <KeyValuePair key="priority" value="%p"/>
                      <KeyValuePair key="category" value="%c"/>
                      <KeyValuePair key="exception" value="%ex"/>
                </LoggerFields>

        </Syslog>
</Appenders>

Rsyslog alternatives

  • Nxlog
  • Kiwi Syslog Server
  • Syslog Watcher

Upvotes: 0

Martin
Martin

Reputation: 38289

There is no HTTP appender in log4j at the moment, but two different appenders have been submitted to the mailing list, one in 2004 and one in 2007.

Perhaps you could create your own HTTP appender based on their code?

Upvotes: 1

Roberto Chiaretti
Roberto Chiaretti

Reputation: 11

Log4j fully supports remote logging by the SocketAppender appender and its subclasses.

Upvotes: 1

Related Questions