Sha256: 397c5937ebebf6df59b1d56436071262f5cefbaace8ccf74266c37d425fbb5d9

Contents?: true

Size: 866 Bytes

Versions: 14

Compression:

Stored size: 866 Bytes

Contents

class Posgra::Logger < ::Logger
  include Singleton

  def initialize
    super($stdout)

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

    self.level = Logger::INFO
  end

  def set_debug(value)
    self.level = value ? Logger::DEBUG : Logger::INFO
  end

  module Helper
    def log(level, message, options = {})
      global_options = @options || {}
      message = "#{@object_identifier}: #{message}" if @object_identifier
      message = "[#{level.to_s.upcase}] #{message}" unless level == :info

      if global_options[:dry_run] and options[:dry_run] != false
        message << ' (dry-run)' if global_options[:dry_run]
      end

      message = message.send(options[:color]) if options[:color]
      logger = global_options[:logger] || Posgra::Logger.instance
      logger.send(level, message)
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
posgra-0.2.3.beta lib/posgra/logger.rb
posgra-0.2.2 lib/posgra/logger.rb
posgra-0.2.1 lib/posgra/logger.rb
posgra-0.2.0 lib/posgra/logger.rb
posgra-0.1.9 lib/posgra/logger.rb
posgra-0.1.8 lib/posgra/logger.rb
posgra-0.1.7 lib/posgra/logger.rb
posgra-0.1.6 lib/posgra/logger.rb
posgra-0.1.5 lib/posgra/logger.rb
posgra-0.1.4 lib/posgra/logger.rb
posgra-0.1.3 lib/posgra/logger.rb
posgra-0.1.2 lib/posgra/logger.rb
posgra-0.1.1 lib/posgra/logger.rb
posgra-0.1.0 lib/posgra/logger.rb