better logging

This commit is contained in:
2025-03-18 16:09:46 -06:00
parent e3e4175f51
commit de80418c00
10 changed files with 430 additions and 45 deletions

View File

@@ -8,9 +8,9 @@ use std::time::Instant;
use db::{connect, Website};
use s3::S3;
use surrealdb::{engine::remote::ws::Client, Surreal};
use tokio::task::JoinSet;
use tokio::{task::JoinSet};
use tracing::{debug, info, instrument, trace, trace_span, warn};
use tracing_subscriber::{fmt::time::LocalTime, EnvFilter};
use tracing_subscriber::{fmt::{self, time::LocalTime}, layer::{Filter, SubscriberExt}, EnvFilter, Layer, Registry};
mod db;
mod parser;
@@ -33,13 +33,33 @@ struct Config<'a> {
async fn main() {
let total_runtime = Timer::start("Completed");
tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.with_line_number(true)
.with_thread_ids(true)
.with_file(true)
.with_timer(LocalTime::rfc_3339())
.init();
let writer = std::fs::OpenOptions::new()
.append(true)
.create(true)
.open("./docker/logs/tracing.log")
.expect("Couldn't make log file!");
let registry = Registry::default()
.with(
fmt::layer()
.with_line_number(true)
.with_thread_ids(true)
.with_file(true)
// .with_timer(LocalTime::rfc_3339()) // Loki or alloy does this automatically
.json()
.with_writer(writer)
);
tracing::subscriber::set_global_default(registry).expect("Failed to set default subscriber");
// tracing_subscriber::fmt()
// .with_env_filter(EnvFilter::from_default_env())
// .with_line_number(true)
// .with_thread_ids(true)
// .with_file(true)
// .with_timer(LocalTime::rfc_3339())
// .init();
debug!("Starting...");
// Would probably take these in as parameters from a cli
let starting_url = "https://en.wikipedia.org/";
@@ -56,8 +76,8 @@ async fn main() {
surreal_db: "v1.12",
s3_bucket: "v1.12",
s3_url: "http://localhost:9000",
s3_access_key: "8UO76z8wCs9DnpxSbQUY",
s3_secret_key: "xwKVMpf2jzgprsdo85Dvo74UmO84y0aRrAUorYY5",
s3_access_key: "p8gXIZEO2FnWqWBiJYwo",
s3_secret_key: "1mRO0EYA2YAQ0xsKrlbkIIz4AT8KNXy6QIQPtxUu",
};
@@ -66,7 +86,7 @@ async fn main() {
.expect("Failed to connect to surreal, aborting.");
let s3 = S3::connect(&config)
.await
.expect("Failed to connect to minio, aborting.");
.expect("Failed to connect to minio, aborting.\n\nThis probably means you need to login to the minio console and get a new access key!\n\n(Probably here) http://localhost:9001/access-keys/new-account\n\n");
let reqwest = reqwest::Client::builder()
// .use_rustls_tls()