Class: LogStash::Inputs::Log4j
- Defined in:
- lib/logstash/inputs/log4j.rb
Overview
Read events over a TCP socket from Log4j SocketAppender.
Can either accept connections from clients or connect to a server, depending on ‘mode`. Depending on mode, you need a matching SocketAppender or SocketHubAppender on the remote side
Constant Summary
Constants included from Config::Mixin
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
-
#initialize(*args) ⇒ Log4j
constructor
A new instance of Log4j.
- #register ⇒ Object
- #run(output_queue) ⇒ Object
Methods inherited from Base
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
#initialize(*args) ⇒ Log4j
Returns a new instance of Log4j.
35 36 37 |
# File 'lib/logstash/inputs/log4j.rb', line 35 def initialize(*args) super(*args) end |
Instance Method Details
#register ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/logstash/inputs/log4j.rb', line 40 def register require "java" require "jruby/serialization" if __FILE__ !~ /^(jar:)?file:\/\// if File.exists?("vendor/jar/elasticsearch-0.90.3/lib/log4j-1.2.17.jar") require "vendor/jar/elasticsearch-0.90.3/lib/log4j-1.2.17.jar" end end if server? @logger.info("Starting Log4j input listener", :address => "#{@host}:#{@port}") @server_socket = TCPServer.new(@host, @port) end @logger.info("Log4j input") end |
#run(output_queue) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/logstash/inputs/log4j.rb', line 113 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 |