Skip to content

Commit a1b77aa

Browse files
committed
feat: allow log level to be configured via PACT_BROKER_LOG_LEVEL
1 parent 703110a commit a1b77aa

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ For an sqlite database (only recommended for investigation/spikes, as it will be
4040
## Using basic auth
4141
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.
4242

43+
## Setting the log level
44+
45+
Set the environment variable `PACT_BROKER_LOG_LEVEL` to one of `DEBUG`, `INFO`, `WARN`, `ERROR`, or `FATAL`.
46+
4347
## Running with Docker Compose
4448

4549
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!
5862

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

65+
# Troubleshooting
66+
67+
See the [Troubleshooting][troubleshooting] page on the wiki.
68+
6169
[badges]: https://github.com/pact-foundation/pact_broker/wiki/Provider-verification-badges
70+
[troubleshooting]: https://github.com/DiUS/pact_broker-docker/wiki/Troubleshooting

container/etc/nginx/main.d/pactbroker-env.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ env PACT_BROKER_DATABASE_NAME;
66
env PACT_BROKER_DATABASE_PORT;
77
env PACT_BROKER_BASIC_AUTH_USERNAME;
88
env PACT_BROKER_BASIC_AUTH_PASSWORD;
9+
env PACT_BROKER_LOG_LEVEL;

pact_broker/config.ru

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
require 'logger'
21
require 'sequel'
32
require 'pact_broker'
3+
require_relative 'logger'
44
require_relative 'basic_auth'
55
require_relative 'database_connection'
66
require_relative 'passenger_config'
77

88
app = PactBroker::App.new do | config |
9-
config.logger = ::Logger.new($stdout)
10-
config.logger.level = Logger::WARN
9+
config.logger = $logger
1110
config.database_connection = create_database_connection(config.logger)
1211
config.database_connection.timezone = :utc
1312
end

pact_broker/logger.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'logger'
2+
3+
log_level = begin
4+
Kernel.const_get('Logger').const_get(ENV['PACT_BROKER_LOG_LEVEL'] || 'WARN')
5+
rescue NameError
6+
$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."
7+
Logger::WARN
8+
end
9+
10+
$logger = ::Logger.new($stdout)
11+
$logger.level = log_level

script/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ docker run --privileged --name=${PACT_CONT_NAME} -d -p ${PORT_BIND} \
159159
-e PACT_BROKER_DATABASE_PORT=${PACT_BROKER_DATABASE_PORT} \
160160
-e PACT_BROKER_BASIC_AUTH_USERNAME=${PACT_BROKER_BASIC_AUTH_USERNAME} \
161161
-e PACT_BROKER_BASIC_AUTH_PASSWORD=${PACT_BROKER_BASIC_AUTH_PASSWORD} \
162+
-e PACT_BROKER_LOG_LEVEL=INFO \
162163
dius/pact_broker
163164
sleep 1 && docker logs ${PACT_CONT_NAME}
164165

0 commit comments

Comments
 (0)