Skip to content
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

Prevent logging access to a route #1582

Closed
scalp42 opened this issue Dec 17, 2019 · 7 comments
Closed

Prevent logging access to a route #1582

scalp42 opened this issue Dec 17, 2019 · 7 comments

Comments

@scalp42
Copy link

scalp42 commented Dec 17, 2019

Hi folks,

We have a simple route `/ping and we'd like to prevent logging access to it.

What is the recommended way to do that?

Thank you in advance

@jkowens
Copy link
Member

jkowens commented Dec 20, 2019

I haven't tested this but take a look at silencer. Depending on how you configure your app, Rack may be adding logging middleware.

See: https://stackoverflow.com/questions/30471322/disable-sinatra-standard-output

If you make sure CommonLogger is disabled, and then use Silencer I think you might be good.

@scalp42
Copy link
Author

scalp42 commented Dec 20, 2019

I think the challenge is to be able to suppress the access logs per route instead of globally.

@jkowens
Copy link
Member

jkowens commented Dec 21, 2019

Per the Silencer readme:

Silencer is a simple rack-middleware for Rails that can selectively disable logging on per-action basis. It's based on a blog post by Dennis Reimann.

Being Rack middleware, I think it should work with SInatra as well.

This is a Rack example from the readme:

require 'silencer/logger'

use Silencer::Logger, :silence => ["/noisy/action.json"]

@jkowens
Copy link
Member

jkowens commented Dec 21, 2019

Hm, so that very well might not work for you. You might reach a bigger audience for this question on StackOverflow. I'm guessing someone has come across this before.

@jkowens
Copy link
Member

jkowens commented Mar 18, 2020

@scalp42 we've just merged in a new feature to master. I think you might be able to use this to prevent logging to your ping route. Can you check and let me know if this will work?

https://github.com/sinatra/sinatra/blob/master/sinatra-contrib/lib/sinatra/quiet_logger.rb

See also: #1250

@scalp42
Copy link
Author

scalp42 commented Mar 20, 2020

Awesome @jkowens! thanks a lot, I'll give it a try by hopefully end of month but I'm assuming we should be able to close this issue now.

Thanks again.

@scalp42 scalp42 closed this as completed Mar 20, 2020
@scalp42
Copy link
Author

scalp42 commented Sep 4, 2020

@jkowens any idea how to use it when not using a modular app?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants