Class: LogStash::Logging::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/logging/logger.rb

Constant Summary collapse

@@config_mutex =
Mutex.new
@@logging_context =
nil

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Logger

Returns a new instance of Logger.



16
17
18
# File 'lib/logstash/logging/logger.rb', line 16

def initialize(name)
  @logger = LogManager.getLogger(name)
end

Class Method Details

.configure_logging(level, path = LogManager::ROOT_LOGGER_NAME) ⇒ Object



68
69
70
71
72
# File 'lib/logstash/logging/logger.rb', line 68

def self.configure_logging(level, path = LogManager::ROOT_LOGGER_NAME)
  @@config_mutex.synchronize { set_level(level, path) }
rescue Exception => e
  raise ArgumentError, "invalid level[#{level}] for logger[#{path}]"
end

.get_logging_contextObject



91
92
93
# File 'lib/logstash/logging/logger.rb', line 91

def self.get_logging_context
  return @@logging_context
end

.initialize(config_location) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/logstash/logging/logger.rb', line 74

def self.initialize(config_location)
  @@config_mutex.synchronize do
    if @@logging_context.nil?
      file_path = URI(config_location).path
      if ::File.exists?(file_path)
        logs_location = java.lang.System.getProperty("ls.logs")
        puts "Sending Logstash's logs to #{logs_location} which is now configured via log4j2.properties"
        @@logging_context = Configurator.initialize(nil, config_location)
      else
        # fall back to default config
        puts "Could not find log4j2 configuration at path #{file_path}. Using default config which logs to console"
        @@logging_context = Configurator.initialize(DefaultConfiguration.new)
      end
    end
  end
end

Instance Method Details

#debug(message, data = {}) ⇒ Object



44
45
46
# File 'lib/logstash/logging/logger.rb', line 44

def debug(message, data = {})
  @logger.debug(message, data)
end

#debug?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/logstash/logging/logger.rb', line 20

def debug?
  @logger.is_debug_enabled
end

#error(message, data = {}) ⇒ Object



56
57
58
# File 'lib/logstash/logging/logger.rb', line 56

def error(message, data = {})
  @logger.error(message, data)
end

#error?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/logstash/logging/logger.rb', line 28

def error?
  @logger.is_error_enabled
end

#fatal(message, data = {}) ⇒ Object



60
61
62
# File 'lib/logstash/logging/logger.rb', line 60

def fatal(message, data = {})
  @logger.fatal(message, data)
end

#fatal?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/logstash/logging/logger.rb', line 36

def fatal?
  @logger.is_fatal_enabled
end

#info(message, data = {}) ⇒ Object



52
53
54
# File 'lib/logstash/logging/logger.rb', line 52

def info(message, data = {})
  @logger.info(message, data)
end

#info?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/logstash/logging/logger.rb', line 24

def info?
  @logger.is_info_enabled
end

#trace(message, data = {}) ⇒ Object



64
65
66
# File 'lib/logstash/logging/logger.rb', line 64

def trace(message, data = {})
  @logger.trace(message, data)
end

#trace?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/logstash/logging/logger.rb', line 40

def trace?
  @logger.is_trace_enabled
end

#warn(message, data = {}) ⇒ Object



48
49
50
# File 'lib/logstash/logging/logger.rb', line 48

def warn(message, data = {})
  @logger.warn(message, data)
end

#warn?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/logstash/logging/logger.rb', line 32

def warn?
  @logger.is_warn_enabled
end