Class: Hiera::Backend::Eyaml::LoggingHelper
- Inherits:
-
Object
- Object
- Hiera::Backend::Eyaml::LoggingHelper
- Defined in:
- lib/hiera/backend/eyaml/logginghelper.rb
Class Method Summary collapse
- .colorize(message, color) ⇒ Object
- .debug(messageinfo) ⇒ Object
- .hiera? ⇒ Boolean
- .info(messageinfo) ⇒ Object
- .print_message(args) ⇒ Object
- .structure_message(messageinfo) ⇒ Object
- .trace(messageinfo) ⇒ Object
- .warn(messageinfo) ⇒ Object
Class Method Details
.colorize(message, color) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 58 def self.colorize , color suffix = "\e[0m" prefix = case color when :red "\e[31m" when :green "\e[32m" when :blue "\e[34m" else #:white "\e[0m" end "#{prefix}#{}#{suffix}" end |
.debug(messageinfo) ⇒ Object
37 38 39 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 37 def self.debug self.({ :message => self.( ), :hiera_loglevel => :debug, :cli_color => :green, :threshold => 1 }) end |
.hiera? ⇒ Boolean
73 74 75 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 73 def self.hiera? "hiera".eql? Eyaml::Options[:source] end |
.info(messageinfo) ⇒ Object
33 34 35 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 33 def self.info self.({ :message => self.( ), :hiera_loglevel => :debug, :cli_color => :white, :threshold => 0 }) end |
.print_message(args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 45 def self.( args ) = args[:message] ||= "" hiera_loglevel = args[:hiera_loglevel] ||= :debug cli_color = args[:cli_color] ||= :blue threshold = args[:threshold] if self.hiera? Hiera.send(hiera_loglevel, ) if threshold.nil? or Eyaml.verbosity_level > threshold else STDERR.puts self.colorize( , cli_color ) if threshold.nil? or Eyaml.verbosity_level > threshold end end |
.structure_message(messageinfo) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 9 def self. = {:from => "hiera-eyaml-core"} case .class.to_s when 'Hash' .merge!() else .merge!({:msg => .to_s}) end [:prefix] = "[#{[:from]}]" [:spacer] = " #{' ' * [:from].length} " formatted_output = [:msg].split("\n").each_with_index.map do |line, index| if index == 0 "#{[:prefix]} #{line}" else "#{[:spacer]} #{line}" end end formatted_output.join "\n" end |
.trace(messageinfo) ⇒ Object
41 42 43 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 41 def self.trace self.({ :message => self.( ), :hiera_loglevel => :debug, :cli_color => :blue, :threshold => 2 }) end |
.warn(messageinfo) ⇒ Object
29 30 31 |
# File 'lib/hiera/backend/eyaml/logginghelper.rb', line 29 def self.warn self.({ :message => self.( ), :hiera_loglevel => :warn, :cli_color => :red }) end |