Class: LogStash::Logger
- Inherits:
-
Object
- Object
- LogStash::Logger
- Defined in:
- lib/logstash/logging.rb
Instance Attribute Summary collapse
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
Instance Method Summary collapse
- #debug(*args) ⇒ Object
- #debug?(*args) ⇒ Boolean
- #error(*args) ⇒ Object
- #error?(*args) ⇒ Boolean
- #fatal(*args) ⇒ Object
- #fatal?(*args) ⇒ Boolean
- #info(*args) ⇒ Object
- #info?(*args) ⇒ Boolean
-
#initialize(*args) ⇒ Logger
constructor
A new instance of Logger.
-
#level=(value) ⇒ Object
Delegation.
- #warn(*args) ⇒ Object
- #warn?(*args) ⇒ Boolean
Constructor Details
#initialize(*args) ⇒ Logger
Returns a new instance of Logger.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/logstash/logging.rb', line 10 def initialize(*args) super() #self[:program] = File.basename($0) #subscribe(::Logger.new(*args)) @target = args[0] @channel = Cabin::Channel.get(LogStash) # lame hack until cabin's smart enough not to doubley-subscribe something. # without this subscription count check, running the test suite # causes Cabin to subscribe to STDOUT maaaaaany times. subscriptions = @channel.instance_eval { @subscribers.count } @channel.subscribe(@target) unless subscriptions > 0 # Set default loglevel to WARN unless $DEBUG is set (run with 'ruby -d') @level = $DEBUG ? :debug : :warn if ENV["LOGSTASH_DEBUG"] @level = :debug end # Direct metrics elsewhere. @channel.metrics.channel = Cabin::Channel.new end |
Instance Attribute Details
#target ⇒ Object
Returns the value of attribute target.
7 8 9 |
# File 'lib/logstash/logging.rb', line 7 def target @target end |
Class Method Details
.setup_log4j(logger) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/logging.rb', line 47 def self.setup_log4j(logger) require "java" properties = java.util.Properties.new log4j_level = "WARN" case logger.level when :debug log4j_level = "DEBUG" when :info log4j_level = "INFO" when :warn log4j_level = "WARN" end # case level properties.setProperty("log4j.rootLogger", "#{log4j_level},logstash") # TODO(sissel): This is a shitty hack to work around the fact that # LogStash::Logger isn't used anymore. We should fix that. target = logger.instance_eval { @subscribers }.values.first.instance_eval { @io } case target when STDOUT properties.setProperty("log4j.appender.logstash", "org.apache.log4j.ConsoleAppender") properties.setProperty("log4j.appender.logstash.Target", "System.out") when STDERR properties.setProperty("log4j.appender.logstash", "org.apache.log4j.ConsoleAppender") properties.setProperty("log4j.appender.logstash.Target", "System.err") when target.is_a?(File) properties.setProperty("log4j.appender.logstash", "org.apache.log4j.FileAppender") properties.setProperty("log4j.appender.logstash.File", target.path) else properties.setProperty("log4j.appender.logstash", "org.apache.log4j.varia.NullAppender") end # case target properties.setProperty("log4j.appender.logstash.layout", "org.apache.log4j.PatternLayout") properties.setProperty("log4j.appender.logstash.layout.conversionPattern", "log4j, [%d{yyyy-MM-dd}T%d{HH:mm:ss.SSS}] %5p: %c: %m%n") org.apache.log4j.LogManager.resetConfiguration org.apache.log4j.PropertyConfigurator.configure(properties) logger.debug("log4j java properties setup", :log4j_level => log4j_level) end |
Instance Method Details
#debug(*args) ⇒ Object
36 |
# File 'lib/logstash/logging.rb', line 36 def debug(*args); @channel.debug(*args); end |
#debug?(*args) ⇒ Boolean
37 |
# File 'lib/logstash/logging.rb', line 37 def debug?(*args); @channel.debug?(*args); end |
#error(*args) ⇒ Object
42 |
# File 'lib/logstash/logging.rb', line 42 def error(*args); @channel.error(*args); end |
#error?(*args) ⇒ Boolean
43 |
# File 'lib/logstash/logging.rb', line 43 def error?(*args); @channel.error?(*args); end |
#fatal(*args) ⇒ Object
44 |
# File 'lib/logstash/logging.rb', line 44 def fatal(*args); @channel.fatal(*args); end |
#fatal?(*args) ⇒ Boolean
45 |
# File 'lib/logstash/logging.rb', line 45 def fatal?(*args); @channel.fatal?(*args); end |
#info(*args) ⇒ Object
38 |
# File 'lib/logstash/logging.rb', line 38 def info(*args); @channel.info(*args); end |
#info?(*args) ⇒ Boolean
39 |
# File 'lib/logstash/logging.rb', line 39 def info?(*args); @channel.info?(*args); end |
#level=(value) ⇒ Object
Delegation
35 |
# File 'lib/logstash/logging.rb', line 35 def level=(value) @channel.level = value; end |
#warn(*args) ⇒ Object
40 |
# File 'lib/logstash/logging.rb', line 40 def warn(*args); @channel.warn(*args); end |
#warn?(*args) ⇒ Boolean
41 |
# File 'lib/logstash/logging.rb', line 41 def warn?(*args); @channel.warn?(*args); end |