Class: Phrender::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/phrender/logger.rb

Constant Summary collapse

MESSAGE_FORMAT =
"%s: %s"

Class Method Summary collapse

Class Method Details

.console(message) ⇒ Object



17
18
19
# File 'lib/phrender/logger.rb', line 17

def console(message)
  log MESSAGE_FORMAT % [ apply_color("CONSOLE", :magenta), message ]
end

.critical(message) ⇒ Object



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

def critical(message)
  log MESSAGE_FORMAT % [ apply_color("CRITICAL", :on_red), message ]
end

.error(message) ⇒ Object



25
26
27
# File 'lib/phrender/logger.rb', line 25

def error(message)
  log MESSAGE_FORMAT % [ apply_color("ERROR", :red), message ]
end

.info(message) ⇒ Object



21
22
23
# File 'lib/phrender/logger.rb', line 21

def info(message)
  log MESSAGE_FORMAT % [ apply_color("INFO"), message ]
end

.log(msg, color = nil) ⇒ Object



37
38
39
40
41
# File 'lib/phrender/logger.rb', line 37

def log(msg, color = nil)
  message = "[%s] - %s" % [Time.now,  msg]
  $stdout.puts message
  $stdout.flush
end

.log_json(json) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/phrender/logger.rb', line 9

def log_json(json)
  %w(console info error trace critical).each do |type|
    if json.has_key? type
      send type.to_sym, json[type]
    end
  end
end

.trace(message) ⇒ Object



29
30
31
# File 'lib/phrender/logger.rb', line 29

def trace(message)
  log MESSAGE_FORMAT % [ apply_color("TRACE", :cyan), message ]
end