require 'active_support/core_ext' module EventBus def self.set_up_logging base_logdir = ENV['EVENTBUS_LOGDIR'] if base_logdir.nil? base_logdir = File.join(ENV['HOME'], "logs", self.PROD_LEVEL, "eventbus", self.application_id) end FileUtils.mkdir_p(base_logdir) unless File.directory?(base_logdir) filename = [File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)), ".log"].join logfile_path = File.join(base_logdir, filename) shift_age = ENV['EVENTBUS_LOG_SHIFT_AGE'] || "daily" shift_size = ENV['EVENTBUS_LOG_SHIFT_SIZE'] || 20971520 # 20MB puts "Logging to #{logfile_path}." self.logger = Logger.new(logfile_path, shift_age, shift_size) logger.info "Logging initialized. Rotation age: #{shift_age} Rotation size: #{shift_size}" end # CONSTANTS # True Constants mattr_accessor :CORE_APPLICATION_ID mattr_accessor :DEFAULT_APPLICATION_ID mattr_accessor :DEFAULT_PROD_LEVEL self.CORE_APPLICATION_ID = "EVENTBUS_CORE" self.DEFAULT_APPLICATION_ID = self.CORE_APPLICATION_ID self.DEFAULT_PROD_LEVEL = "development" # Calculated Constants mattr_accessor :PROD_LEVEL self.PROD_LEVEL = ENV['EVENTBUS_PROD_LEVEL'] || self.DEFAULT_PROD_LEVEL # VARIABLES mattr_accessor :application_id self.application_id = ENV['EVENTBUS_APPLICATION_ID'] || self.DEFAULT_APPLICATION_ID mattr_accessor :logger self.set_up_logging end