Class: Leafy::Core::ConsoleReporter

Inherits:
ScheduledReporter show all
Defined in:
lib/leafy/core/console_reporter.rb

Defined Under Namespace

Classes: Builder

Constant Summary collapse

CONSOLE_WIDTH =
80

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ScheduledReporter

createDefaultExecutor, #logger, logger, #report, #start, #stop, #to_s, #update

Constructor Details

#initialize(registry, executor = nil, shutdownExecutorOnStop = true, output: nil, clock: nil) ⇒ ConsoleReporter

Returns a new instance of ConsoleReporter.



56
57
58
59
60
# File 'lib/leafy/core/console_reporter.rb', line 56

def initialize(registry, executor = nil, shutdownExecutorOnStop = true, output: nil, clock: nil)
  super(registry, 'console-reporter', executor, shutdownExecutorOnStop)
  @output = output || STDOUT
  @clock = clock || Clock.default_clock
end

Instance Attribute Details

#clockObject (readonly)

Returns the value of attribute clock.



55
56
57
# File 'lib/leafy/core/console_reporter.rb', line 55

def clock
  @clock
end

#outputObject (readonly)

Returns the value of attribute output.



55
56
57
# File 'lib/leafy/core/console_reporter.rb', line 55

def output
  @output
end

Instance Method Details

#do_report(gauges, counters, histograms, meters, timers) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/leafy/core/console_reporter.rb', line 74

def do_report(gauges,
              counters,
              histograms,
              meters,
              timers)
  dateTime = Time.at(@clock.time / 1000000.0).utc
  printWithBanner(dateTime.to_s, '=');
  output.puts

  print_report(gauges, 'Gauges', method(:printGauge))
  print_report(counters, 'Counters', method(:printCounter))
  print_report(histograms, 'Histograms', method(:printHistogram))
  print_report(meters, 'Meters', method(:printMeter))
  print_report(timers, 'Timers', method(:printTimer))

  output.puts
  output.flush
end

#printWithBanner(string, char) ⇒ Object



149
150
151
152
153
154
# File 'lib/leafy/core/console_reporter.rb', line 149

def printWithBanner(string, char)
  output.print(string)
  output.print(' ')
  (CONSOLE_WIDTH - string.size - 1).times { output.print(char) }
  output.puts
end