Class: Logue::Log
- Inherits:
-
Object
- Object
- Logue::Log
- Includes:
- Severity
- Defined in:
- lib/logue/log.rb,
lib/logue/severity.rb
Defined Under Namespace
Modules: Severity
Constant Summary collapse
- DEFAULT_FILENAME_WIDTH =
-25
- DEFAULT_LINENUM_WIDTH =
4- DEFAULT_FUNCTION_WIDTH =
-20
- @@log =
by default, class methods delegate to a single app-wide log.
Logger.new
Constants included from Severity
Severity::DEBUG, Severity::ERROR, Severity::FATAL, Severity::INFO, Severity::WARN
Class Method Summary collapse
- .add_color_method(color, code) ⇒ Object
- .colorize_line ⇒ Object
-
.colorize_line=(col) ⇒ Object
sets whether to colorize the entire line, or just the message.
- .debug(msg = "", depth = 1, &blk) ⇒ Object
- .error(msg = "", depth = 1, &blk) ⇒ Object
- .fatal(msg = "", depth = 1, &blk) ⇒ Object
- .format ⇒ Object
- .format=(fmt) ⇒ Object
- .ignore_class(classname) ⇒ Object
- .ignore_file(fname) ⇒ Object
- .ignore_method(methname) ⇒ Object
- .info(msg = "", depth = 1, &blk) ⇒ Object
- .level=(lvl) ⇒ Object
- .log(msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk) ⇒ Object
- .log_class(classname) ⇒ Object
- .log_file(fname) ⇒ Object
- .log_method(methname) ⇒ Object
-
.logger ⇒ Object
Returns the logger of the log.
- .method_missing(meth, *args, &blk) ⇒ Object
- .outfile ⇒ Object
-
.outfile=(fname) ⇒ Object
Assigns output to a file with the given name.
- .output ⇒ Object
-
.output=(io) ⇒ Object
Assigns output to the given stream.
- .quiet ⇒ Object
- .quiet=(q) ⇒ Object
- .respond_to?(meth) ⇒ Boolean
- .set_color(lvl, color) ⇒ Object
- .set_default_widths ⇒ Object
-
.set_widths(file_width, line_width, func_width) ⇒ Object
Creates a printf format for the given widths, for aligning output.
- .stack(msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk) ⇒ Object
- .verbose ⇒ Object
- .verbose=(v) ⇒ Object
- .warn(msg = "", depth = 1, &blk) ⇒ Object
- .write(msg, depth = 1, cname = nil, &blk) ⇒ Object
Class Method Details
.add_color_method(color, code) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/logue/log.rb', line 90 def self.add_color_method color, code instmeth = Array.new instmeth << "def #{color} msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk" instmeth << " log(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)" instmeth << "end" instance_eval instmeth.join("\n") clsmeth = Array.new clsmeth << "def #{color} msg = \"\", lvl = Log::DEBUG, depth = 1, cname = nil, &blk" clsmeth << " logger.#{color}(\"\\e[#{code}m\#{msg\}\\e[0m\", lvl, depth + 1, cname, &blk)" clsmeth << "end" class_eval clsmeth.join("\n") end |
.colorize_line ⇒ Object
151 152 153 |
# File 'lib/logue/log.rb', line 151 def self.colorize_line logger.colorize_line end |
.colorize_line=(col) ⇒ Object
sets whether to colorize the entire line, or just the message.
147 148 149 |
# File 'lib/logue/log.rb', line 147 def self.colorize_line= col logger.colorize_line = col end |
.debug(msg = "", depth = 1, &blk) ⇒ Object
194 195 196 |
# File 'lib/logue/log.rb', line 194 def self.debug msg = "", depth = 1, &blk logger.log msg, DEBUG, depth + 1, &blk end |
.error(msg = "", depth = 1, &blk) ⇒ Object
222 223 224 225 226 227 228 |
# File 'lib/logue/log.rb', line 222 def self.error msg = "", depth = 1, &blk if verbose logger.log msg, ERROR, depth + 1, &blk else $stderr.puts "ERROR: " + msg end end |
.fatal(msg = "", depth = 1, &blk) ⇒ Object
202 203 204 |
# File 'lib/logue/log.rb', line 202 def self.fatal msg = "", depth = 1, &blk logger.log msg, FATAL, depth + 1, &blk end |
.format ⇒ Object
129 130 131 |
# File 'lib/logue/log.rb', line 129 def self.format logger.format end |
.format=(fmt) ⇒ Object
133 134 135 |
# File 'lib/logue/log.rb', line 133 def self.format= fmt logger.format = fmt end |
.ignore_class(classname) ⇒ Object
178 179 180 |
# File 'lib/logue/log.rb', line 178 def self.ignore_class classname logger.ignored_class classname end |
.ignore_file(fname) ⇒ Object
170 171 172 |
# File 'lib/logue/log.rb', line 170 def self.ignore_file fname logger.ignore_file fname end |
.ignore_method(methname) ⇒ Object
174 175 176 |
# File 'lib/logue/log.rb', line 174 def self.ignore_method methname logger.ignored_method methname end |
.info(msg = "", depth = 1, &blk) ⇒ Object
198 199 200 |
# File 'lib/logue/log.rb', line 198 def self.info msg = "", depth = 1, &blk logger.log msg, INFO, depth + 1, &blk end |
.level=(lvl) ⇒ Object
117 118 119 |
# File 'lib/logue/log.rb', line 117 def self.level= lvl logger.level = lvl end |
.log(msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk) ⇒ Object
206 207 208 |
# File 'lib/logue/log.rb', line 206 def self.log msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk logger.log msg, lvl, depth + 1, cname, &blk end |
.log_class(classname) ⇒ Object
190 191 192 |
# File 'lib/logue/log.rb', line 190 def self.log_class classname logger.log_class classname end |
.log_file(fname) ⇒ Object
182 183 184 |
# File 'lib/logue/log.rb', line 182 def self.log_file fname logger.log_file fname end |
.log_method(methname) ⇒ Object
186 187 188 |
# File 'lib/logue/log.rb', line 186 def self.log_method methname logger.log_method methname end |
.logger ⇒ Object
Returns the logger of the log. A class method delegating to an instance method … not so good. But temporary.
70 71 72 |
# File 'lib/logue/log.rb', line 70 def self.logger @@log end |
.method_missing(meth, *args, &blk) ⇒ Object
74 75 76 77 78 79 80 81 82 83 |
# File 'lib/logue/log.rb', line 74 def self.method_missing meth, *args, &blk validcolors = Sickill::Rainbow::TERM_COLORS # only handling foregrounds, not backgrounds if code = validcolors[meth] add_color_method meth.to_s, code + 30 send meth, *args, &blk else super end end |
.outfile ⇒ Object
161 162 163 |
# File 'lib/logue/log.rb', line 161 def self.outfile logger.outfile end |
.outfile=(fname) ⇒ Object
Assigns output to a file with the given name. Returns the file; client is responsible for closing it.
157 158 159 |
# File 'lib/logue/log.rb', line 157 def self.outfile= fname logger.outfile = fname end |
.output ⇒ Object
142 143 144 |
# File 'lib/logue/log.rb', line 142 def self.output logger.output end |
.output=(io) ⇒ Object
Assigns output to the given stream.
138 139 140 |
# File 'lib/logue/log.rb', line 138 def self.output= io logger.output = io end |
.quiet ⇒ Object
121 122 123 |
# File 'lib/logue/log.rb', line 121 def self.quiet logger.quiet end |
.quiet=(q) ⇒ Object
125 126 127 |
# File 'lib/logue/log.rb', line 125 def self.quiet= q logger.quiet = q end |
.respond_to?(meth) ⇒ Boolean
85 86 87 88 |
# File 'lib/logue/log.rb', line 85 def self.respond_to? meth validcolors = Sickill::Rainbow::TERM_COLORS validcolors.include?(meth) || super end |
.set_color(lvl, color) ⇒ Object
240 241 242 |
# File 'lib/logue/log.rb', line 240 def self.set_color lvl, color logger.set_color lvl, color end |
.set_default_widths ⇒ Object
105 106 107 |
# File 'lib/logue/log.rb', line 105 def self.set_default_widths logger.set_default_widths end |
.set_widths(file_width, line_width, func_width) ⇒ Object
Creates a printf format for the given widths, for aligning output.
166 167 168 |
# File 'lib/logue/log.rb', line 166 def self.set_widths file_width, line_width, func_width logger.set_widths file_width, line_width, func_width end |
.stack(msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk) ⇒ Object
210 211 212 |
# File 'lib/logue/log.rb', line 210 def self.stack msg = "", lvl = DEBUG, depth = 1, cname = nil, &blk logger.stack msg, lvl, depth + 1, cname, &blk end |
.verbose ⇒ Object
109 110 111 |
# File 'lib/logue/log.rb', line 109 def self.verbose logger.verbose end |
.verbose=(v) ⇒ Object
113 114 115 |
# File 'lib/logue/log.rb', line 113 def self.verbose= v logger.verbose = v && v != 0 ? DEBUG : FATAL end |
.warn(msg = "", depth = 1, &blk) ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/logue/log.rb', line 214 def self.warn msg = "", depth = 1, &blk if verbose logger.log msg, WARN, depth + 1, &blk else $stderr.puts "WARNING: " + msg end end |