Sha256: 4d3aa1c7e3cf5bc39166371af2373d39849bb818b273a4b4b235f43ba6a2d492

Contents?: true

Size: 1.96 KB

Versions: 46

Compression:

Stored size: 1.96 KB

Contents

module SiteHook
  module Loggers
    class Git
      def initialize(base:, level:)
        @@levels  = {
            unknown: ::Logger::UNKNOWN,
            fatal: ::Logger::FATAL,
            error: ::Logger::ERROR,
            info: ::Logger::INFO,
            debug: ::Logger::DEBUG
        }
        @@loggers = {
            stdout: ::Logger.new(STDOUT, progname: base),
            stderr: ::Logger.new(STDERR, progname: base),
            file: ::Logger.new(SiteHook::Paths.make_log_name(base, level), progname: base)
        }
        @@loggers.each do |_logger, obj|
          obj.datetime_format = '%Y-%m-%dT%H:%M:%S%Z'
          obj.formatter       = proc do |severity, datetime, progname, msg|
            "#{severity} [#{datetime}] #{progname} —— #{msg}\n"
          end
        end
      end

      def unknown(obj)
        @@loggers.each do |key, value|
          next if key == :stderr
          value.unknown(obj)
        end
      end

      def error(obj)
        @@loggers.each do |key, value|
          next if key == :stderr
          value.error(obj)
        end
      end

      def info(obj)
        @@loggers.each do |key, value|
          next if key == :stderr
          value.info(obj)
        end
      end

      def fatal(obj)
        @@loggers.each do |key, value|
          next if key == :stderr
          value.fatal(obj)
        end
      end

      def warn(obj)
        @@loggers.each do |key, value|
          value.warn(obj)
        end
      end
      def debug(obj)
        @@loggers.each do |key, value|
          next if key == :stderr
          value.debug(obj)
        end
      end

      # @param [Symbol] level log level to log at
      # @param [Object] obj some kind of object or msg to log
      def self.log(level, obj)
        @@loggers.each do |logger|
          logger.add(@levels[level], obj)
        end
      end

      def self.log_raw(msg)
        @@loggers.each do |logger|
          logger.<<(obj)
        end

      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
site_hook-1.0.10 lib/site_hook/loggers/git.rb
site_hook-1.0.9 lib/site_hook/loggers/git.rb
site_hook-1.0.8 lib/site_hook/loggers/git.rb
site_hook-1.0.7 lib/site_hook/loggers/git.rb
site_hook-1.0.6 lib/site_hook/loggers/git.rb
site_hook-1.0.5 lib/site_hook/loggers/git.rb
site_hook-1.0.4 lib/site_hook/loggers/git.rb
site_hook-1.0.3 lib/site_hook/loggers/git.rb
site_hook-1.0.2 lib/site_hook/loggers/git.rb
site_hook-1.0.1 lib/site_hook/loggers/git.rb
site_hook-1.0.0 lib/site_hook/loggers/git.rb
site_hook-0.9.20 lib/site_hook/loggers/git.rb
site_hook-0.9.19 lib/site_hook/loggers/git.rb
site_hook-0.9.16 lib/site_hook/loggers/git.rb
site_hook-0.9.15 lib/site_hook/loggers/git.rb
site_hook-0.9.14 lib/site_hook/loggers/git.rb
site_hook-0.9.12 lib/site_hook/loggers/git.rb
site_hook-0.9.11 lib/site_hook/loggers/git.rb
site_hook-0.9.10 lib/site_hook/loggers/git.rb
site_hook-0.9.9 lib/site_hook/loggers/git.rb