Skip to content

Commit

Permalink
feat: allow log level to be configured via PACT_BROKER_LOG_LEVEL
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 12, 2017
1 parent 703110a commit a1b77aa
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ For an sqlite database (only recommended for investigation/spikes, as it will be
## Using basic auth
Run your container with `PACT_BROKER_BASIC_AUTH_USERNAME` and `PACT_BROKER_BASIC_AUTH_PASSWORD` set to enable basic auth for the pact broker application. Note that the [verification status badges][badges] are not protected by basic auth, so that you may embed them in README markdown.

## Setting the log level

Set the environment variable `PACT_BROKER_LOG_LEVEL` to one of `DEBUG`, `INFO`, `WARN`, `ERROR`, or `FATAL`.

## Running with Docker Compose

For a quick start with the Pact Broker and Postgres, we have an example
Expand All @@ -58,4 +62,9 @@ curl -v http://$DOCKER_HOST # you can visit in your browser too!

_NOTE: this image should be modified before using in Production, in particular, the use of hard-coded credentials_

# Troubleshooting

See the [Troubleshooting][troubleshooting] page on the wiki.

[badges]: https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-badges
[troubleshooting]: https://github.com/DiUS/pact_broker-docker/wiki/Troubleshooting
1 change: 1 addition & 0 deletions container/etc/nginx/main.d/pactbroker-env.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ env PACT_BROKER_DATABASE_NAME;
env PACT_BROKER_DATABASE_PORT;
env PACT_BROKER_BASIC_AUTH_USERNAME;
env PACT_BROKER_BASIC_AUTH_PASSWORD;
env PACT_BROKER_LOG_LEVEL;
5 changes: 2 additions & 3 deletions pact_broker/config.ru
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
require 'logger'
require 'sequel'
require 'pact_broker'
require_relative 'logger'
require_relative 'basic_auth'
require_relative 'database_connection'
require_relative 'passenger_config'

app = PactBroker::App.new do | config |
config.logger = ::Logger.new($stdout)
config.logger.level = Logger::WARN
config.logger = $logger
config.database_connection = create_database_connection(config.logger)
config.database_connection.timezone = :utc
end
Expand Down
11 changes: 11 additions & 0 deletions pact_broker/logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'logger'

log_level = begin
Kernel.const_get('Logger').const_get(ENV['PACT_BROKER_LOG_LEVEL'] || 'WARN')
rescue NameError
$stderr.puts "Ignoring PACT_BROKER_LOG_LEVEL '#{ENV['PACT_BROKER_LOG_LEVEL']}' as it is invalid. Valid values are: DEBUG INFO WARN ERROR FATAL. Using WARN."
Logger::WARN
end

$logger = ::Logger.new($stdout)
$logger.level = log_level
1 change: 1 addition & 0 deletions script/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ docker run --privileged --name=${PACT_CONT_NAME} -d -p ${PORT_BIND} \
-e PACT_BROKER_DATABASE_PORT=${PACT_BROKER_DATABASE_PORT} \
-e PACT_BROKER_BASIC_AUTH_USERNAME=${PACT_BROKER_BASIC_AUTH_USERNAME} \
-e PACT_BROKER_BASIC_AUTH_PASSWORD=${PACT_BROKER_BASIC_AUTH_PASSWORD} \
-e PACT_BROKER_LOG_LEVEL=INFO \
dius/pact_broker
sleep 1 && docker logs ${PACT_CONT_NAME}
Expand Down

0 comments on commit a1b77aa

Please sign in to comment.