Skip to content

Instantly share code, notes, and snippets.

@guyhughes
Last active August 29, 2015 14:01
Show Gist options
  • Save guyhughes/ea9ae37dfe12ee3c7292 to your computer and use it in GitHub Desktop.
Save guyhughes/ea9ae37dfe12ee3c7292 to your computer and use it in GitHub Desktop.
Ruby: Using Logger class with Thor.
require 'thor'
require 'logger'
class_option :verbose, :type => :boolean, :aliases => "-v"
class_option :debug, :type => :boolean, :aliases => "-d"
class_option :quiet, :type => :boolean, :aliases => "-q"
def initialize(*args)
@log = Logger.new(STDOUT)
if options[:debug]
@log.level = Logger::DEBUG
@log.info("Logger level set to DEBUG")
elsif options[:verbose]
@log.level = Logger::INFO
@log.info("Logger level set to INFO")
elsif options[:quiet]
@log.level = Logger::ERROR
@log.info("Logger level set to ERROR")
else
@log.level = Logger::WARN
@log.info("Logger level defaulting to WARN")
end
end

Ruby: Basic implementation of Logger class using Thor cli.

... just so I don't have to look for this again, ever.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment