Module: Logue::Loggable
- Defined in:
- lib/logue/loggable.rb
Instance Method Summary
collapse
-
#add_color_method(color, code) ⇒ Object
-
#debug(msg = "", depth = 1, &blk) ⇒ Object
-
#error(msg = "", depth = 1, &blk) ⇒ Object
-
#fatal(msg = "", depth = 1, &blk) ⇒ Object
-
#info(msg = "", depth = 1, &blk) ⇒ Object
-
#log(msg = "", lvl = Log::DEBUG, depth = 1, &blk) ⇒ Object
Logs the given message, including the class whence invoked.
-
#method_missing(meth, *args, &blk) ⇒ Object
-
#respond_to?(meth) ⇒ Boolean
-
#stack(msg = "", lvl = Log::DEBUG, depth = 1, &blk) ⇒ Object
-
#warn(msg = "", depth = 1, &blk) ⇒ Object
-
#write(msg = "", depth = 1, &blk) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/logue/loggable.rb', line 77
def method_missing meth, *args, &blk
validcolors = Sickill::Rainbow::TERM_COLORS
if code = validcolors[meth]
add_color_method meth.to_s, code + 30
send meth, *args, &blk
else
super
end
end
|
Instance Method Details
#add_color_method(color, code) ⇒ Object
93
94
95
96
97
98
99
|
# File 'lib/logue/loggable.rb', line 93
def add_color_method color, code
meth = Array.new
meth << "def #{color}(msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk)"
meth << " Log.#{color} msg, lvl, depth + 1, self.class.to_s, &blk"
meth << "end"
self.class.module_eval meth.join("\n")
end
|
#debug(msg = "", depth = 1, &blk) ⇒ Object
49
50
51
|
# File 'lib/logue/loggable.rb', line 49
def debug msg = "", depth = 1, &blk
Log.log msg, Log::DEBUG, depth + 1, self.class.to_s, &blk
end
|
#error(msg = "", depth = 1, &blk) ⇒ Object
61
62
63
|
# File 'lib/logue/loggable.rb', line 61
def error msg = "", depth = 1, &blk
Log.log msg, Log::ERROR, depth + 1, self.class.to_s, &blk
end
|
#fatal(msg = "", depth = 1, &blk) ⇒ Object
65
66
67
|
# File 'lib/logue/loggable.rb', line 65
def fatal msg = "", depth = 1, &blk
Log.log msg, Log::FATAL, depth + 1, self.class.to_s, &blk
end
|
#info(msg = "", depth = 1, &blk) ⇒ Object
53
54
55
|
# File 'lib/logue/loggable.rb', line 53
def info msg = "", depth = 1, &blk
Log.log msg, Log::INFO, depth + 1, self.class.to_s, &blk
end
|
#log(msg = "", lvl = Log::DEBUG, depth = 1, &blk) ⇒ Object
Logs the given message, including the class whence invoked.
45
46
47
|
# File 'lib/logue/loggable.rb', line 45
def log msg = "", lvl = Log::DEBUG, depth = 1, &blk
Log.log msg, lvl, depth + 1, self.class.to_s, &blk
end
|
#respond_to?(meth) ⇒ Boolean
88
89
90
91
|
# File 'lib/logue/loggable.rb', line 88
def respond_to? meth
validcolors = Sickill::Rainbow::TERM_COLORS
validcolors.include?(meth) || super
end
|
#stack(msg = "", lvl = Log::DEBUG, depth = 1, &blk) ⇒ Object
69
70
71
|
# File 'lib/logue/loggable.rb', line 69
def stack msg = "", lvl = Log::DEBUG, depth = 1, &blk
Log.stack msg, lvl, depth + 1, self.class.to_s, &blk
end
|
#warn(msg = "", depth = 1, &blk) ⇒ Object
57
58
59
|
# File 'lib/logue/loggable.rb', line 57
def warn msg = "", depth = 1, &blk
Log.log msg, Log::WARN, depth + 1, self.class.to_s, &blk
end
|
#write(msg = "", depth = 1, &blk) ⇒ Object
73
74
75
|
# File 'lib/logue/loggable.rb', line 73
def write msg = "", depth = 1, &blk
Log.write msg, depth + 1, self.class.to_s, &blk
end
|