Class: ChefBackup::Logger
- Inherits:
-
Object
- Object
- ChefBackup::Logger
- Defined in:
- lib/chef_backup/logger.rb
Overview
Basic Logging Class
Instance Attribute Summary collapse
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #color? ⇒ Boolean
-
#initialize(logfile = nil) ⇒ Logger
constructor
A new instance of Logger.
- #log(msg, level = :info) ⇒ Object
-
#pastel ⇒ Object
pastel.decorate is a lightweight replacement for highline.color.
Constructor Details
#initialize(logfile = nil) ⇒ Logger
Returns a new instance of Logger.
15 16 17 |
# File 'lib/chef_backup/logger.rb', line 15 def initialize(logfile = nil) $stdout = logfile ? File.open(logfile, "ab") : $stdout end |
Instance Attribute Details
#stdout ⇒ Object
Returns the value of attribute stdout.
13 14 15 |
# File 'lib/chef_backup/logger.rb', line 13 def stdout @stdout end |
Class Method Details
.log(msg, level = :info) ⇒ Object
9 10 11 |
# File 'lib/chef_backup/logger.rb', line 9 def self.log(msg, level = :info) logger.log(msg, level) end |
.logger(logfile = nil) ⇒ Object
4 5 6 7 |
# 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 |
Instance Method Details
#color? ⇒ Boolean
40 41 42 |
# File 'lib/chef_backup/logger.rb', line 40 def color? $stdout.tty? end |
#log(msg, level = :info) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 ⇒ Object
pastel.decorate is a lightweight replacement for highline.color
20 21 22 23 24 25 |
# File 'lib/chef_backup/logger.rb', line 20 def pastel @pastel ||= begin require "pastel" unless defined?(Pastel) Pastel.new end end |