lib/berkeley_library/logging/loggers.rb in berkeley_library-logging-0.2.6.1 vs lib/berkeley_library/logging/loggers.rb in berkeley_library-logging-0.2.6.2

- old
+ new

@@ -7,17 +7,11 @@ module Loggers class << self FALLBACK_LOG_DIR = 'log'.freeze def default_logger - if defined?(Rails) - return Rails.logger if Rails.logger - - warn('Rails is defined, but Rails logger is nil') - end - - new_default_logger + rails_logger || new_default_logger end # TODO: support passing a hash / passing default_log_file def new_default_logger(config = nil) return new_readable_logger($stdout) unless config @@ -36,10 +30,17 @@ new_logger_with(logdev: logdev, formatter: Formatters.new_readable_formatter) end private + def rails_logger + return unless defined?(Rails) + return unless Rails.respond_to?(:logger) + + Rails.logger + end + def new_broadcast_logger(config) new_json_logger($stdout).tap do |json_logger| file_logger = rails_file_logger(config) json_logger.extend Ougai::Logger.broadcast(file_logger) end @@ -66,10 +67,10 @@ raise ArgumentError, "Not a directory: #{log_dir}" unless File.directory?(log_dir) end end def workdir - return Rails.application.root if defined?(Rails) + return Rails.application.root if defined?(Rails) && Rails.respond_to?(:application) Pathname.getwd end end