Module: Log::Comfort

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject

where data is logged to



25
26
27
# File 'lib/log/comfort.rb', line 25

def logger
  @logger
end

Instance Method Details

#debug(text, origin = nil, data = nil, *flags) ⇒ Object

See Log::Entry.new to see what arguments are valid. Module::debug(text, *args) is the same as:

$stderr.puts(Log::Message.new(text, :debug, *args))


41
42
43
44
45
# File 'lib/log/comfort.rb', line 41

def debug(text, origin=nil, data=nil, *flags)
	(@logger || $stderr).puts(
		Log::Entry.new(text.to_str, :debug, origin||log_origin, data=nil, *flags)
	)
end

#error(text, origin = nil, data = nil, *flags) ⇒ Object

See Log::Entry.new to see what arguments are valid. Module::error(text, *args) is the same as:

$stderr.puts(Log::Message.new(text, :error, *args))


68
69
70
71
72
# File 'lib/log/comfort.rb', line 68

def error(text, origin=nil, data=nil, *flags)
	(@logger || $stderr).puts(
		Log::Entry.new(text.to_str, :error, origin||log_origin, data=nil, *flags)
	)
end

#exception(e) ⇒ Object

Exception is special cased, if @logger || $stderr responds to ‘exception’, the exception is just forwarded, else it uses puts and prints the exception and the backtrace



86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/log/comfort.rb', line 86

def exception(e)
	log = @logger || $stderr
	if log.respond_to?(:exception) then
		log.exception(e)
	else
		log.puts("#{Time.now.strftime('%FT%T')} [exception]: #{e} (#{e.class})")
		if $VERBOSE then
			prefix = "--> "
			log.puts(*e.backtrace.map { |l| prefix+l })
		end
	end
end

#fail(text, origin = nil, data = nil, *flags) ⇒ Object

See Log::Entry.new to see what arguments are valid. Module::fail(text, *args) is the same as:

$stderr.puts(Log::Message.new(text, :fail, *args))


77
78
79
80
81
# File 'lib/log/comfort.rb', line 77

def fail(text, origin=nil, data=nil, *flags)
	(@logger || $stderr).puts(
		Log::Entry.new(text.to_str, :fail, origin||log_origin, data=nil, *flags)
	)
end

#info(text, origin = nil, data = nil, *flags) ⇒ Object

See Log::Entry.new to see what arguments are valid. Module::info(text, *args) is the same as:

$stderr.puts(Log::Message.new(text, :info, *args))


50
51
52
53
54
# File 'lib/log/comfort.rb', line 50

def info(text, origin=nil, data=nil, *flags)
	(@logger || $stderr).puts(
		Log::Entry.new(text.to_str, :info, origin||log_origin, data=nil, *flags)
	)
end

#log(text, severity = :info, origin = nil, data = nil, *flags) ⇒ Object

See Log::Message.new Module::log(*args) is simply: $stderr.puts(Log::Message.new(*args))



32
33
34
35
36
# File 'lib/log/comfort.rb', line 32

def log(text, severity=:info, origin=nil, data=nil, *flags)
	(@logger || $stderr).puts(
		Log::Entry.new(text.to_str, severity, origin||log_origin, data=nil, *flags)
	)
end

#warn(text, origin = nil, data = nil, *flags) ⇒ Object

See Log::Entry.new to see what arguments are valid. Module::warn(text, *args) is the same as:

$stderr.puts(Log::Message.new(text, :warn, *args))


59
60
61
62
63
# File 'lib/log/comfort.rb', line 59

def warn(text, origin=nil, data=nil, *flags)
	(@logger || $stderr).puts(
		Log::Entry.new(text.to_str, :warn, origin||log_origin, data=nil, *flags)
	)
end