Class: Rucola::Log
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
-
#level ⇒ Object
Holds the current log level.
Instance Method Summary collapse
- #debug(*args) ⇒ Object
- #error(*args) ⇒ Object
- #fatal(*args) ⇒ Object
- #info(*args) ⇒ Object
-
#initialize ⇒ Log
constructor
Creates a new Log instance.
-
#level_for_env ⇒ Object
Returns default log level for the application environment.
-
#log(message_level, *args) ⇒ Object
Writes a message to the log is the current loglevel is equal or greater than the message_level.
- #unknown(*args) ⇒ Object
- #warn(*args) ⇒ Object
Constructor Details
#initialize ⇒ Log
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
#level ⇒ Object
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 |
#level_for_env ⇒ Object
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
57 58 59 |
# File 'lib/rucola/log.rb', line 57 def log(, *args) OSX.NSLog(*args) if >= level end |