Sha256: e8315f70b878d159f8d12d1035b90379df3a0dd0914e0b89aed07c7ed72009af

Contents?: true

Size: 1.22 KB

Versions: 5

Compression:

Stored size: 1.22 KB

Contents

require 'logger'

module Skylight
  module Util
    module Logging
      if ENV[TRACE_ENV_KEY]
        def trace(msg, *args)
          log :DEBUG, msg, *args
        end

        def t
          log :DEBUG, yield
        end
      else
        def trace(*)
        end

        def t
        end
      end

      def debug(msg, *args)
        log :DEBUG, msg, *args
      end

      def info(msg, *args)
        log :INFO, msg, *args
      end

      def warn(msg, *args)
        log :WARN, msg, *args
      end

      def error(msg, *args)
        log :ERROR, msg, *args
      end

      alias fmt sprintf

      MAP = {
        :DEBUG => Logger::DEBUG,
        :INFO  => Logger::INFO,
        :WARN  => Logger::WARN,
        :ERROR => Logger::ERROR }

      def log(level, msg, *args)
        return unless respond_to?(:config)
        return unless c = config

        if logger = c.logger
          if args.length > 0
            logger.log MAP[level], sprintf("[SKYLIGHT] #{msg}", *args)
          else
            logger.log MAP[level], "[SKYLIGHT] #{msg}"
          end
        end
      rescue Exception => e
        if ENV[TRACE_ENV_KEY]
          puts "[ERROR] #{e.message}"
          puts e.backtrace
        end
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
skylight-0.1.2 lib/skylight/util/logging.rb
skylight-0.1.1 lib/skylight/util/logging.rb
skylight-0.1.0 lib/skylight/util/logging.rb
skylight-0.1.0.alpha2 lib/skylight/util/logging.rb
skylight-0.1.0.alpha1 lib/skylight/util/logging.rb