Sha256: b1c495eab1578e73ffdcdbef21c6654cf38a560c4f450b6914a945f1e149c92d

Contents?: true

Size: 1.01 KB

Versions: 44

Compression:

Stored size: 1.01 KB

Contents

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

module Wovnrb
  class WovnLogger
    include Singleton

    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|
        unless logger.respond_to? method
          raise 'not suite for logger'
        end
      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

44 entries across 44 versions & 1 rubygems

Version Path
wovnrb-1.1.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.13 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.12 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.11 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.10 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.9 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.8 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.7 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.6 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.5 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.4 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.2 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-1.0.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-0.2.30 lib/wovnrb/services/wovn_logger.rb
wovnrb-0.2.29 lib/wovnrb/services/wovn_logger.rb
wovnrb-0.2.28 lib/wovnrb/services/wovn_logger.rb
wovnrb-0.2.27 lib/wovnrb/services/wovn_logger.rb
wovnrb-0.2.26 lib/wovnrb/services/wovn_logger.rb
wovnrb-0.2.25 lib/wovnrb/services/wovn_logger.rb