Class: BenchBloc::Logger
- Inherits:
-
Object
- Object
- BenchBloc::Logger
- Defined in:
- lib/bench_bloc/logger/logger.rb
Direct Known Subclasses
Defined Under Namespace
Classes: RubyProf
Instance Attribute Summary collapse
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize(results, title) ⇒ Logger
constructor
A new instance of Logger.
-
#log_results ⇒ Object
TODO: Split into a BenchmarkLogger class.
- #write_to_log(results) ⇒ Object
Constructor Details
#initialize(results, title) ⇒ Logger
Returns a new instance of Logger.
5 6 7 |
# File 'lib/bench_bloc/logger/logger.rb', line 5 def initialize results, title @results, @title = results, title end |
Instance Attribute Details
#results ⇒ Object (readonly)
Returns the value of attribute results.
4 5 6 |
# File 'lib/bench_bloc/logger/logger.rb', line 4 def results @results end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
4 5 6 |
# File 'lib/bench_bloc/logger/logger.rb', line 4 def title @title end |
Instance Method Details
#log_results ⇒ Object
TODO: Split into a BenchmarkLogger class
10 11 12 13 14 15 |
# File 'lib/bench_bloc/logger/logger.rb', line 10 def log_results results.sort! { |a, b| b.real <=> a.real } formatted_results = BenchBloc::Formatter::Benchmark.new(results, title).format_results write_to_log formatted_results end |
#write_to_log(results) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bench_bloc/logger/logger.rb', line 17 def write_to_log results if defined?(Rails) # Rails Logger not working, naming conflict I think, # or it needs to be required # log = Rails::Logger.new("#{Rails.root}/log/benchmarks.log") # log.info(results) f = File.new("#{Rails.root}/log/benchmarks.log", "w") f.puts(results) f.close else f = File.new("benchmarks.log", "w") f.puts(results) f.puts(parse_db_logger) f.close end end |