Sha256: 60d767a54b0d64c9d6e37efd6af0bfa8971d5218418d82796841be18934230f0

Contents?: true

Size: 1.08 KB

Versions: 18

Compression:

Stored size: 1.08 KB

Contents

require 'singleton'
require 'logger' unless defined?(Logger)

module Wovnrb
  class WovnLogger
    include Singleton

    class << self
      def error(message)
        instance.error(message)
      end
    end

    def initialize
      path = Store.instance.settings['log_path']
      if path
        begin
          @logger = Logger.new(path)
        rescue
          begin
            @logger = Logger.new('wovn_error.log')
            @logger.error("Wovn Error: log_path(#{path}) is invalid, please change log_path at config")
          rescue
            @logger = $stderr
            $stderr.puts("Wovn Error: log_path(#{path}) is invalid, please change log_path at config")
          end
        end
      else
        @logger = $stderr
      end
    end

    def set_logger(logger)
      [:error].each do |method|
        raise 'not suite for logger' unless logger.respond_to? method
      end

      @logger = logger
    end

    def error(message)
      if @logger == $stderr
        @logger.puts "Wovnrb Error: #{message}"
      else
        @logger.error message
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
wovnrb-3.1.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.0.3 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.0.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.0.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.6.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.5.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.2.4 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.2.3 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.2.2 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.2.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.2.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.1.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.0.5 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.0.4 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.0.3 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.0.2 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.0.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-2.0.0 lib/wovnrb/services/wovn_logger.rb