Swap out old log
for shiny tracing
This commit is contained in:
parent
fb99afdc26
commit
b16ba3e3f7
404
Cargo.lock
generated
404
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -13,8 +13,6 @@ dotenv = "0.15"
|
|||||||
http-api-problem = { version = "0.17", features = ["with-warp"] }
|
http-api-problem = { version = "0.17", features = ["with-warp"] }
|
||||||
hyper = "0.13"
|
hyper = "0.13"
|
||||||
listenfd = "0.3"
|
listenfd = "0.3"
|
||||||
log = "0.4"
|
|
||||||
pretty_env_logger = "0.4"
|
|
||||||
tokio = { version = "0.2", features = ["macros"] }
|
tokio = { version = "0.2", features = ["macros"] }
|
||||||
sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "postgres", "chrono", "uuid", "ipnetwork", "json" ] }
|
sqlx = { version = "0.3", default-features = false, features = [ "runtime-tokio", "macros", "postgres", "chrono", "uuid", "ipnetwork", "json" ] }
|
||||||
warp = { version = "0.2", features = ["compression"] }
|
warp = { version = "0.2", features = ["compression"] }
|
||||||
@ -27,3 +25,5 @@ uuid = { version = "0.8", features = ["serde", "v4"] }
|
|||||||
ipnetwork = "0.16"
|
ipnetwork = "0.16"
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
async-trait = "0.1"
|
async-trait = "0.1"
|
||||||
|
tracing = "0.1"
|
||||||
|
tracing-subscriber = "0.2"
|
||||||
|
@ -30,3 +30,5 @@
|
|||||||
# Todo
|
# Todo
|
||||||
|
|
||||||
* Make self-contained docker container that can run the app without any setup.
|
* Make self-contained docker container that can run the app without any setup.
|
||||||
|
* Add rate-limiting per IP address. The `tower` crate has a service that might
|
||||||
|
be useful for this.
|
||||||
|
17
src/main.rs
17
src/main.rs
@ -1,6 +1,3 @@
|
|||||||
#[macro_use]
|
|
||||||
extern crate log;
|
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Clap;
|
use clap::Clap;
|
||||||
use dotenv::dotenv;
|
use dotenv::dotenv;
|
||||||
@ -10,6 +7,8 @@ use serde::Serialize;
|
|||||||
use sqlx::postgres::PgPool;
|
use sqlx::postgres::PgPool;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
use tracing::info;
|
||||||
|
use tracing_subscriber::fmt::format::FmtSpan;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use warp::Filter;
|
use warp::Filter;
|
||||||
|
|
||||||
@ -53,10 +52,12 @@ struct ErrorMessage {
|
|||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
dotenv().ok();
|
dotenv().ok();
|
||||||
if env::var_os("RUST_LOG").is_none() {
|
let env_log_filter =
|
||||||
env::set_var("RUST_LOG", "shopkeeper=info");
|
env::var("RUST_LOG").unwrap_or_else(|_| "warp=info,shopkeeper=info".to_owned());
|
||||||
}
|
tracing_subscriber::fmt()
|
||||||
pretty_env_logger::init();
|
.with_env_filter(env_log_filter)
|
||||||
|
.with_span_events(FmtSpan::CLOSE)
|
||||||
|
.init();
|
||||||
let opts: Opts = Opts::parse();
|
let opts: Opts = Opts::parse();
|
||||||
|
|
||||||
if opts.migrate {
|
if opts.migrate {
|
||||||
@ -96,7 +97,7 @@ async fn main() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.recover(problem::unpack_problem)
|
.recover(problem::unpack_problem)
|
||||||
.with(warp::compression::gzip())
|
.with(warp::compression::gzip())
|
||||||
.with(warp::log("shopkeeper"));
|
.with(warp::trace::request());
|
||||||
|
|
||||||
let svc = warp::service(routes);
|
let svc = warp::service(routes);
|
||||||
let make_svc = hyper::service::make_service_fn(|_: _| {
|
let make_svc = hyper::service::make_service_fn(|_: _| {
|
||||||
|
@ -4,6 +4,7 @@ use chrono::prelude::*;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::postgres::PgPool;
|
use sqlx::postgres::PgPool;
|
||||||
use sqlx::types::Json;
|
use sqlx::types::Json;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
use super::ListParams;
|
use super::ListParams;
|
||||||
use super::Model;
|
use super::Model;
|
||||||
|
@ -4,6 +4,7 @@ use chrono::prelude::*;
|
|||||||
use ipnetwork::IpNetwork;
|
use ipnetwork::IpNetwork;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::postgres::PgPool;
|
use sqlx::postgres::PgPool;
|
||||||
|
use tracing::debug;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use super::ListParams;
|
use super::ListParams;
|
||||||
|
@ -3,6 +3,7 @@ use async_trait::async_trait;
|
|||||||
use chrono::prelude::*;
|
use chrono::prelude::*;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use sqlx::postgres::PgPool;
|
use sqlx::postgres::PgPool;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
use super::ListParams;
|
use super::ListParams;
|
||||||
use super::Model;
|
use super::Model;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use http_api_problem::HttpApiProblem;
|
use http_api_problem::HttpApiProblem;
|
||||||
|
use tracing::error;
|
||||||
use warp::http::StatusCode;
|
use warp::http::StatusCode;
|
||||||
use warp::{reject, Rejection, Reply};
|
use warp::{reject, Rejection, Reply};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user