From 7062c750133e7ffd681968697ef2a54466ee0e5d Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 11 Apr 2024 23:06:04 -0400 Subject: [PATCH 1/5] Add log crate --- Cargo.lock | 1 + Cargo.toml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 90dc998..f3a10bc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1510,6 +1510,7 @@ dependencies = [ "leptos_icons", "leptos_meta", "leptos_router", + "log", "openssl", "pbkdf2", "serde", diff --git a/Cargo.toml b/Cargo.toml index 4677ca9..e1fa462 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ 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 } [patch.crates-io] gloo-net = { git = "https://github.com/rustwasm/gloo.git", rev = "a823fab7ecc4068e9a28bd669da5eaf3f0a56380" } @@ -61,6 +62,7 @@ ssr = [ "tower-http", "tower-sessions-redis-store", "axum-login", + "log", ] # Defines a size-optimized profile for the WASM bundle in release mode From 4f6f3f90c169a97069c48d66940e4516c5a90e89 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 11 Apr 2024 23:14:53 -0400 Subject: [PATCH 2/5] Add flexi_logger crate --- Cargo.lock | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 ++ 2 files changed, 86 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f3a10bc..5b2514e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", @@ -3067,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" diff --git a/Cargo.toml b/Cargo.toml index e1fa462..48f3b78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,7 @@ 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" } @@ -63,6 +64,7 @@ ssr = [ "tower-sessions-redis-store", "axum-login", "log", + "flexi_logger", ] # Defines a size-optimized profile for the WASM bundle in release mode From 557c189a17cdf2df0bfce0629b88d6acfa611d4e Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 11 Apr 2024 23:19:02 -0400 Subject: [PATCH 3/5] Add ASCII art of logo and name --- ascii_art.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ascii_art.txt diff --git a/ascii_art.txt b/ascii_art.txt new file mode 100644 index 0000000..bdd918f --- /dev/null +++ b/ascii_art.txt @@ -0,0 +1,10 @@ + .-=. =+==-. + .=++++. =+++++=. + _ _ _ _______ =++++++= :*++++++= + | | (_) | |__ __| -++++**+. -+**++++- + | | _| |__ _ __ ___| |_ _ _ __ ___ ___ *+++**+ +**+++* + | | | | '_ \| '__/ _ \ | | | | '_ \ / _ \/ __| *+++**+ +**+++* + | |____| | |_) | | | __/ | |_| | | | | __/\__ \ -++++**+-: +**++++- + |______|_|_.__/|_| \___|_|\__,_|_| |_|\___||___/ =++++++**+ -+++++= + .=+++++++=.+++=. + .-==++++---. From 241389e5f7fca172b2da189cc888507afd6753a9 Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 11 Apr 2024 23:19:21 -0400 Subject: [PATCH 4/5] Add logging to main --- src/main.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6f9b667..e647089 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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"); } From b6066e2d3e325bc7d3d6d82d9c4432e6a8a43aed Mon Sep 17 00:00:00 2001 From: Ethan Girouard Date: Thu, 11 Apr 2024 23:42:22 -0400 Subject: [PATCH 5/5] Include ASCII art file in Docker build --- .dockerignore | 1 + Dockerfile | 1 + 2 files changed, 2 insertions(+) diff --git a/.dockerignore b/.dockerignore index 59dfed4..5ab2a05 100644 --- a/.dockerignore +++ b/.dockerignore @@ -8,3 +8,4 @@ !/style !/Cargo.lock !/Cargo.toml +!/ascii_art.txt diff --git a/Dockerfile b/Dockerfile index c02cd2f..a0390e8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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