Class: Rucola::Log

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/rucola/log.rb

Overview

The Log class is basically a wrapper around NSLog. It is a singleton class so you should get an instance using the instance class method instead of new.

Rucola::Log.instance.fatal("Couldn't initialize application.")

The Log class is generally accessed through the log method on Kernel.

log.debug("%d exceptions caught, giving up", exceptions.length)

Constant Summary collapse

DEBUG =
0
INFO =
1
WARN =
2
ERROR =
3
FATAL =
4
UNKNOWN =
5
SILENT =
9

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLog

Creates a new Log instance. Don’t call this directly, call instance instead.

log.instance


29
30
31
# File 'lib/rucola/log.rb', line 29

def initialize
  @level = level_for_env
end

Instance Attribute Details

#levelObject

Holds the current log level



24
25
26
# File 'lib/rucola/log.rb', line 24

def level
  @level
end

Instance Method Details

#debug(*args) ⇒ Object



33
# File 'lib/rucola/log.rb', line 33

def debug(*args); log(DEBUG, *args); end

#error(*args) ⇒ Object



36
# File 'lib/rucola/log.rb', line 36

def error(*args); log(ERROR, *args); end

#fatal(*args) ⇒ Object



37
# File 'lib/rucola/log.rb', line 37

def fatal(*args); log(FATAL, *args); end

#info(*args) ⇒ Object



34
# File 'lib/rucola/log.rb', line 34

def info(*args); log(INFO, *args); end

#level_for_envObject

Returns default log level for the application environment.

log.level_for_env #=> Log::ERROR


43
44
45
46
47
48
49
50
51
52
# File 'lib/rucola/log.rb', line 43

def level_for_env
  case RCApp.env
  when 'test'
    SILENT
  when 'debug'
    DEBUG
  when 'release'
    ERROR
  end
end

#log(message_level, *args) ⇒ Object

Writes a message to the log is the current loglevel is equal or greater than the message_level.

log.log(Log::DEBUG, "This is a debug message")


57
58
59
# File 'lib/rucola/log.rb', line 57

def log(message_level, *args)
  OSX.NSLog(*args) if message_level >= level
end

#unknown(*args) ⇒ Object



38
# File 'lib/rucola/log.rb', line 38

def unknown(*args); log(UNKNOWN, *args); end

#warn(*args) ⇒ Object



35
# File 'lib/rucola/log.rb', line 35

def warn(*args); log(WARN, *args); end