Class: LogStash::Inputs::Log4j2
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::Log4j2
- Defined in:
- lib/logstash/inputs/log4j2.rb
Overview
Read events over a TCP socket from a Log4j2 SocketAppender.
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 SocketHubAppender on the remote side.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Log4j2
constructor
A new instance of Log4j2.
- #register ⇒ Object
- #run(output_queue) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Log4j2
Returns a new instance of Log4j2.
39 40 41 |
# File 'lib/logstash/inputs/log4j2.rb', line 39 def initialize(*args) super(*args) end |
Instance Method Details
#register ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/logstash/inputs/log4j2.rb', line 44 def register require "java" require "jruby/serialization" begin vendor_dir = ::File.("../../../vendor/", ::File.dirname(__FILE__)) require File.join(vendor_dir, "log4j-api-2.1.jar") require File.join(vendor_dir, "log4j-core-2.1.jar") require File.join(vendor_dir, "disruptor-3.3.0.jar") Java::OrgApacheLoggingLog4jCoreImpl.const_get("Log4jLogEvent") rescue raise(LogStash::PluginLoadingError, "Log4j2 java library not loaded") end if server? @logger.info("Starting Log4j2 input listener", :address => "#{@host}:#{@port}") @server_socket = TCPServer.new(@host, @port) end @logger.info("Log4j input") end |
#run(output_queue) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/logstash/inputs/log4j2.rb', line 141 def run(output_queue) if server? loop do # Start a new thread for each connection. Thread.start(@server_socket.accept) do |s| # TODO(sissel): put this block in its own method. # monkeypatch a 'peer' method onto the socket. s.instance_eval { class << self; include ::LogStash::Util::SocketPeer end } @logger.debug("Accepted connection", :client => s.peer, :server => "#{@host}:#{@port}") handle_socket(s, output_queue) end # Thread.start end # loop else loop do client_socket = TCPSocket.new(@host, @port) client_socket.instance_eval { class << self; include ::LogStash::Util::SocketPeer end } @logger.debug("Opened connection", :client => "#{client_socket.peer}") handle_socket(client_socket, output_queue) end # loop end end |