Class: Nanite::Log

Inherits:
Object show all
Defined in:
lib/nanite/log.rb,
lib/nanite/log/formatter.rb

Defined Under Namespace

Classes: Formatter

Constant Summary collapse

LEVELS =

Map log levels symbols to values

{ :debug => Logger::DEBUG,
:info  => Logger::INFO,
:warn  => Logger::WARN,
:error => Logger::ERROR,
:fatal => Logger::FATAL }

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.fileObject

:nodoc



18
19
20
# File 'lib/nanite/log.rb', line 18

def file
  @file
end

.levelObject

:nodoc



18
19
20
# File 'lib/nanite/log.rb', line 18

def level
  @level
end

.loggerObject

:nodoc



18
19
20
# File 'lib/nanite/log.rb', line 18

def logger
  @logger
end

Class Method Details

.init(identity = nil, path = false) ⇒ Object

Use Nanite::Logger.init when you want to set up the logger manually. If this method is called with no arguments, it will log to STDOUT at the :info level. It also configures the Logger instance it creates to use the custom Nanite::Log::Formatter class.



23
24
25
26
27
28
29
30
31
32
# File 'lib/nanite/log.rb', line 23

def init(identity = nil, path = false)
  if path
    @file = File.join(path, "nanite.#{identity}.log")
  else
    @file = STDOUT
  end
  @logger = Logger.new(file)
  @logger.formatter = Nanite::Log::Formatter.new
  Log.level = :info
end

.method_missing(method_symbol, *args) ⇒ Object

Passes any other method calls on directly to the underlying Logger object created with init. If this method gets hit before a call to Nanite::Logger.init has been made, it will call Nanite::Logger.init() with no arguments.



55
56
57
58
59
60
61
62
# File 'lib/nanite/log.rb', line 55

def method_missing(method_symbol, *args)
  init unless @logger
  if args.length > 0
    @logger.send(method_symbol, *args)
  else
    @logger.send(method_symbol)
  end
end