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.



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

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

Class Method Details

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



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

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



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

def self.get_logging_context
  return @@logging_context
end

.initialize(config_location) ⇒ Object



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

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



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

def debug?
  @logger.is_debug_enabled
end

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



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

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

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  @logger.is_error_enabled
end

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



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

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

#fatal?Boolean

Returns:

  • (Boolean)


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

def fatal?
  @logger.is_fatal_enabled
end

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



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

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

#info?Boolean

Returns:

  • (Boolean)


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

def info?
  @logger.is_info_enabled
end

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



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

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

#trace?Boolean

Returns:

  • (Boolean)


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

def trace?
  @logger.is_trace_enabled
end

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



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

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

#warn?Boolean

Returns:

  • (Boolean)


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

def warn?
  @logger.is_warn_enabled
end