Class: Loggr::SLF4J::Logger

Inherits:
Object
  • Object
show all
Includes:
Loggr::Severity
Defined in:
lib/loggr/slf4j/logger.rb

Overview

A logger which is backed by SLF4J, thus only useable in a JRuby environment.

Constant Summary

Constants included from Loggr::Severity

Loggr::Severity::DEBUG, Loggr::Severity::ERROR, Loggr::Severity::FATAL, Loggr::Severity::INFO, Loggr::Severity::TRACE, Loggr::Severity::UNKNOWN, Loggr::Severity::WARN

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Logger

Create a new Logger instance for the given name



37
38
39
40
41
42
43
44
45
# File 'lib/loggr/slf4j/logger.rb', line 37

def initialize(name, options = {})
  name = self.class.in_java_notation(name)
  @java_logger = Java::OrgSlf4j::LoggerFactory.getLogger(name.to_s)
  @java_marker = MarkerFactory[options[:marker]]
  
  # seriously, this is handled by slf4j and pretty dynamic
  @level = Logger::UNKNOWN
  @auto_flushing = true
end

Instance Attribute Details

#auto_flushingObject (readonly)

Just to ensure compatiability with AS::BufferedLogger



30
31
32
# File 'lib/loggr/slf4j/logger.rb', line 30

def auto_flushing
  @auto_flushing
end

#closeObject (readonly)

Just to ensure compatiability with AS::BufferedLogger



30
31
32
# File 'lib/loggr/slf4j/logger.rb', line 30

def close
  @close
end

#flushObject (readonly)

Just to ensure compatiability with AS::BufferedLogger



30
31
32
# File 'lib/loggr/slf4j/logger.rb', line 30

def flush
  @flush
end

#java_loggerObject (readonly)

Access raw SLF4J logger & marker instances



33
34
35
# File 'lib/loggr/slf4j/logger.rb', line 33

def java_logger
  @java_logger
end

#java_markerObject (readonly)

Access raw SLF4J logger & marker instances



33
34
35
# File 'lib/loggr/slf4j/logger.rb', line 33

def java_marker
  @java_marker
end

#levelObject

Basically has no impact, because is handled by SLF4J



27
28
29
# File 'lib/loggr/slf4j/logger.rb', line 27

def level
  @level
end

Class Method Details

.in_java_notation(name) ⇒ Object

If a class, module or object is used converts ‘Foo::Bar::SomeThing` to java notation: `foo.bar.SomeThing`. Symbols and Strings are left as is!



70
71
72
73
74
75
76
# File 'lib/loggr/slf4j/logger.rb', line 70

def self.in_java_notation(name)
  return name.to_s if name.respond_to?(:to_str) || name.is_a?(Symbol)
  name = name.is_a?(Module) ? name.name.to_s : name.class.name.to_s
  parts = name.split('::')
  last  = parts.pop
  parts.map { |p| p.downcase }.push(last).join('.')
end