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

Suppressing redundant logging #1592

Closed
azw413 opened this issue Mar 26, 2021 · 3 comments
Closed

Suppressing redundant logging #1592

azw413 opened this issue Mar 26, 2021 · 3 comments

Comments

@azw413
Copy link

azw413 commented Mar 26, 2021

Rocket is mostly amazing but there's a lot of redundant logging coming out which can't be suppressed. Documentation suggests that setting config.log_level(LoggingLevel::Off) should disable internal logging but it doesn't. Here's an example :-

2021-03-26 15:48:52 [INFO] [rocket::rocket] GET /api/roid/list/5305 text/xml:
2021-03-26 15:48:52 [INFO] [_] Matched: GET /api/roid/list/<sector_id> (api_roid_list)
2021-03-26 15:48:52 [INFO] [vo_server] 209.240.117.223:54991 -> /api/roid/list/5305: Azek I-12 - 240 asteroids.
2021-03-26 15:48:52 [INFO] [_] Outcome: Success
2021-03-26 15:48:52 [INFO] [_] Response succeeded.
2021-03-26 15:49:11 [INFO] [rocket::rocket] HEAD / text/html:
2021-03-26 15:49:11 [ERROR] [_] No matching routes for HEAD / text/html.
2021-03-26 15:49:11 [INFO] [_] Autohandling HEAD request.
2021-03-26 15:49:11 [INFO] [_] Matched: GET / [10]
2021-03-26 15:49:11 [INFO] [_] Outcome: Success
2021-03-26 15:49:11 [INFO] [_] Response succeeded.

Note all of the output when all I want is the vo_server output. Here's my initialisation :-

// Setup logging
   fern::Dispatch::new()
      .format(|out, message, record| {
         out.finish(format_args!(
            "{} [{}] [{}] {}",
            chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
            record.level(),
            record.target(),
            message
         ))
      })
      .level(log::LevelFilter::Info)
      .chain(std::io::stdout())
      .chain(fern::log_file("vo-server.log").unwrap())
      .apply().expect("Can't initialise logging");

   load_sectors().expect("Can't read sectors database");

   let mut config = Config::build(Environment::Production)
      .address("0.0.0.0")
      .port(3000)
      .log_level(LoggingLevel::Off)
      .finalize();
   rocket::custom(config.unwrap())
      .mount("/", routes![api_stats, api_roid_list, api_roid_query, api_roid_add, api_roid_table])
      .mount("/", StaticFiles::from("html"))
      .launch();
@SergioBenitez
Copy link
Member

SergioBenitez commented Apr 4, 2021

Rocket is mostly amazing but there's a lot of redundant logging coming out which can't be suppressed.

None of the log output is redundant, though it may be more information than you'd like.

Documentation suggests that setting config.log_level(LoggingLevel::Off) should disable internal logging but it doesn't.

But it does! You are, however, reenabling it when you install your own logger, redirecting Rocket's log output to yours. At that point, it's your responsibility to filter out log messages you don't want to see in whichever way you deem.

Everything is working as expected here. See also #21 and #1410 for impending logging improvements.

@iot-resister
Copy link

With fern

    fern::Dispatch::new()
        .filter(|metadata| !metadata.target().starts_with("rocket"))

@mgumbley-resilient
Copy link

mgumbley-resilient commented Dec 23, 2022

Hi, we're using log4rs, and have installed a filter to prevent certain lines going to the log - which works well for most things (e.g. certain lines rusoto emits that we don't want logged), but not records with a target of "rocket::server" (as they appear in the log). The filter receives these with a target of "", I think this is due to the indentation system of rocket's log.rs. If I filter out records with a target of "", they do get filtered out... but then so do other lines. I found I had to filter out records using the module_path, not the target.
e.g.

    if record.module_path() == Some("rocket::server") && record.level() == Level::Info {
        return Response::Reject;
    }
    return Response::Neutral;

(Using rocket v0.5.0-rc.1)

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