Ultra simple gem that contains module that you can include to any class to log all method calls to standard output or/and file.
Add this line to your application's Gemfile:
gem 'method_logger'
And then execute:
$ bundle
Or install it yourself as:
$ gem install method_logger
Include mixin at the end of your class like this:
include MethodLogger::mixin({})
You can customize it by passing options to mixin in hash:
{
include_inherited: true, # determines if should include inherited methods
ignored_methods: [], # [Array of symbols] used to ignore methods that we don't need to see
logger: Logger.new(File.open(options[:filename], 'a+')), # if you don't like basic ruby logger, you can pass your own. It
must respond to #info
formatter: DefaultFormatter.new, # this is used for formatting. You can pass any object that responds to #call method
filename: 'method_logger_log.txt', # filename to put logs in default logger
log_to_file: false ,# determines if it should log to file
log_to_stdout: true # determines if it should log to standard output
}
Simple example output for active record model with just 1 field in fresh project :
class Project < ApplicationRecord
include MethodLogger::mixin({ log_to_file: true, filename: 'example.output' })
end
Bug reports and pull requests are welcome on GitHub at https://github.com/bbonislawski/method_logger.
The gem is available as open source under the terms of the MIT License.