On Nov 27, 2009, at 8:43 AM, Yannick Perret wrote:
> Hello,
>
> the incident #2527 is related to the lack of control of loglevel on
> puppetd program.
>
> This lack is still present in 0.25.1.
> I wrote a patch for puppetd.rb code (located at
> /usr/lib/ruby/site_ruby/1.8/puppet/application/puppetd.rb on my
> client).
>
> This patch adds an option "--loglevel" which accept
> debug/notice/warning/... parameters. This loglevel is applied,
> appart if
> an other option set the loglevel (i.e. --test).
> If the given loglevel is not valid the current default loglevel is
> used.
>
> As I'm not very familiar with ruby code neigther with puppet code
> structure, please feel free to review it.
>
> Here is the patch:
> --- puppetd.rb 2009-11-27 15:43:29.191196367 +0100
> +++ puppetd.new.rb 2009-11-27 15:43:57.391197765 +0100
> @@ -25,6 +25,7 @@
> :debug => false,
> :centrallogs => false,
> :setdest => false,
> + :loglevel => false,
> :enable => false,
> :disable => false,
> :client => true,
> @@ -86,6 +87,10 @@
> @args[:Port] = arg
> end
>
> + option("--loglevel LOGLEVEL") do |arg|
> + options[:loglevel] = arg
> + end
> +
> dispatch do
> return :onetime if options[:onetime]
> return :main
> @@ -135,7 +140,30 @@
> if options[:debug]
> Puppet::Util::Log.level = :debug
> else
> - Puppet::Util::Log.level = :info
> + if options[:loglevel]
> + if options[:loglevel] == "debug"
> + Puppet::Util::Log.level = :debug
> + elsif options[:loglevel] == "info"
> + Puppet::Util::Log.level = :info
> + elsif options[:loglevel] == "notice"
> + Puppet::Util::Log.level = :notice
> + elsif options[:loglevel] == "warning"
> + Puppet::Util::Log.level = :warning
> + elsif options[:loglevel] == "err"
> + Puppet::Util::Log.level = :err
> + elsif options[:loglevel] == "alert"
> + Puppet::Util::Log.level = :alert
> + elsif options[:loglevel] == "emerg"
> + Puppet::Util::Log.level = :emerg
> + elsif options[:loglevel] == "crit"
> + Puppet::Util::Log.level = :crit
> + else
This is much easier with something like:
if options[:loglevel]
begin
Puppet::Util::Log.level = options[:loglevel].to_sym
rescue => detail
raise ArgumentError, "Invalid log level #{options[:loglevel]}"
end
end
No need for a huge case statement.
> + Puppet.warning "Invalid loglevel %s. Using info." %
> options[:loglevel]
> + Puppet::Util::Log.level = :info
> + end
> + else
> + Puppet::Util::Log.level = :info
> + end
I think there's some duplication of logic here, in that you're setting
the level to info at least three different places.
And it shouldn't be too hard to have some tests for this.
> end
> end
>
>
> Regards,
> --
> Yannick
>
>
> --
>
> You received this message because you are subscribed to the Google
> Groups "Puppet Developers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]
> .
> For more options, visit this group at
> http://groups.google.com/group/puppet-dev?hl=en
> .
>
>
--
A child can go only so far in life without potty training. It is not
mere coincidence that six of the last seven presidents were potty
trained, not to mention nearly half of the nation's state legislators.
-- Dave Barry
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.