Skip to content

Commit

Permalink
ADD KNAPSACK_LOG_LEVEL option
Browse files Browse the repository at this point in the history
  • Loading branch information
k2nr committed Oct 11, 2016
1 parent 3539d3b commit 05d028f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/knapsack.rb
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
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
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

0 comments on commit 05d028f

Please sign in to comment.