lib/kafkr.rb in kafkr-0.018.1 vs lib/kafkr.rb in kafkr-0.21.0
- old
+ new
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-
+require "pry"
require "logger"
require "openssl"
require "securerandom"
require "ostruct"
require "gibberish"
@@ -13,68 +13,25 @@
require_relative "kafkr/producer"
require_relative "kafkr/version"
module Kafkr
class << self
- attr_accessor :current_environment
def logger
@logger ||= configure_logger
end
- def configure_logger(output = default_output)
+ def configure_logger(output = STDOUT)
begin
@logger = ::Logger.new(output)
rescue Errno::EACCES, Errno::ENOENT => e
@logger = ::Logger.new(STDOUT)
@logger.error("Could not open log file: #{e.message}")
end
- set_logger_level
+ @logger.level = ::Logger::DEBUG
@logger
end
- def default_output
- case current_environment
- when "production"
- "/var/log/kafkr.log"
- else
- STDOUT
- end
- end
-
- def set_logger_level
- @logger.level = case current_environment
- when "development"
- ::Logger::DEBUG
- when "staging"
- ::Logger::INFO
- when "production"
- ::Logger::WARN
- else
- ::Logger::DEBUG
- end
- end
-
- def current_environment
- @current_environment ||= ENV["KAFKR_ENV"] || "development"
- end
-
- def development?
- current_environment == "development"
- end
-
- def test?
- current_environment == "test"
- end
-
- def staging?
- current_environment == "staging"
- end
-
- def production?
- current_environment == "production"
- end
-
def write(message, unique_id = nil)
begin
logger.info(message)
rescue IOError => e
@logger.error("Failed to write log: #{e.message}")
@@ -98,5 +55,6 @@
yield(configuration)
rescue => e
logger.error("Configuration error: #{e.message}")
end
end
+