davydovanton / kan

Simple, functional authorization library and role management for ruby
http://www.kanrb.org
MIT License
232 stars 12 forks source link

Add logger support #5

Closed davydovanton closed 6 years ago

valikos commented 6 years ago

@davydovanton do you have any ideas how logger should works and which kind of activity to log?

davydovanton commented 6 years ago

I think it will be cool to just allow logger getter in ability blocks. Something like:

class Post::Abilities
  include Kan::Abilities

  register 'read' do |user, _|
    logger # => logger instance
    logger.info 'Something happened'
    true
  end
end

And initialization:

admin_abilities = Kan::Application.new(
  posts: Post::AdminAbilities.new(logger: MyLoggerClass.new),
  comments: Comment::AdminAbilities.new, # => will use default STDOUT logger instance
)
valikos commented 6 years ago

@davydovanton could you please check https://github.com/davydovanton/kan/pull/7? Is this correct for you? I think there will be good to have some global Kan::Application::Logger that can be configured by configuration. What do you think about this?