ankane / logstop

Keep personal data out of your logs
MIT License
240 stars 13 forks source link

Compatibility with non-rails loggers #15

Closed skatkov closed 2 years ago

skatkov commented 2 years ago

This looks like an awesome project and interesting approach to data obfuscation in logs. Thank you for sharing it publically!

I tried it out in a non-rails environment (sinatra) and was unable to use it. I've ran into following errors:

NoMethodError: undefined method `info' for #<Logger::Formatter:0x000000013b3cec18 @datetime_format=nil>
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/logstop-0.2.8/lib/logstop/formatter.rb:31:in `method_missing'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/features/logging.rb:33:in `wrap_request'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/client.rb:107:in `block in wrap_request'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/client.rb:106:in `each'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/client.rb:106:in `inject'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/client.rb:106:in `wrap_request'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/client.rb:55:in `build_request'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/client.rb:30:in `request'
    /Users/skatkov/.rvm/gems/ruby-2.7.6/gems/http-5.1.0/lib/http/chainable.rb:20:in `get'
    /Users/skatkov/Code/middleware/lib/studio/client.rb:14:in `block in get'

I used it with standard ruby Logger class, that doesn't have a formatter class.

logger = Logger.new STDOUT
logger.formatter # => nil

But also tried Ougai logger, that has formatter class. But doesn't define info and error classes in formatter, yeat, it's defined in a Ougai::Logger class instead.

logger = Ougai::Logger.new STDOUT
logger.formatter.class # => Ougai::Formatters::Bunyan
l.formatter.methods.include?(:info) # => false
l.methods.include?(:info) # => true

Would you be interested in improving compatibility with non-rails loggers? I'm considering forking this and trying to get it to work with Ougai, but not sure if you want me to bring these changes to original repo.

skatkov commented 2 years ago

I figured out where I was wrong ;-) closing