New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom logger #1472

Open
IvanDelsinne opened this Issue Aug 28, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@IvanDelsinne

IvanDelsinne commented Aug 28, 2018

I've been trying to set up a custom logger to hide some sensitive informations from the WEBrick auto-logging.

My code is the following:

# service/log.rb
require 'rack'

module Service
    class RackLogger < Rack::CommonLogger
        def call(env)
            puts env["PATH_INFO"].inspect
            #super
            @app.call env
        end
    end
end

disable :logging
use Service::RackLogger

And my application (entrypoint) code is the following:

# Require the necessary libraries.
require 'rubygems'
require 'rack'
require 'sinatra'
require 'sinatra/json'

configure do
  root = File.expand_path(File.dirname(__FILE__))
  set :logging, false #both false and nil provokes this behaviour
end

not_found do
  status 404
  json ({ error: "Not found" })
end

# Load the services.
Dir["app/services/*.rb"].each { |file| load file }
# Load the controllers.
Dir["app/controllers/*.rb"].each { |file| load file }

After this code, if run, I still get the usual logging alongside my own inspect puts call:

::1 - - [28/Aug/2018:21:46:15 +0200] "GET /album/... HTTP/1.1" 200 2205 0.8188

My question is: How to either disable the logging completely or change the logger class ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment