Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,14 @@ For instance to run subset of tests for the first CI node with specified seed yo

Above example is for RSpec. You can use respectively rake task name and token environment variable when you want to run tests for minitest, cucumber or spinach.

### How can I change log level?

You can change log level by specifying the `KNAPSACK_LOG_LEVEL` environment variable.

KNAPSACK_LOG_LEVEL=warn bundle exec rake knapsack:rspec

Available values are `debug`, `info`, and `warn`. The default log level is `info`.

## Gem tests

### Spec
Expand Down
2 changes: 1 addition & 1 deletion lib/knapsack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def load_tasks
def logger
return @@logger if @@logger
log = Knapsack::Logger.new
log.level = Knapsack::Logger::INFO
log.level = Knapsack::Config::Env.log_level
@@logger = log
end

Expand Down
8 changes: 8 additions & 0 deletions lib/knapsack/config/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def test_dir
ENV['KNAPSACK_TEST_DIR']
end

def log_level
{
"debug" => Knapsack::Logger::DEBUG,
"info" => Knapsack::Logger::INFO,
"warn" => Knapsack::Logger::WARN,
}[ENV['KNAPSACK_LOG_LEVEL']] || Knapsack::Logger::INFO
end

private

def index_starting_from_one(index)
Expand Down
14 changes: 14 additions & 0 deletions spec/knapsack/config/env_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,18 @@
it { should be_nil }
end
end

describe '.log_level' do
subject { described_class.log_level }

context 'when ENV exists' do
let(:log_level) { 'debug' }
before { stub_const("ENV", { 'KNAPSACK_LOG_LEVEL' => log_level }) }
it { should eql Knapsack::Logger::DEBUG }
end

context "when ENV doesn't exist" do
it { should eql Knapsack::Logger::INFO }
end
end
end