Class: Rakie::Log
- Inherits:
-
Object
- Object
- Rakie::Log
- Defined in:
- lib/rakie/log.rb
Constant Summary collapse
- LEVEL_INFO =
0
- LEVEL_ERROR =
1
- LEVEL_DEBUG =
2
Instance Attribute Summary collapse
-
#level ⇒ Object
Returns the value of attribute level.
-
#out ⇒ Object
Returns the value of attribute out.
Class Method Summary collapse
- .debug(message, who = nil) ⇒ Object
- .error(message, who = nil) ⇒ Object
- .info(message, who = nil) ⇒ Object
- .instance ⇒ Object
- .level ⇒ Object
- .level=(level) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Log
constructor
A new instance of Log.
- #level_debug? ⇒ Boolean
- #level_error? ⇒ Boolean
- #level_info? ⇒ Boolean
- #level_text(level = nil) ⇒ Object
Constructor Details
#initialize ⇒ Log
Returns a new instance of Log.
11 12 13 14 |
# File 'lib/rakie/log.rb', line 11 def initialize @level = Rakie.current_mode == Rakie::MODE_DEV ? LEVEL_DEBUG : LEVEL_ERROR @out = STDOUT end |
Instance Attribute Details
#level ⇒ Object
Returns the value of attribute level.
3 4 5 |
# File 'lib/rakie/log.rb', line 3 def level @level end |
#out ⇒ Object
Returns the value of attribute out.
3 4 5 |
# File 'lib/rakie/log.rb', line 3 def out @out end |
Class Method Details
.debug(message, who = nil) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rakie/log.rb', line 75 def self.debug(, who=nil) unless self.instance.level_debug? return end if who = "#{who}: #{}" end level = self.instance.level_text(LEVEL_DEBUG) self.instance.out.print("[#{Time.now.to_s}][#{level}] #{}\n") end |
.error(message, who = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/rakie/log.rb', line 62 def self.error(, who=nil) unless self.instance.level_error? return end if who = "#{who}: #{}" end level = self.instance.level_text(LEVEL_ERROR) self.instance.out.write("[#{Time.now.to_s}][#{level}] #{}\n") end |
.info(message, who = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rakie/log.rb', line 49 def self.info(, who=nil) unless self.instance.level_info? return end if who = "#{who}: #{}" end level = self.instance.level_text(LEVEL_INFO) self.instance.out.write("[#{Time.now.to_s}][#{level}] #{}\n") end |
.instance ⇒ Object
45 46 47 |
# File 'lib/rakie/log.rb', line 45 def self.instance @instance ||= Log.new end |
.level ⇒ Object
88 89 90 |
# File 'lib/rakie/log.rb', line 88 def self.level self.instance.level end |
.level=(level) ⇒ Object
92 93 94 |
# File 'lib/rakie/log.rb', line 92 def self.level=(level) self.instance.level = level end |
Instance Method Details
#level_debug? ⇒ Boolean
41 42 43 |
# File 'lib/rakie/log.rb', line 41 def level_debug? @level >= LEVEL_DEBUG end |
#level_error? ⇒ Boolean
37 38 39 |
# File 'lib/rakie/log.rb', line 37 def level_error? @level >= LEVEL_ERROR end |
#level_info? ⇒ Boolean
33 34 35 |
# File 'lib/rakie/log.rb', line 33 def level_info? @level >= LEVEL_INFO end |
#level_text(level = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rakie/log.rb', line 16 def level_text(level=nil) unless level level = @level end case level when LEVEL_INFO return "INFO" when LEVEL_ERROR return "ERROR" when LEVEL_DEBUG return "DEBUG" end end |