Sha256: 00ff1cf70355f414c6975d9b50f12c8e5768eb6b6b52f645e69983aab3a341aa

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 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 log_trace trace
      alias log_debug debug
      alias log_info  info
      alias log_warn  warn
      alias log_error error

      alias fmt       sprintf

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

        if logger = c.logger
          return unless logger.respond_to?(level)

          if args.length > 0
            logger.send level, sprintf("[SKYLIGHT] [#{Skylight::VERSION}] #{msg}", *args)
          else
            logger.send level, "[SKYLIGHT] [#{Skylight::VERSION}] #{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

20 entries across 20 versions & 1 rubygems

Version Path
skylight-0.3.21 lib/skylight/util/logging.rb
skylight-0.3.20 lib/skylight/util/logging.rb
skylight-0.3.19 lib/skylight/util/logging.rb
skylight-0.3.18 lib/skylight/util/logging.rb
skylight-0.3.17 lib/skylight/util/logging.rb
skylight-0.3.14 lib/skylight/util/logging.rb
skylight-0.3.13 lib/skylight/util/logging.rb
skylight-0.3.12 lib/skylight/util/logging.rb
skylight-0.3.11 lib/skylight/util/logging.rb
skylight-0.3.10 lib/skylight/util/logging.rb
skylight-0.3.8 lib/skylight/util/logging.rb
skylight-0.3.7 lib/skylight/util/logging.rb
skylight-0.3.6 lib/skylight/util/logging.rb
skylight-0.3.3 lib/skylight/util/logging.rb
skylight-0.3.2 lib/skylight/util/logging.rb
skylight-0.3.1 lib/skylight/util/logging.rb
skylight-0.3.0 lib/skylight/util/logging.rb
skylight-0.3.0.rc.6 lib/skylight/util/logging.rb
skylight-0.3.0.rc.5 lib/skylight/util/logging.rb
skylight-0.3.0.rc.4 lib/skylight/util/logging.rb