Created
January 2, 2012 22:46
-
-
Save fetep/1552466 to your computer and use it in GitHub Desktop.
logstash + log4j configuration!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/logstash/logging.rb b/lib/logstash/logging.rb | |
index bafb342..b0692e2 100644 | |
--- a/lib/logstash/logging.rb | |
+++ b/lib/logstash/logging.rb | |
@@ -3,6 +3,8 @@ require "cabin" | |
require "logger" | |
class LogStash::Logger < Cabin::Channel | |
+ attr_accessor :target | |
+ | |
public | |
def initialize(*args) | |
super() | |
@@ -15,5 +17,45 @@ class LogStash::Logger < Cabin::Channel | |
#self[:program] = File.basename($0) | |
subscribe(::Logger.new(*args)) | |
+ @target = args[0] | |
end # def initialize | |
+ | |
+ def setup_log4j(logger="") | |
+ require "java" | |
+ | |
+ #p = java.util.Properties.new(java.lang.System.getProperties()) | |
+ p = java.util.Properties.new | |
+ log4j_level = "WARN" | |
+ case level | |
+ when :debug | |
+ log4j_level = "DEBUG" | |
+ when :info | |
+ log4j_level = "INFO" | |
+ end # case level | |
+ p.setProperty("log4j.rootLogger", "#{log4j_level},logstash") | |
+ | |
+ case target | |
+ when STDOUT | |
+ p.setProperty("log4j.appender.logstash", | |
+ "org.apache.log4j.ConsoleAppender") | |
+ p.setProperty("log4j.appender.logstash.Target", "System.out") | |
+ when STDERR | |
+ p.setProperty("log4j.appender.logstash", | |
+ "org.apache.log4j.ConsoleAppender") | |
+ p.setProperty("log4j.appender.logstash.Target", "System.err") | |
+ else | |
+ p.setProperty("log4j.appender.logstash", | |
+ "org.apache.log4j.FileAppender") | |
+ p.setProperty("log4j.appender.logstash.File", target) | |
+ end # case target | |
+ | |
+ p.setProperty("log4j.appender.logstash.layout", | |
+ "org.apache.log4j.PatternLayout") | |
+ p.setProperty("log4j.appender.logstash.layout.conversionPattern", | |
+ "%5p %d{HH:mm:ss,SSS} %m%n") | |
+ | |
+ org.apache.log4j.LogManager.resetConfiguration | |
+ org.apache.log4j.PropertyConfigurator.configure(p) | |
+ debug("log4j java properties setup", :log4j_level => log4j_level) | |
+ end | |
end # class LogStash::Logger | |
diff --git a/lib/logstash/outputs/elasticsearch.rb b/lib/logstash/outputs/elasticsearch.rb | |
index 5748a6e..421d78c 100644 | |
--- a/lib/logstash/outputs/elasticsearch.rb | |
+++ b/lib/logstash/outputs/elasticsearch.rb | |
@@ -67,6 +67,10 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base | |
require jar | |
end | |
+ # setup log4j properties for elasticsearch | |
+ @logger.setup_log4j | |
+ | |
if @embedded | |
%w(host cluster bind_host).each do |name| | |
if instance_variable_get("@#{name}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
starting up with default loglevel: | |
% ruby --1.9 bin/logstash agent -f etc/agent.conf | |
# nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
starting up with info: | |
% ruby --1.9 bin/logstash agent -v -f etc/agent.conf | |
I, [2012-01-02T17:44:32.160000 #20940] INFO -- : Input registered {"timestamp":"2012-01-02T17:44:32.153000 -0500","plugin":"LogStash::Inputs::Stdin: {\"type\"=>\"test\", \"debug\"=>false}","message":"Input registered","level":"info"} | |
I, [2012-01-02T17:44:32.206000 #20940] INFO -- : Starting embedded ElasticSearch local node. {"timestamp":"2012-01-02T17:44:32.205000 -0500","message":"Starting embedded ElasticSearch local node.","level":"info"} | |
INFO 17:44:32,263 [Bloodwraith] {0.18.6}[20940]: initializing ... | |
INFO 17:44:32,267 [Bloodwraith] loaded [], sites [] | |
INFO 17:44:33,081 [Bloodwraith] {0.18.6}[20940]: initialized | |
INFO 17:44:33,081 [Bloodwraith] {0.18.6}[20940]: starting ... | |
[...] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
starting up with debug: | |
% ruby --1.9 bin/logstash agent -vv -f etc/agent.conf | |
[...] | |
I, [2012-01-02T17:45:23.568000 #21060] INFO -- : Starting embedded ElasticSearch local node. {"timestamp":"2012-01-02T17:45:23.568000 -0500","message":"Starting embedded ElasticSearch local node.","file":"outputs/elasticsearch.rb","line":"111","method":"start_local_elasticsearch","level":"info"} | |
INFO 17:45:23,627 [Royal Roy] {0.18.6}[21060]: initializing ... | |
INFO 17:45:23,631 [Royal Roy] loaded [], sites [] | |
DEBUG 17:45:24,134 [Royal Roy] creating thread_pool [cached], type [cached], keep_alive [30s] | |
DEBUG 17:45:24,134 [Royal Roy] creating thread_pool [index], type [cached], keep_alive [5m] | |
DEBUG 17:45:24,134 [Royal Roy] creating thread_pool [search], type [cached], keep_alive [5m] | |
[...] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment