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.



14
15
16
# File 'lib/logstash/logging/logger.rb', line 14

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

Class Method Details

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



66
67
68
69
70
# File 'lib/logstash/logging/logger.rb', line 66

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

.get_logging_contextObject



89
90
91
# File 'lib/logstash/logging/logger.rb', line 89

def self.get_logging_context
  return @@logging_context
end

.initialize(config_location) ⇒ Object



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

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



42
43
44
# File 'lib/logstash/logging/logger.rb', line 42

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

#debug?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/logstash/logging/logger.rb', line 18

def debug?
  @logger.is_debug_enabled
end

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



54
55
56
# File 'lib/logstash/logging/logger.rb', line 54

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

#error?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/logstash/logging/logger.rb', line 26

def error?
  @logger.is_error_enabled
end

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



58
59
60
# File 'lib/logstash/logging/logger.rb', line 58

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

#fatal?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/logstash/logging/logger.rb', line 34

def fatal?
  @logger.is_fatal_enabled
end

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



50
51
52
# File 'lib/logstash/logging/logger.rb', line 50

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

#info?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/logstash/logging/logger.rb', line 22

def info?
  @logger.is_info_enabled
end

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



62
63
64
# File 'lib/logstash/logging/logger.rb', line 62

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

#trace?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/logstash/logging/logger.rb', line 38

def trace?
  @logger.is_trace_enabled
end

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



46
47
48
# File 'lib/logstash/logging/logger.rb', line 46

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

#warn?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/logstash/logging/logger.rb', line 30

def warn?
  @logger.is_warn_enabled
end