Class: EventMachine::RTMP::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/em-rtmp/logger.rb

Constant Summary collapse

LEVEL_DEBUG =
0
LEVEL_INFO =
1
LEVEL_ERROR =
2
@@level =
LEVEL_INFO

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.level(level) ⇒ Object

Returns the value of attribute level.



12
13
14
# File 'lib/em-rtmp/logger.rb', line 12

def level
  @level
end

Class Method Details

.debug(message, options = {}) ⇒ Object



19
20
21
22
# File 'lib/em-rtmp/logger.rb', line 19

def self.debug(message, options={})
  return unless @@level <= LEVEL_DEBUG
  print message, {level: "DEBUG", caller: caller}.merge(options)
end

.error(message, options = {}) ⇒ Object



29
30
31
32
# File 'lib/em-rtmp/logger.rb', line 29

def self.error(message, options={})
  return unless @@level <= LEVEL_ERROR
  print message, {level: "ERROR", caller: caller}.merge(options)
end

.info(message, options = {}) ⇒ Object



24
25
26
27
# File 'lib/em-rtmp/logger.rb', line 24

def self.info(message, options={})
  return unless @@level <= LEVEL_INFO
  print message, {level: "INFO", caller: caller}.merge(options)
end


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/em-rtmp/logger.rb', line 34

def self.print(message, options={})
  options[:level] ||= "PRINT"
  options[:caller] ||= caller

  caller_splat = options[:caller][0].split(":")
  ruby_file = caller_splat[0].split("/").last
  ruby_line = caller_splat[1]
  ruby_method = caller_splat[2].match(/`(.*)'/)[1]

  puts "%-10s%-30s%-30s%s" % ["[#{options[:level]}]", "#{ruby_file}:#{ruby_line}", ruby_method, message.encode("UTF-8")]
end