Class: MyStuff::Logger::Reader
- Inherits:
-
Object
- Object
- MyStuff::Logger::Reader
- Defined in:
- lib/my_stuff/logger/reader.rb
Instance Attribute Summary collapse
-
#filters ⇒ Object
Returns the value of attribute filters.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #colorize? ⇒ Boolean
-
#format_io(input) ⇒ Object
Read lines from IO, and pretty-print them.
- #format_log_line(x) ⇒ Object
-
#initialize(options = {}) ⇒ Reader
constructor
A new instance of Reader.
-
#write(x) ⇒ Object
Do a really poor job of emulating an IO device :p.
Constructor Details
#initialize(options = {}) ⇒ Reader
Returns a new instance of Reader.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/my_stuff/logger/reader.rb', line 12 def initialize = {} @output = [:device] || STDOUT if .include? :colorize @colorize = [:colorize] else @colorize = @output.tty? end @filters = ([:filters] || [ :PriorityColors, ]).map{ |filter| ReaderFilters.get(filter) } end |
Instance Attribute Details
#filters ⇒ Object
Returns the value of attribute filters.
8 9 10 |
# File 'lib/my_stuff/logger/reader.rb', line 8 def filters @filters end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
9 10 11 |
# File 'lib/my_stuff/logger/reader.rb', line 9 def output @output end |
Instance Method Details
#colorize? ⇒ Boolean
10 |
# File 'lib/my_stuff/logger/reader.rb', line 10 def colorize?; @colorize; end |
#format_io(input) ⇒ Object
Read lines from IO, and pretty-print them.
26 27 28 29 30 |
# File 'lib/my_stuff/logger/reader.rb', line 26 def format_io input input.each_line do |line| output.write format_log_line(line) end end |
#format_log_line(x) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/my_stuff/logger/reader.rb', line 32 def format_log_line x filters.each do |filter| x.replace(filter.call(x, :colorize => colorize?)) end x end |
#write(x) ⇒ Object
Do a really poor job of emulating an IO device :p
40 41 42 43 44 |
# File 'lib/my_stuff/logger/reader.rb', line 40 def write x x.each_line do |line| output.write format_log_line(line) end end |