Sha256: 63e608ae32e58aa3b3d7ec145b2f6fa7a30d4d5fb5a7a320cedb77d3abe212f1

Contents?: true

Size: 1.39 KB

Versions: 2

Compression:

Stored size: 1.39 KB

Contents

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'logger'

module Reality
  module Logging
    class << self
      # noinspection RubyDynamicConstAssignment
      def configure(module_type, stream = STDOUT)
        logger = ::Logger.new(stream)
        logger.level = ::Logger::INFO
        logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" }

        module_type.const_set(:Logger, logger)
        module_type.instance_eval do
          def self.debug(message)
            self.const_get(:Logger).debug(message)
          end

          def self.info(message)
            self.const_get(:Logger).info(message)
          end

          def self.warn(message)
            self.const_get(:Logger).warn(message)
          end

          def self.error(message)
            self.const_get(:Logger).error(message)
            raise message
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
reality-core-1.1.0 lib/reality/logging.rb
reality-core-1.0.0 lib/reality/logging.rb