crusher 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  module Crusher
2
2
  class CrushSession
3
3
 
4
- attr_reader :target, :scenario, :log_file
4
+ attr_reader :target, :scenario, :logger
5
5
 
6
6
  def initialize(target, scenario, options = {})
7
7
  @target = target
@@ -26,12 +26,8 @@ module Crusher
26
26
  end
27
27
 
28
28
  def log(message)
29
- log_message = Time.now.strftime('%Y-%m-%d %H:%M:%S') + ' ' + @current_phase + ' ' + message + "\n"
30
- if @log_file
31
- @log_file.syswrite(log_message)
32
- else
33
- puts log_message
34
- end
29
+ log_message = @current_phase + ' ' + message
30
+ @logger.info log_message
35
31
  nil
36
32
  end
37
33
 
@@ -73,8 +69,11 @@ module Crusher
73
69
  return nil if @queued_jobs.length == 0
74
70
 
75
71
  fork do
76
-
77
- @log_file = File.open(@options.delete(:log_file), 'a') if @options[:log_file]
72
+ log_output = @options[:log_file] ? @options.delete(:log_file) : STDOUT
73
+ @logger = Logger.new(log_output, File::APPEND)
74
+ formatter = Logger::Formatter.new
75
+ formatter.datetime_format = "%Y-%m-%d %H:%M:%S"
76
+ @logger.formatter = formatter
78
77
 
79
78
  # Reseed the pseudorandom number generator with the process's PID file, otherwise
80
79
  # we'll inherit our sequence of random numbers from the parent process
@@ -92,7 +91,6 @@ module Crusher
92
91
  end
93
92
 
94
93
  @queued_jobs = []
95
-
96
94
  nil
97
95
  end
98
96
 
@@ -7,12 +7,7 @@ module Crusher
7
7
  @options = options
8
8
 
9
9
  Dir.mkdir @options[:stats_log_dir] if @options[:stats_log_dir] && !File.exist?(@options[:stats_log_dir])
10
-
11
- begin
12
- @log_file = File.open(options[:log_file], 'a') if options[:log_file]
13
- rescue Errno::ENOENT
14
- log("Log file #{options[:log_file]} couldn't be opened; logging to STDOUT")
15
- end
10
+
16
11
  end
17
12
 
18
13
  def act!; end
@@ -27,6 +22,7 @@ module Crusher
27
22
  keys, values = data.map{|k,v| [k.to_s,v.to_s] }.transpose
28
23
  stats_log_file(event_type) do |file|
29
24
  file.syswrite "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')},#{values.join(',')}\n"
25
+ file.flush unless file.fsync
30
26
  end
31
27
  end
32
28
 
data/lib/crusher.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'logger'
1
2
  require 'rubygems'
2
3
  require 'crusher/crush_session'
3
4
  require 'crusher/load_generator'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crusher
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - phene