From 582d5427cfa17131d789417b92d2b36d866efdf9 Mon Sep 17 00:00:00 2001 From: David Byron Date: Fri, 17 Apr 2015 09:18:14 -0700 Subject: [PATCH 1/2] test that using logger works --- spec/sneakers/runner_spec.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 spec/sneakers/runner_spec.rb diff --git a/spec/sneakers/runner_spec.rb b/spec/sneakers/runner_spec.rb new file mode 100644 index 00000000..98c8bdba --- /dev/null +++ b/spec/sneakers/runner_spec.rb @@ -0,0 +1,26 @@ +require 'logger' +require 'spec_helper' +require 'sneakers' + +describe Sneakers::Runner do + let(:logger) { Logger.new('logtest.log') } + + describe "with configuration that specifies a logger object" do + before do + Sneakers.configure(log: logger) + @runner = Sneakers::Runner.new([]) + end + + it 'passes the logger to serverengine' do + # Stub out ServerEngine::Daemon.run so we only exercise the way we invoke + # ServerEngine.create + any_instance_of(ServerEngine::Daemon) do |daemon| + stub(daemon).main{ return 0 } + end + + @runner.run + # look at @runner's @se instance variable (actually of type Daemon)...and + # figure out what it's logger is... + end + end +end From f90e810f5cdc30aaf38fe8f4d39afa3339380b81 Mon Sep 17 00:00:00 2001 From: David Byron Date: Tue, 14 Apr 2015 13:59:06 -0700 Subject: [PATCH 2/2] Give serverengine the same logger object sneakers uses. Avoid problems when Sneakers.configure receives a logger object instead of a log file. --- lib/sneakers/runner.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/sneakers/runner.rb b/lib/sneakers/runner.rb index bca3ac5e..07f495dc 100644 --- a/lib/sneakers/runner.rb +++ b/lib/sneakers/runner.rb @@ -64,8 +64,15 @@ def reload_config! end private - def make_serverengine_config + def make_serverengine_config + # From Sneakers#setup_general_logger, there's support for a Logger object + # in CONFIG[:log]. However, serverengine takes an object in :logger. + # Pass our logger object so there's no issue about sometimes passing a + # file and sometimes an object. + without_log = Sneakers::CONFIG.merge(@conf) + without_log.delete(:log) Sneakers::CONFIG.merge(@conf).merge({ + :logger => Sneakers.logger, :worker_type => 'process', :worker_classes => @worker_classes })