Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(maint) Enable logging for all puppet doc commands #1580

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 13 additions & 9 deletions lib/puppet/application/doc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ def setup
else
setup_reference
end

setup_logging
end

def setup_reference
Expand All @@ -261,16 +263,18 @@ def setup_rdoc(dummy_argument=:work_arround_for_ruby_GC_bug)
Puppet.settings.handlearg(option[:opt], option[:arg])
end
end
end

# Handle the logging settings.
if options[:debug] or options[:verbose]
if options[:debug]
Puppet::Util::Log.level = :debug
else
Puppet::Util::Log.level = :info
end

Puppet::Util::Log.newdestination(:console)
def setup_logging
# Handle the logging settings.
if options[:debug]
Puppet::Util::Log.level = :debug
elsif options[:verbose]
Puppet::Util::Log.level = :info
else
Puppet::Util::Log.level = :warning
end

Puppet::Util::Log.newdestination(:console)
end
end
87 changes: 55 additions & 32 deletions spec/unit/application/doc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,61 @@
@doc.setup
end

describe "configuring logging" do
before :each do
Puppet::Util::Log.stubs(:newdestination)
end

describe "with --debug" do
before do
@doc.options[:debug] = true
end

it "should set log level to debug" do
@doc.setup
Puppet::Util::Log.level.should == :debug
end

it "should set log destination to console" do
Puppet::Util::Log.expects(:newdestination).with(:console)
@doc.setup
end
end

describe "with --verbose" do
before do
@doc.options[:verbose] = true
end

it "should set log level to info" do
@doc.setup
Puppet::Util::Log.level.should == :info
end

it "should set log destination to console" do
Puppet::Util::Log.expects(:newdestination).with(:console)
@doc.setup
end
end

describe "without --debug or --verbose" do
before do
@doc.options[:debug] = false
@doc.options[:verbose] = false
end

it "should set log level to warning" do
@doc.setup
Puppet::Util::Log.level.should == :warning
end

it "should set log destination to console" do
Puppet::Util::Log.expects(:newdestination).with(:console)
@doc.setup
end
end
end

describe "in non-rdoc mode" do
it "should get all non-dynamic reference if --all" do
@doc.options[:all] = true
Expand All @@ -163,10 +218,6 @@
end

describe "in rdoc mode" do
before :each do
Puppet::Util::Log.stubs(:newdestination)
end

describe "when there are unknown args" do
it "should expand --modulepath if any" do
@doc.unknown_args = [ { :opt => "--modulepath", :arg => "path" } ]
Expand Down Expand Up @@ -199,34 +250,6 @@

@doc.setup_rdoc
end

it "should set log level to debug if --debug" do
@doc.options[:debug] = true
@doc.setup_rdoc
Puppet::Util::Log.level.should == :debug
end

it "should set log level to info if --verbose" do
@doc.options[:verbose] = true
@doc.setup_rdoc
Puppet::Util::Log.level.should == :info
end

it "should set log destination to console if --verbose" do
@doc.options[:verbose] = true

Puppet::Util::Log.expects(:newdestination).with(:console)

@doc.setup_rdoc
end

it "should set log destination to console if --debug" do
@doc.options[:debug] = true

Puppet::Util::Log.expects(:newdestination).with(:console)

@doc.setup_rdoc
end
end
end

Expand Down