Sha256: bc1bf125402fdacfcaec7b8da3529b863dbb0444c298477ca022f86a4dc8d25d

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

class Cronicle::Logger < ::Logger
  include Singleton

  def initialize
    super($stdout)

    self.formatter = proc do |severity, datetime, progname, msg|
      "#{msg}\n"
    end

    self.level = INFO
  end

  def set_debug(value)
    if value
      self.level = DEBUG
      SSHKit.config.output_verbosity = :debug
    else
      self.level = INFO
      SSHKit.config.output_verbosity = :warn
    end
  end

  class << self
    def log(level, message, opts = {})
      message = "#{level.to_s.downcase}: #{message}" unless level == :info
      message << ' (dry-run)' if opts[:dry_run]
      message.gsub!(/\s+\z/, '')
      message = message.send(opts[:color]) if opts[:color]

      job_info = ''

      if opts[:job]
        job_info << opts[:job]
      end

      host_user = [:host, :user].map {|key|
        value = opts[key]
	next unless value
        value = Cronicle::Utils.short_hostname(value) if key == :host
        value
      }.compact

      unless host_user.empty?
        job_info << ' on ' unless job_info.empty?
        job_info << host_user.join('/')
      end

      unless job_info.empty?
        job_info = "#{job_info}>".light_black
        message = "#{job_info} #{message}"
      end

      logger = opts[:logger] || Cronicle::Logger.instance
      logger.send(level, message)
    end
  end # of class methods

  # XXX:
  module Helper
    def log(level, message, opts = {})
      opts = (@options || {}).merge(opts)
      Cronicle::Logger.log(level, message, opts)
    end
  end
end

SSHKit.config.output_verbosity = :warn

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cronicle-0.2.3 lib/cronicle/logger.rb