For other versions, see theVersioned plugin docs.
For plugins not bundled by default, it is easy to install by running bin/logstash-plugin install logstash-input-log4j
. See Working with plugins for more details.
For questions about the plugin, open a topic in the Discuss forums. For bugs or feature requests, open an issue in Github.For the list of Elastic supported plugins, please consult the Elastic Support Matrix.
This plugin is deprecated. It is recommended that you use filebeat to collect logs from log4j.
The following section is a guide for how to migrate from SocketAppender to use filebeat.
To migrate away from log4j SocketAppender to using filebeat, you will need to make 3 changes:
1) Configure your log4j.properties (in your app) to write to a local file.2) Install and configure filebeat to collect those logs and ship them to Logstash3) Configure Logstash to use the beats input.
Configuring log4j for writing to local files. In your log4j.properties file, remove SocketAppender and replace it with RollingFileAppender.
For example, you can use the following log4j.properties configuration to write daily log files.
# Your app's log4j.properties (log4j 1.2 only)log4j.rootLogger=dailylog4j.appender.daily=org.apache.log4j.rolling.RollingFileAppenderlog4j.appender.daily.RollingPolicy=org.apache.log4j.rolling.TimeBasedRollingPolicylog4j.appender.daily.RollingPolicy.FileNamePattern=/var/log/your-app/app.%d.loglog4j.appender.daily.layout = org.apache.log4j.PatternLayoutlog4j.appender.daily.layout.ConversionPattern=%d{YYYY-MM-dd HH:mm:ss,SSSZ} %p %c{1}:%L - %m%n
Configuring log4j.properties in more detail is outside the scope of this migration guide.
Configuring filebeat. Next,installfilebeat. Based on the above log4j.properties, we can use this filebeatconfiguration:
# filebeat.ymlfilebeat: prospectors: - paths: - /var/log/your-app/app.*.log input_type: logoutput: logstash: hosts: ["your-logstash-host:5000"]
For more details on configuring filebeat, seethe filebeat configuration guide.
Configuring Logstash to receive from filebeat. Finally, configure Logstash with a beats input:
# logstash configurationinput { beats { port => 5000 }}
It is strongly recommended that you also enable TLS in filebeat and logstashbeats input for protection and safety of your log data..
For more details on configuring the beats input, seethe logstash beats input documentation.
Read events over a TCP socket from a Log4j SocketAppender. This plugin works only with log4j version 1.x.
Can either accept connections from clients or connect to a server,depending on mode
. Depending on which mode
is configured,you need a matching SocketAppender or a SocketHubAppenderon the remote side.
One event is created per received log4j LoggingEvent with the following schema:
timestamp
⇒ the number of milliseconds elapsed from 1/1/1970 until logging event was created.path
⇒ the name of the loggerpriority
⇒ the level of this eventlogger_name
⇒ the name of the loggerthread
⇒ the thread name making the logging requestclass
⇒ the fully qualified class name of the caller making the logging request.file
⇒ the source file name and line number of the caller making the logging request in a colon-separated format "fileName:lineNumber".method
⇒ the method name of the caller making the logging request.NDC
⇒ the NDC stringstack_trace
⇒ the multi-line stack-traceAlso if the original log4j LoggingEvent contains MDC hash entries, they will be merged in the event as fields.
This plugin supports the following configuration options plus the Common Options described later.
Setting | Input type | Required |
---|---|---|
No |
||
string, one of |
No |
|
No |
||
No |
Also see Common Options for a list of options supported by allinput plugins.
"0.0.0.0"
When mode is server
, the address to listen on.When mode is client
, the address to connect to.
server
, client
"server"
Mode to operate in. server
listens for client connections,client
connects to a server.
4560
When mode is server
, the port to listen on.When mode is client
, the port to connect to.
false
Proxy protocol support, only v1 is supported at this timehttp://www.haproxy.org/download/1.5/doc/proxy-protocol.txt
The following configuration options are supported by all input plugins:
"plain"
The codec used for input data. Input codecs are a convenient method for decoding your data before it enters the input, without needing a separate filter in your Logstash pipeline.
true
Disable or enable metric logging for this specific plugin instanceby default we record all the metrics we can, but you can disable metrics collectionfor a specific plugin.
Add a unique ID
to the plugin configuration. If no ID is specified, Logstash will generate one.It is strongly recommended to set this ID in your configuration. This is particularly usefulwhen you have two or more plugins of the same type, for example, if you have 2 log4j inputs.Adding a named ID in this case will help in monitoring Logstash when using the monitoring APIs.
input { log4j { id => "my_plugin_id" }}
Add any number of arbitrary tags to your event.
This can help with processing later.
Add a type
field to all events handled by this input.
Types are used mainly for filter activation.
The type is stored as part of the event itself, so you canalso use the type to search for it in Kibana.
If you try to set a type on an event that already has one (forexample when you send an event from a shipper to an indexer) thena new input will not override the existing type. A type set atthe shipper stays with that event for its life evenwhen sent to another Logstash server.