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

Logger Middleware - Allow certain endpoints to be excluded from logging #211

Closed
glademiller opened this issue May 7, 2018 · 10 comments
Closed

Comments

@glademiller
Copy link
Contributor

Constant health checks create a lot of clutter in logs. I would love a simple way to remove certain endpoints from the default Logger middleware.

Thoughts on how this could be done:

  • Logger Takes a list of endpoints to not log.
  • Logger takes a closure or something implementing a trait that allows it to filter logs.
  • I simply filter the log at the logger level instead of in the middleware.
@fafhrd91
Copy link
Member

fafhrd91 commented May 7, 2018

lets implement first option, as it is simplest. we can implement second option later if anyone would need it.

would you provide PR?

@fafhrd91
Copy link
Member

fafhrd91 commented May 8, 2018

added Logger::exclude

@fafhrd91 fafhrd91 closed this as completed May 8, 2018
@glademiller
Copy link
Contributor Author

Thanks for getting this done I just got a bit of time freed up and was going to look into it but you beat me to it. Thank you!

@neilyoung
Copy link

Sorry for bringing up this again. I would like to stop actix from logging at all. I'm using log and simplelog and if my application log level goes up to trace, actix really heavily logs and I currently don't know, how to stop that. I admit, it is possible, that I didn't understand it all :)

22:27:20 [TRACE] (9) actix_server::worker: [/Users/decades/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/actix-server-1.0.4/src/worker.rs:263] Service "actix-web-service-0.0.0.0:5000" is available
22:27:20 [TRACE] (6) actix_web::middleware::logger: [/Users/decades/.cargo/registry/src/jackfan.us.kg-1ecc6299db9ec823/actix-web-3.1.0/src/middleware/logger.rs:314] Access log format: %a "%r" %s %b "%{Referer}i" "%{Use

@robjtede
Copy link
Member

@neilyoung I don't know if simplelogger has the ability to filter out specific logs. With env_logger, for example, you can say RUST_LOG=info,my_crate=trace cargo run to only show trace logs from your own project.

@neilyoung
Copy link

Hi @robjtede and thanks for the super quick reply. Yes, I have seen the env configuration to configure env_logger, but those don't apply. So I have to continue searching. I tried to

.wrap(Logger::new(""))

This was accepted, but in the end it just created empty "INFO" traces, whenever something happened on the network :)

@robjtede
Copy link
Member

The logger middleware is specifically for logging request statuses as you might see in nginx or apache logs, for instance. So if you don't want these logs simply omit the .wrap(Logger) call.

If I've misunderstood @ me in the Gitter chat and we can continue there.

@neilyoung
Copy link

Basically I added it, because I wanted to stop logging. It also traces (if app level is trace) independently of whether I issue the wrap call or not. This was just an attempt.

Unfortunately I can't use env_logger, which seems to not be able to log to file. Maybe I drop simplelog too in favour of log4j.
Thank you for your offer, but it is rather late over here, I will stop for today 👍

@neilyoung
Copy link

I switched to log4rs. Problem solved.

@neilyoung
Copy link

OK, it works, but it is very cumbersome to stop all parts of actix-web from jabbering. And there is a daily update to this list, because new loggers are popping up. Any idea how to stop that generally?

Currently it looks like so: I'm switching all components I know off back to Error level. These are the currently discovered:

            .logger(Logger::builder().build("mio::poll", LevelFilter::Error))
            .logger(Logger::builder().build("mio::sys", LevelFilter::Error))
            .logger(Logger::builder().build("actix_web::middleware::logger", LevelFilter::Error))
            .logger(Logger::builder().build("actix_server::worker", LevelFilter::Error))
            .logger(Logger::builder().build("actix_server::builder", LevelFilter::Error))
            .logger(Logger::builder().build("actix_http::h1::decoder", LevelFilter::Error))
            .logger(Logger::builder().build("actix_http::h1::dispatcher", LevelFilter::Error))

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

4 participants