Sha256: 1a7adf71694db322a8f5c7ef725219c4c8df6b5e1435760b05c4809a63d1c400

Contents?: true

Size: 1.79 KB

Versions: 20

Compression:

Stored size: 1.79 KB

Contents

module MCollective
  module Logger
    # Implements a syslog based logger using the standard ruby syslog class
    class Console_logger < Base
      def start
        set_level(:info)

        config = Config.instance
        set_level(config.loglevel.to_sym) if config.configured
      end

      def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName
        # nothing to do here, we ignore high levels when we log
      end

      def valid_levels
        {:info => :info,
         :warn => :warning,
         :debug => :debug,
         :fatal => :crit,
         :error => :err}
      end

      def log(level, from, msg, normal_output=$stderr, last_resort_output=$stderr)
        if @known_levels.index(level) >= @known_levels.index(@active_level)
          time = Time.new.strftime("%Y/%m/%d %H:%M:%S")

          normal_output.puts("%s %s: %s %s" % [colorize(level, level), time, from, msg])
        end
      rescue
        # if this fails we probably cant show the user output at all,
        # STDERR it as last resort
        last_resort_output.puts("#{level}: #{msg}")
      end

      # Set some colors for various logging levels, will honor the
      # color configuration option and return nothing if its configured
      # not to
      def color(level)
        colorize = Config.instance.color

        colors = {:error => Util.color(:red),
                  :fatal => Util.color(:red),
                  :warn => Util.color(:yellow),
                  :info => Util.color(:green),
                  :reset => Util.color(:reset)}

        if colorize
          colors[level] || ""
        else
          ""
        end
      end

      # Helper to return a string in specific color
      def colorize(level, msg)
        "%s%s%s" % [color(level), msg, color(:reset)]
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
choria-mcorpc-support-2.26.5 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.26.4 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.26.3 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.26.2 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.26.1 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.26.0 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.25.3 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.25.2 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.25.1 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.25.0 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.24.4 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.24.3 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.24.2 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.24.1 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.24.0 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.23.3 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.23.2 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.23.1 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.23.0 lib/mcollective/logger/console_logger.rb
choria-mcorpc-support-2.23.0.pre lib/mcollective/logger/console_logger.rb