Skip to content

Commit 420a779

Browse files
committed
fix: logging with fern
1 parent a139c15 commit 420a779

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

atcoder-problems-backend/src/bin/run_server.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use atcoder_problems_backend::utils::init_log_config;
66

77
#[actix_web::main]
88
async fn main() {
9+
// std::env::set_var("RUST_LOG", "actix_web=info");
910
init_log_config().unwrap();
1011
let database_url = env::var("SQL_URL").expect("SQL_URL is not set.");
1112
let port = 8080;

atcoder-problems-backend/src/server/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) mod virtual_contest;
1515
use actix_web::{http::header, web, App, HttpResponse, HttpServer};
1616
pub use auth::{Authentication, GitHubAuthentication, GitHubUserResponse};
1717

18-
const LOG_TEMPLATE: &str = "{method:%{Method}i, url:%U, status:%s, duration:%T}";
18+
const LOG_TEMPLATE: &str = r#"{"method":"%{method}xi", "url":"%U", "status":%s, "duration":%T}"#;
1919

2020
pub async fn run_server<A>(
2121
pg_pool: sql_client::PgPool,
@@ -30,7 +30,7 @@ where
3030
HttpServer::new(move || {
3131
App::new()
3232
.app_data(web::Data::new(app_data.clone()))
33-
.wrap(actix_web::middleware::Logger::new(LOG_TEMPLATE))
33+
.wrap(actix_web::middleware::Logger::new(LOG_TEMPLATE).custom_request_replace("method", |req| req.method().to_string()))
3434
.configure(services::config_services::<A>)
3535
})
3636
.bind((host, port))?

atcoder-problems-backend/src/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn init_log_config() -> Result<()> {
2828
.format(|out, message, _record| out.finish(format_args!("{}", message)))
2929
.level(LevelFilter::Info)
3030
.level_for("sqlx", LevelFilter::Warn)
31-
.level_for("tide", LevelFilter::Warn)
31+
.level_for("actix_web", LevelFilter::Warn)
3232
.level_for("reqwest", LevelFilter::Warn)
3333
.chain(std::io::stdout())
3434
.apply()?;

0 commit comments

Comments
 (0)