diff --git a/lib/avo.rb b/lib/avo.rb index f154ede155..f81df3b45c 100644 --- a/lib/avo.rb +++ b/lib/avo.rb @@ -49,8 +49,8 @@ class << self delegate :license, :app, :error_manager, :tool_manager, :resource_manager, to: Avo::Current def boot - boot_logger - boot_fields + @logger = Avo.configuration.logger + @field_manager = Avo::Fields::FieldManager.build @cache_store = Avo.configuration.cache_store plugin_manager.boot_plugins Avo.run_load_hooks(:boot, self) @@ -124,25 +124,6 @@ def mount_engines mount Avo::Pro::Engine, at: "/avo-pro" if defined?(Avo::Pro::Engine) } end - - private - - def boot_logger - file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log")) - - file_logger.datetime_format = "%Y-%m-%d %H:%M:%S" - file_logger.formatter = proc do |severity, time, progname, msg| - "[Avo] #{time}: #{msg}\n".tap do |i| - puts i - end - end - - @logger = file_logger - end - - def boot_fields - @field_manager = Avo::Fields::FieldManager.build - end end end diff --git a/lib/avo/configuration.rb b/lib/avo/configuration.rb index 3584b289c0..4a9d882eee 100644 --- a/lib/avo/configuration.rb +++ b/lib/avo/configuration.rb @@ -6,6 +6,7 @@ class Configuration attr_writer :branding attr_writer :root_path attr_writer :cache_store + attr_writer :logger attr_accessor :timezone attr_accessor :per_page attr_accessor :per_page_steps @@ -97,6 +98,7 @@ def initialize @resource_parent_controller = "Avo::ResourcesController" @mount_avo_engines = true @cache_store = computed_cache_store + @logger = default_logger end def current_user_method(&block) @@ -193,6 +195,25 @@ def computed_cache_store end } end + + def logger + Avo::ExecutionContext.new(target: @logger).handle + end + + def default_logger + -> { + file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log")) + + file_logger.datetime_format = "%Y-%m-%d %H:%M:%S" + file_logger.formatter = proc do |severity, time, progname, msg| + "[Avo] #{time}: #{msg}\n".tap do |i| + puts i + end + end + + file_logger + } + end end def self.configuration diff --git a/lib/generators/avo/templates/initializer/avo.tt b/lib/generators/avo/templates/initializer/avo.tt index a36c73e8e8..8b0c18ec55 100644 --- a/lib/generators/avo/templates/initializer/avo.tt +++ b/lib/generators/avo/templates/initializer/avo.tt @@ -64,6 +64,20 @@ Avo.configure do |config| ## provide a lambda to enable or disable cache_resource_filters per user/resource. # config.cache_resource_filters = -> { current_user.cache_resource_filters? } + ## == Logger == + # config.logger = -> { + # file_logger = ActiveSupport::Logger.new(Rails.root.join("log", "avo.log")) + # + # file_logger.datetime_format = "%Y-%m-%d %H:%M:%S" + # file_logger.formatter = proc do |severity, time, progname, msg| + # "[Avo] #{time}: #{msg}\n".tap do |i| + # puts i + # end + # end + # + # file_logger + # } + ## == Customization == # config.app_name = 'Avocadelicious' # config.timezone = 'UTC'