Class: Clog
Constant Summary collapse
- @@foreground =
:white
- @@background =
:red
- @@maxwidth =
max length before putting caller location on next line
150
Class Method Summary collapse
- .clog(*args) ⇒ Object
-
.colors(bg, fg = :white) ⇒ Object
change colors, default foreground is set here.
-
.maxwidth(max) ⇒ Object
change default maxwidth.
-
.message(*args) ⇒ Object
Generate string to be logged.
Class Method Details
.clog(*args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/clog.rb', line 22 def clog(*args) # write to appopriate stream if defined?(Rails.logger) Rails.logger.debug((*args)) else # for testing puts (*args) end end |
.colors(bg, fg = :white) ⇒ Object
change colors, default foreground is set here
10 11 12 13 |
# File 'lib/clog.rb', line 10 def self.colors(bg, fg=:white) @@background = bg @@foreground = fg end |
.maxwidth(max) ⇒ Object
change default maxwidth
16 17 18 |
# File 'lib/clog.rb', line 16 def self.maxwidth(max) @@maxwidth = max end |
.message(*args) ⇒ Object
Generate string to be logged
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/clog.rb', line 34 def (*args) if args.size == 0 # flag flag + leftloc elsif args.size == 1 # single argument if too_long_for_leftloc(args, leftloc) "#{args[0].inspect}\n#{uploc}" else "#{args[0].inspect}#{leftloc}" end elsif args.size == 2 && args[0].class == Symbol # symbol + single argument #symbol = colorize(args[0].to_s + ':') if too_long_for_leftloc(args, leftloc) "#{args[0]}: #{args[1].inspect}\n#{uploc}" else "#{args[0]}: #{args[1].inspect}#{leftloc}" end else # multiple args, each gets its own line str = args.inject(''){|str, x| str << "#{x.inspect}\n"} "#{str}#{uploc}" end end |