mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
- start using cabin for logging.
This commit is contained in:
parent
40052a9c9d
commit
ed61924c74
5 changed files with 19 additions and 93 deletions
1
Gemfile
1
Gemfile
|
@ -4,6 +4,7 @@ def jruby?
|
||||||
return RUBY_ENGINE == "jruby"
|
return RUBY_ENGINE == "jruby"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
gem "cabin", "0.1.2" # for logging. apache 2 license
|
||||||
gem "bunny" # for amqp support, MIT-style license
|
gem "bunny" # for amqp support, MIT-style license
|
||||||
gem "uuidtools" # for naming amqp queues, License ???
|
gem "uuidtools" # for naming amqp queues, License ???
|
||||||
gem "filewatch", "~> 0.3.0" # for file tailing, BSD License
|
gem "filewatch", "~> 0.3.0" # for file tailing, BSD License
|
||||||
|
|
15
Gemfile.lock
15
Gemfile.lock
|
@ -2,9 +2,11 @@ GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
awesome_print (0.4.0)
|
awesome_print (0.4.0)
|
||||||
bouncy-castle-java (1.5.0146.1)
|
bson (1.4.0)
|
||||||
bson (1.4.0-java)
|
bson (1.4.0-java)
|
||||||
bunny (0.7.6)
|
bunny (0.7.6)
|
||||||
|
cabin (0.1.2)
|
||||||
|
json
|
||||||
filewatch (0.3.0)
|
filewatch (0.3.0)
|
||||||
gelf (1.1.3)
|
gelf (1.1.3)
|
||||||
json
|
json
|
||||||
|
@ -12,13 +14,9 @@ GEM
|
||||||
gmetric (0.1.3)
|
gmetric (0.1.3)
|
||||||
haml (3.1.3)
|
haml (3.1.3)
|
||||||
jls-grok (0.9.0)
|
jls-grok (0.9.0)
|
||||||
jruby-elasticsearch (0.0.10)
|
json (1.6.1)
|
||||||
jruby-openssl (0.7.4)
|
|
||||||
bouncy-castle-java
|
|
||||||
json (1.6.1-java)
|
json (1.6.1-java)
|
||||||
minitest (2.6.1)
|
minitest (2.6.1)
|
||||||
mizuno (0.4.0)
|
|
||||||
rack (>= 1.0.0)
|
|
||||||
mongo (1.4.0)
|
mongo (1.4.0)
|
||||||
bson (= 1.4.0)
|
bson (= 1.4.0)
|
||||||
rack (1.3.3)
|
rack (1.3.3)
|
||||||
|
@ -36,21 +34,20 @@ GEM
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
java
|
java
|
||||||
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
awesome_print
|
awesome_print
|
||||||
bunny
|
bunny
|
||||||
|
cabin (= 0.1.2)
|
||||||
filewatch (~> 0.3.0)
|
filewatch (~> 0.3.0)
|
||||||
gelf
|
gelf
|
||||||
gelfd (~> 0.1.0)
|
gelfd (~> 0.1.0)
|
||||||
gmetric (~> 0.1.3)
|
gmetric (~> 0.1.3)
|
||||||
haml
|
haml
|
||||||
jls-grok (= 0.9.0)
|
jls-grok (= 0.9.0)
|
||||||
jruby-elasticsearch (~> 0.0.10)
|
|
||||||
jruby-openssl
|
|
||||||
json
|
json
|
||||||
minitest
|
minitest
|
||||||
mizuno
|
|
||||||
mongo
|
mongo
|
||||||
rack
|
rack
|
||||||
rake
|
rake
|
||||||
|
|
|
@ -227,14 +227,14 @@ class LogStash::Agent
|
||||||
end
|
end
|
||||||
|
|
||||||
if @verbose >= 3 # Uber debugging.
|
if @verbose >= 3 # Uber debugging.
|
||||||
@logger.level = Logger::DEBUG
|
@logger.level = :debug
|
||||||
$DEBUG = true
|
$DEBUG = true
|
||||||
elsif @verbose == 2 # logstash debug logs
|
elsif @verbose == 2 # logstash debug logs
|
||||||
@logger.level = Logger::DEBUG
|
@logger.level = :debug
|
||||||
elsif @verbose == 1 # logstash info logs
|
elsif @verbose == 1 # logstash info logs
|
||||||
@logger.level = Logger::INFO
|
@logger.level = :info
|
||||||
else # Default log level
|
else # Default log level
|
||||||
@logger.level = Logger::WARN
|
@logger.level = :warn
|
||||||
end
|
end
|
||||||
end # def configure
|
end # def configure
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ class LogStash::Config::File
|
||||||
def initialize(path=nil, string=nil)
|
def initialize(path=nil, string=nil)
|
||||||
@path = path
|
@path = path
|
||||||
@string = string
|
@string = string
|
||||||
@logger = Logger.new(STDERR)
|
@logger = LogStash::Logger.new(STDERR)
|
||||||
|
|
||||||
if (path.nil? and string.nil?) or (!path.nil? and !string.nil?)
|
if (path.nil? and string.nil?) or (!path.nil? and !string.nil?)
|
||||||
raise "Must give path or string, not both or neither"
|
raise "Must give path or string, not both or neither"
|
||||||
|
|
|
@ -1,91 +1,19 @@
|
||||||
require "logstash/namespace"
|
require "logstash/namespace"
|
||||||
|
require "cabin"
|
||||||
require "logger"
|
require "logger"
|
||||||
|
|
||||||
class LogStash::Logger < Logger
|
class LogStash::Logger < Cabin::Channel
|
||||||
# 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
|
|
||||||
|
|
||||||
public
|
public
|
||||||
def initialize(*args)
|
def initialize(*args)
|
||||||
super(*args)
|
super()
|
||||||
@formatter = LogStash::Logger::Formatter.new
|
|
||||||
|
|
||||||
# Set default loglevel to WARN unless $DEBUG is set (run with 'ruby -d')
|
# 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"]
|
if ENV["LOGSTASH_DEBUG"]
|
||||||
self.level = Logger::DEBUG
|
self.level = :debug
|
||||||
end
|
end
|
||||||
|
|
||||||
@formatter.progname = self.progname = File.basename($0)
|
#self[:program] = File.basename($0)
|
||||||
|
subscribe(::Logger.new(*args))
|
||||||
# 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
|
|
||||||
end # def initialize
|
end # def initialize
|
||||||
|
|
||||||
public
|
|
||||||
def level=(level)
|
|
||||||
super(level)
|
|
||||||
@formatter.level = level
|
|
||||||
end # def level=
|
|
||||||
end # class LogStash::Logger
|
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#<type>
|
|
||||||
# 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
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue