From a1b77aa2df669ef7a2f4c0ba416f9f926b21b7bf Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Fri, 13 Oct 2017 10:44:14 +1100 Subject: [PATCH] feat: allow log level to be configured via PACT_BROKER_LOG_LEVEL --- README.md | 9 +++++++++ container/etc/nginx/main.d/pactbroker-env.conf | 1 + pact_broker/config.ru | 5 ++--- pact_broker/logger.rb | 11 +++++++++++ script/test.sh | 1 + 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 pact_broker/logger.rb diff --git a/README.md b/README.md index 8d3a800..1123f75 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/container/etc/nginx/main.d/pactbroker-env.conf b/container/etc/nginx/main.d/pactbroker-env.conf index cc5c2e7..30af19a 100644 --- a/container/etc/nginx/main.d/pactbroker-env.conf +++ b/container/etc/nginx/main.d/pactbroker-env.conf @@ -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; diff --git a/pact_broker/config.ru b/pact_broker/config.ru index e1a87b2..5f29e05 100644 --- a/pact_broker/config.ru +++ b/pact_broker/config.ru @@ -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 diff --git a/pact_broker/logger.rb b/pact_broker/logger.rb new file mode 100644 index 0000000..e467734 --- /dev/null +++ b/pact_broker/logger.rb @@ -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 diff --git a/script/test.sh b/script/test.sh index b36636b..f90a6af 100755 --- a/script/test.sh +++ b/script/test.sh @@ -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}