Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: postrank-labs/goliath
...
head fork: postrank-labs/goliath
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on May 19, 2011
@dj2 dj2 Allow custom logger setup.
Defining a setup_logger method in the API will allow the API to
override the standard Goliath logging. Note, if this is used, Goliath
will not setup any loggers. It is your responsibility to deal with
stdout and file logging if desired.

[Issue #52]
42260c4
View
15 examples/custom_logger.rb
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+$:<< '../lib' << 'lib'
+
+require 'goliath'
+
+class CustomLogger < Goliath::API
+ def setup_logger(logger, opts)
+ log_format = Log4r::PatternFormatter.new(:pattern => "%d :: %m")
+ logger.add(Log4r::StdoutOutputter.new('console', :formatter => log_format))
+ end
+
+ def response(env)
+ [200, {}, "OK"]
+ end
+end
View
8 lib/goliath/runner.rb
@@ -176,12 +176,18 @@ def show_options(opts)
# @return [Logger] The logger object
def setup_logger
log = Log4r::Logger.new('goliath')
+ log.level = @verbose ? Log4r::DEBUG : Log4r::INFO
+
+ # allow api to setup logging as it desires
+ if api.respond_to?(:setup_logger)
+ api.setup_logger(log, options)
+ return log
+ end
log_format = Log4r::PatternFormatter.new(:pattern => "[#{Process.pid}:%l] %d :: %m")
setup_file_logger(log, log_format) if @log_file
setup_stdout_logger(log, log_format) if @log_stdout
- log.level = @verbose ? Log4r::DEBUG : Log4r::INFO
log
end
View
19 spec/unit/runner_spec.rb
@@ -89,6 +89,25 @@
log = @r.send(:setup_logger)
end
end
+
+ describe 'custom logger' do
+ it 'calls the api loger setup method' do
+ api = mock('api')
+ api.should_receive(:respond_to?).with(:setup_logger).and_return(true)
+ api.should_receive(:setup_logger).and_return(true)
+
+ @r.should_not_receive(:setup_stdout_logger)
+ @r.should_not_receive(:setup_file_logger)
+
+ @r.api = api
+ @r.log_stdout = true
+ @r.verbose = true
+ @r.log_file = 'out.log'
+
+ l = @r.send(:setup_logger)
+ l.should_not be_nil
+ end
+ end
end
it 'creates the log dir if neeed' do

No commit comments for this range

Something went wrong with that request. Please try again.