Search code examples
ruby-on-railsloggingrubygemsselect-n-plus-1

Custom logger for rails prosopite gem


How to configure prosopite gem in rails for custom logger file. I need to separate file for specs and API scan details. for example: prosopite_api.log file for API scan details. prosopite_specs.log file for Specs scan details.

In the readme file they have provided a way, by passing a custom logger class to prosopite.custom_logger, but I do not want to create this custom class and also don't have a need for the separate custom logger class, What I need is just a separate logger file for specs.


Solution

  • We can just pass a new instance of the existing logger class with the file name we want. for example:

    Prosopite.custom_logger = Logger.new('log/custom_file_name.log')
    

    This way I didn't have to create a new custom logger class and configured a separate file for specs(By adding this in test.rb).

    development.rb:

      config.after_initialize do
        Prosopite.prosopite_logger = true
        Prosopite.custom_logger = Rails.logger
      end
    

    test.rb

      config.after_initialize do
        Prosopite.custom_logger = Logger.new('log/prosopite_specs.log')
      end