class ChefBackup::Logger
Basic Logging Class
Attributes
stdout[RW]
Public Class Methods
log(msg, level = :info)
click to toggle source
# File lib/chef_backup/logger.rb, line 9 def self.log(msg, level = :info) logger.log(msg, level) end
logger(logfile = nil)
click to toggle source
# File lib/chef_backup/logger.rb, line 4 def self.logger(logfile = nil) @logger = nil if @logger && logfile && @logger.stdout != logfile @logger ||= new(logfile) end
new(logfile = nil)
click to toggle source
# File lib/chef_backup/logger.rb, line 15 def initialize(logfile = nil) $stdout = logfile ? File.open(logfile, "ab") : $stdout end
Public Instance Methods
color?()
click to toggle source
# File lib/chef_backup/logger.rb, line 40 def color? $stdout.tty? end
log(msg, level = :info)
click to toggle source
# File lib/chef_backup/logger.rb, line 27 def log(msg, level = :info) case level when :warn msg = "WARNING: #{msg}" $stdout.puts(color? ? pastel.decorate(msg, :yellow) : msg) when :error msg = "ERROR: #{msg}" $stdout.puts(color? ? pastel.decorate(msg, :red) : msg) else $stdout.puts(msg) end end
pastel()
click to toggle source
pastel.decorate is a lightweight replacement for highline.color
# File lib/chef_backup/logger.rb, line 20 def pastel @pastel ||= begin require "pastel" unless defined?(Pastel) Pastel.new end end