Class: AjaxCat::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/ajax-cat/logger.rb

Constant Summary collapse

true

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix = false) ⇒ Logger

Returns a new instance of Logger.



10
11
12
# File 'lib/ajax-cat/logger.rb', line 10

def initialize(prefix = false)
	@prefix = prefix
end

Class Method Details



6
7
8
# File 'lib/ajax-cat/logger.rb', line 6

def self.print_log(val)
	@@print = val
end

Instance Method Details

#compose_message(message) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ajax-cat/logger.rb', line 19

def compose_message(message)
	t = Time.now
	milliseconds = (t.to_f * 1000 % 1000).to_i
	ret = (t.strftime("%Y-%d-%m %H:%M:%S.#{milliseconds}") + " ")
	(3 - milliseconds.to_s.length).times {ret += " "}
	if @prefix
		ret = "#{ret}#{@prefix.red}: #{message}"
	else
		ret = "#{ret}#{message.green}"
	end
	ret
end

#log(message) ⇒ Object



14
15
16
17
# File 'lib/ajax-cat/logger.rb', line 14

def log(message)
	return unless @@print
	puts compose_message(message)
end