Sha256: 117d11b3a4b7af40e03ab4016a81e94435dc9f41c7708a1a050224264f2c7d66

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

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

module Wovnrb
  class WovnLogger
    attr_reader :uuid

    include Singleton

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

      def uuid
        instance.uuid
      end
    end

    def initialize
      @uuid = SecureRandom.uuid
      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 "[#{@uuid}] Wovnrb Error: #{message}"
      else
        @logger.error "[#{@uuid}] #{message}"
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
wovnrb-3.11.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.11.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.10.3 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.10.2 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.10.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.10.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.9.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.8.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.7.2 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.7.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.6.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.5.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.4.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.4.0 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.3.1 lib/wovnrb/services/wovn_logger.rb
wovnrb-3.2.0 lib/wovnrb/services/wovn_logger.rb