add logging

This commit is contained in:
anna 2022-12-05 20:16:56 +01:00
parent cffde9c0a5
commit e69cfa1f14
Signed by: fef
GPG key ID: EC22E476DC2D3D84
3 changed files with 56 additions and 0 deletions

51
Cargo.lock generated
View file

@ -240,6 +240,17 @@ dependencies = [
"num-traits",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -550,6 +561,19 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "env_logger"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "event-listener"
version = "2.5.3"
@ -756,6 +780,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humantime"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f"
dependencies = [
"quick-error",
]
[[package]]
name = "iana-time-zone"
version = "0.1.53"
@ -994,6 +1027,8 @@ dependencies = [
"actix-web",
"chrono",
"dotenvy",
"log",
"pretty_env_logger",
"serde",
"serde_json",
"sqlx",
@ -1084,6 +1119,16 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "pretty_env_logger"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d"
dependencies = [
"env_logger",
"log",
]
[[package]]
name = "proc-macro2"
version = "1.0.47"
@ -1093,6 +1138,12 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "quick-error"
version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "1.0.21"

View file

@ -7,6 +7,8 @@ edition = "2021"
actix-web = "4"
chrono = { version = "0.4", features = [ "alloc", "clock", "serde" ] }
dotenvy = "0.15.6"
log = "0.4"
pretty_env_logger = "0.4"
serde = "1.0"
serde_json = "1.0"
sqlx = { version = "0.6", features = [ "chrono", "runtime-actix-rustls", "postgres" ] }

View file

@ -1,4 +1,5 @@
use actix_web::{get, web, App, HttpResponse, HttpServer, Responder};
use log::*;
use sqlx::postgres::PgPoolOptions;
use sqlx::{migrate, query, PgPool, Pool};
@ -12,6 +13,7 @@ use state::AppState;
#[actix_web::main]
async fn main() -> std::io::Result<()> {
dotenvy::dotenv().ok();
pretty_env_logger::init();
let config = Config::from_env();
let db_pool = init_db(&config).await.unwrap();
@ -34,6 +36,7 @@ async fn init_db(conf: &Config) -> sqlx::Result<PgPool> {
.connect(&conf.database_url)
.await?;
info!("Running migrations");
migrate!().run(&pool).await?;
Ok(pool)