lib/flowcommerce_spree.rb in flowcommerce_spree-0.0.2 vs lib/flowcommerce_spree.rb in flowcommerce_spree-0.0.3
- old
+ new
@@ -7,10 +7,11 @@
require 'flowcommerce_spree/logging_http_client'
require 'flowcommerce_spree/logging_http_handler'
require 'flowcommerce_spree/webhook_service'
require 'flowcommerce_spree/session'
require 'flow/simple_gateway'
+require 'request_store'
module FlowcommerceSpree
def self.client(logger: FlowcommerceSpree.logger, **opts)
FlowCommerce.instance(http_handler: LoggingHttpHandler.new(logger: logger), **opts)
end
@@ -18,14 +19,23 @@
def self.configure
yield self if block_given?
end
def self.logger
- logger = ActiveSupport::Logger.new(STDOUT, 3, 10_485_760)
+ logger = ActiveSupport::Logger.new(STDOUT)
+ logger_formatter = proc do |severity, datetime, _progname, msg|
+ "\n#{datetime}, #{severity}: #{msg}\n"
+ end
+
+ logger.formatter = logger_formatter
+
# Broadcast the log into the file besides STDOUT, if `log` folder exists
if Dir.exist?('log')
- logger.extend(ActiveSupport::Logger.broadcast(ActiveSupport::Logger.new('log/flowcommerce_spree.log')))
+ file_logger = ActiveSupport::Logger.new('log/flowcommerce_spree.log', 3, 10_485_760)
+ file_logger.formatter = logger_formatter
+
+ logger.extend(ActiveSupport::Logger.broadcast(file_logger))
end
logger
end
end