Class: LogStash::Logging::Logger

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

Constant Summary collapse

@@config_mutex =
Mutex.new

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Logger

Returns a new instance of Logger.



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

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

Class Method Details

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



70
71
72
73
74
# File 'lib/logstash/logging/logger.rb', line 70

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



98
99
100
# File 'lib/logstash/logging/logger.rb', line 98

def self.get_logging_context
  return  LoggerContext.getContext(false)
end

.reconfigure(config_location) ⇒ Object



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

def self.reconfigure(config_location)
  @@config_mutex.synchronize do
    config_location_uri = URI.create(config_location)
    file_path = config_location_uri.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"
      #reconfigure the default context to use our log4j2.properties file
      get_logging_context.setConfigLocation(URI.create(config_location))
      #ensure everyone agrees which context to use for the LogManager
      context_factory = LogstashLoggerContextFactory.new(get_logging_context)
      LogManager.setFactory(context_factory)
    else
      # fall back to default config
      puts "Could not find log4j2 configuration at path #{file_path}. Using default config which logs errors to the console"
    end
  end
end

Instance Method Details

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



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

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

#debug?Boolean

Returns:

  • (Boolean)


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

def debug?
  @logger.is_debug_enabled
end

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



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

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

#error?Boolean

Returns:

  • (Boolean)


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

def error?
  @logger.is_error_enabled
end

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



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

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

#fatal?Boolean

Returns:

  • (Boolean)


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

def fatal?
  @logger.is_fatal_enabled
end

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



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

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

#info?Boolean

Returns:

  • (Boolean)


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

def info?
  @logger.is_info_enabled
end

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



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

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

#trace?Boolean

Returns:

  • (Boolean)


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

def trace?
  @logger.is_trace_enabled
end

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



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

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

#warn?Boolean

Returns:

  • (Boolean)


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

def warn?
  @logger.is_warn_enabled
end