diff --git a/Gemfile b/Gemfile index 1b6810f62..8850a7004 100644 --- a/Gemfile +++ b/Gemfile @@ -4,6 +4,7 @@ def jruby? return RUBY_ENGINE == "jruby" end +gem "cabin", "0.1.2" # for logging. apache 2 license gem "bunny" # for amqp support, MIT-style license gem "uuidtools" # for naming amqp queues, License ??? gem "filewatch", "~> 0.3.0" # for file tailing, BSD License diff --git a/Gemfile.lock b/Gemfile.lock index 5d1feaa6c..115c95335 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,9 +2,11 @@ GEM remote: http://rubygems.org/ specs: awesome_print (0.4.0) - bouncy-castle-java (1.5.0146.1) + bson (1.4.0) bson (1.4.0-java) bunny (0.7.6) + cabin (0.1.2) + json filewatch (0.3.0) gelf (1.1.3) json @@ -12,13 +14,9 @@ GEM gmetric (0.1.3) haml (3.1.3) jls-grok (0.9.0) - jruby-elasticsearch (0.0.10) - jruby-openssl (0.7.4) - bouncy-castle-java + json (1.6.1) json (1.6.1-java) minitest (2.6.1) - mizuno (0.4.0) - rack (>= 1.0.0) mongo (1.4.0) bson (= 1.4.0) rack (1.3.3) @@ -36,21 +34,20 @@ GEM PLATFORMS java + ruby DEPENDENCIES awesome_print bunny + cabin (= 0.1.2) filewatch (~> 0.3.0) gelf gelfd (~> 0.1.0) gmetric (~> 0.1.3) haml jls-grok (= 0.9.0) - jruby-elasticsearch (~> 0.0.10) - jruby-openssl json minitest - mizuno mongo rack rake diff --git a/lib/logstash/agent.rb b/lib/logstash/agent.rb index bcf426513..e16697601 100644 --- a/lib/logstash/agent.rb +++ b/lib/logstash/agent.rb @@ -227,14 +227,14 @@ class LogStash::Agent end if @verbose >= 3 # Uber debugging. - @logger.level = Logger::DEBUG + @logger.level = :debug $DEBUG = true elsif @verbose == 2 # logstash debug logs - @logger.level = Logger::DEBUG + @logger.level = :debug elsif @verbose == 1 # logstash info logs - @logger.level = Logger::INFO + @logger.level = :info else # Default log level - @logger.level = Logger::WARN + @logger.level = :warn end end # def configure diff --git a/lib/logstash/config/file.rb b/lib/logstash/config/file.rb index 9b012b4aa..fe8e36567 100644 --- a/lib/logstash/config/file.rb +++ b/lib/logstash/config/file.rb @@ -11,7 +11,7 @@ class LogStash::Config::File def initialize(path=nil, string=nil) @path = path @string = string - @logger = Logger.new(STDERR) + @logger = LogStash::Logger.new(STDERR) if (path.nil? and string.nil?) or (!path.nil? and !string.nil?) raise "Must give path or string, not both or neither" diff --git a/lib/logstash/logging.rb b/lib/logstash/logging.rb index e3365d249..bafb342cd 100644 --- a/lib/logstash/logging.rb +++ b/lib/logstash/logging.rb @@ -1,91 +1,19 @@ require "logstash/namespace" +require "cabin" require "logger" -class LogStash::Logger < Logger - # Try to load awesome_print, if it fails, log it later - # but otherwise we will continue to operate as normal. - begin - require "ap" - @@have_awesome_print = true - rescue LoadError => e - @@have_awesome_print = false - @@notify_awesome_print_load_failed = e - end - +class LogStash::Logger < Cabin::Channel public def initialize(*args) - super(*args) - @formatter = LogStash::Logger::Formatter.new + super() # Set default loglevel to WARN unless $DEBUG is set (run with 'ruby -d') - self.level = $DEBUG ? Logger::DEBUG: Logger::INFO + @level = $DEBUG ? :debug : :info if ENV["LOGSTASH_DEBUG"] - self.level = Logger::DEBUG + self.level = :debug end - @formatter.progname = self.progname = File.basename($0) - - # Conditional support for awesome_print - if !@@have_awesome_print && @@notify_awesome_print_load_failed - debug [ "awesome_print not found, falling back to Object#inspect." \ - "If you want prettier log output, run 'gem install "\ - "awesome_print'", - { :exception => @@notify_awesome_print_load_failed }] - - # Only show this once. - @@notify_awesome_print_load_failed = nil - end + #self[:program] = File.basename($0) + subscribe(::Logger.new(*args)) end # def initialize - - public - def level=(level) - super(level) - @formatter.level = level - end # def level= end # class LogStash::Logger - -# Implement a custom Logger::Formatter that uses awesome_inspect on non-strings. -class LogStash::Logger::Formatter < Logger::Formatter - attr_accessor :level - attr_accessor :progname - - public - def call(severity, timestamp, who, object) - # override progname to be the caller if the log level threshold is DEBUG - # We only do this if the logger level is DEBUG because inspecting the - # stack and doing extra string manipulation can have performance impacts - # under high logging rates. - if @level == Logger::DEBUG - # callstack inspection, include our caller - # turn this: "/usr/lib/ruby/1.8/irb/workspace.rb:52:in `irb_binding'" - # into this: ["/usr/lib/ruby/1.8/irb/workspace.rb", "52", "irb_binding"] - # - # caller[3] is actually who invoked the Logger# - # This only works if you use the severity methods - path, line, method = caller[3].split(/(?::in `|:|')/) - # Trim RUBYLIB path from 'file' if we can - #whence = $:.select { |p| path.start_with?(p) }[0] - whence = $:.detect { |p| path.start_with?(p) } - if !whence - # We get here if the path is not in $: - file = path - else - file = path[whence.length + 1..-1] - end - who = "#{file}:#{line}##{method}" - end - - # Log like normal if we got a string. - if object.is_a?(String) - super(severity, timestamp, who, object) - else - # If we logged an object, use .awesome_inspect (or just .inspect) - # to stringify it for higher sanity logging. - if object.respond_to?(:awesome_inspect) - super(severity, timestamp, who, object.awesome_inspect) - else - super(severity, timestamp, who, object.inspect) - end - end - end # def call -end # class LogStash::Logger::Formatter