Merge branch '30-add-logging-to-startup-of-backend' into 'main'

Add logging

Closes #30

See merge request libretunes/libretunes!22
This commit is contained in:
Ethan Girouard 2024-05-08 17:56:45 -04:00
commit 9b1ea51896
6 changed files with 114 additions and 2 deletions

View File

@ -8,3 +8,4 @@
!/style
!/Cargo.lock
!/Cargo.toml
!/ascii_art.txt

85
Cargo.lock generated
View File

@ -44,6 +44,21 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.81"
@ -316,6 +331,18 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.37"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e"
dependencies = [
"android-tzdata",
"iana-time-zone",
"num-traits",
"windows-targets 0.52.4",
]
[[package]]
name = "ciborium"
version = "0.2.2"
@ -422,6 +449,12 @@ dependencies = [
"futures",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]]
name = "cpufeatures"
version = "0.2.12"
@ -613,6 +646,18 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "flexi_logger"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f248c29a6d4bc5d065c9e9068d858761a0dcd796759f7801cc14db35db23abd8"
dependencies = [
"chrono",
"glob",
"log",
"thiserror",
]
[[package]]
name = "float-cmp"
version = "0.9.0"
@ -796,6 +841,12 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "gloo-net"
version = "0.5.0"
@ -965,6 +1016,29 @@ dependencies = [
"tokio",
]
[[package]]
name = "iana-time-zone"
version = "0.1.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "icondata"
version = "0.3.0"
@ -1501,6 +1575,7 @@ dependencies = [
"diesel",
"diesel_migrations",
"dotenv",
"flexi_logger",
"futures",
"http",
"icondata",
@ -1510,6 +1585,7 @@ dependencies = [
"leptos_icons",
"leptos_meta",
"leptos_router",
"log",
"openssl",
"pbkdf2",
"serde",
@ -3066,6 +3142,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets 0.52.4",
]
[[package]]
name = "windows-sys"
version = "0.48.0"

View File

@ -36,6 +36,8 @@ tower-sessions = { version = "0.11", default-features = false }
tower-sessions-redis-store = { version = "0.11", optional = true }
async-trait = "0.1.79"
axum-login = { version = "0.14.0", optional = true }
log = { version = "0.4.21", optional = true }
flexi_logger = { version = "0.28.0", optional = true, default-features = false }
[patch.crates-io]
gloo-net = { git = "https://github.com/rustwasm/gloo.git", rev = "a823fab7ecc4068e9a28bd669da5eaf3f0a56380" }
@ -61,6 +63,8 @@ ssr = [
"tower-http",
"tower-sessions-redis-store",
"axum-login",
"log",
"flexi_logger",
]
# Defines a size-optimized profile for the WASM bundle in release mode

View File

@ -32,6 +32,7 @@ COPY style /app/style
# Minify CSS
RUN npx tailwindcss -i /app/style/main.scss -o /app/style/main.scss --minify
COPY ascii_art.txt /app/ascii_art.txt
COPY assets /app/assets
COPY src /app/src
COPY migrations /app/migrations

10
ascii_art.txt Normal file
View File

@ -0,0 +1,10 @@
.-=. =+==-.
.=++++. =+++++=.
_ _ _ _______ =++++++= :*++++++=
| | (_) | |__ __| -++++**+. -+**++++-
| | _| |__ _ __ ___| |_ _ _ __ ___ ___ *+++**+ +**+++*
| | | | '_ \| '__/ _ \ | | | | '_ \ / _ \/ __| *+++**+ +**+++*
| |____| | |_) | | | __/ | |_| | | | | __/\__ \ -++++**+-: +**++++-
|______|_|_.__/|_| \___|_|\__,_|_| |_|\___||___/ =++++++**+ -+++++=
.=+++++++=.+++=.
.-==++++---.

View File

@ -23,13 +23,23 @@ async fn main() {
use tower_sessions_redis_store::{fred::prelude::*, RedisStore};
use axum_login::AuthManagerLayerBuilder;
use libretunes::auth_backend::AuthBackend;
use log::*;
flexi_logger::Logger::try_with_env_or_str("debug").unwrap().format(flexi_logger::opt_format).start().unwrap();
info!("\n{}", include_str!("../ascii_art.txt"));
info!("Starting Leptos server...");
use dotenv::dotenv;
dotenv().ok();
debug!("Running database migrations...");
// Bring the database up to date
libretunes::database::migrate();
debug!("Connecting to Redis...");
let redis_url = std::env::var("REDIS_URL").expect("REDIS_URL must be set");
let redis_config = RedisConfig::from_url(&redis_url).expect(&format!("Unable to parse Redis URL: {}", redis_url));
let redis_pool = RedisPool::new(redis_config, None, None, None, 1).expect("Unable to create Redis pool");
@ -55,9 +65,10 @@ async fn main() {
.fallback(file_and_error_handler)
.with_state(leptos_options);
println!("listening on http://{}", &addr);
let listener = tokio::net::TcpListener::bind(&addr).await.expect(&format!("Could not bind to {}", &addr));
info!("Listening on http://{}", &addr);
axum::serve(listener, app.into_make_service()).await.expect("Server failed");
}