Switch to tracing from log
Some checks failed
CI / build (push) Has been cancelled

This commit is contained in:
Fabian Stamm
2025-11-05 22:29:21 +01:00
parent 01bc71ab86
commit a23c5217d1
7 changed files with 162 additions and 43 deletions

View File

@ -1,8 +1,8 @@
use std::{fs::File, path::Path};
use log::info;
use serde::Deserialize;
use tokio::signal::unix::Signal;
use tracing::info;
use crate::Result;

View File

@ -2,12 +2,9 @@
use std::collections::HashMap;
use log::debug;
use log::info;
use log::trace;
use log::warn;
use reqwest::header::HeaderMap;
use serde::{Deserialize, Serialize};
use tracing::{debug, info, trace, warn};
use crate::config::Config;
use crate::config::ConfigProvider;

View File

@ -8,11 +8,12 @@ mod udp;
mod consul;
use config::ConfigProvider;
use log::{debug, error, info, warn};
use std::collections::{HashMap, HashSet};
use std::error::Error;
use std::sync::Arc;
use tokio::sync::{broadcast, RwLock};
use tracing::{debug, error, info, warn};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
pub type Result<T> = std::result::Result<T, Box<dyn Error>>;
@ -25,21 +26,35 @@ struct ActiveListener {
#[tokio::main]
async fn main() -> Result<()> {
fern::Dispatch::new()
.format(|out, message, record| {
out.finish(format_args!(
"{}[{}][{}] {}",
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
record.target(),
record.level(),
message
))
})
// Add blanket level filter -
.level(log::LevelFilter::Info)
.level_for("rustocat", log::LevelFilter::Debug)
.chain(std::io::stdout())
.apply()?;
std::panic::set_hook(Box::new(|panic| {
// Get a backtrace!
let backtrace = std::backtrace::Backtrace::capture();
// If the panic has a source location, record it as structured fields.
if let Some(location) = panic.location() {
// On nightly Rust, where the `PanicInfo` type also exposes a
// `message()` method returning just the message, we could record
// just the message instead of the entire `fmt::Display`
// implementation, avoiding the duplicated location
tracing::error!(
message = %panic,
panic.file = location.file(),
panic.line = location.line(),
panic.column = location.column(),
panic.backtrace = %backtrace
);
} else {
tracing::error!(message = %panic, panic.backtrace = %backtrace);
}
}));
tracing_subscriber::registry()
.with(
tracing_subscriber::filter::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "info".into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
let listeners: HashMap<String, ActiveListener> = HashMap::new();
let text_config_provider = config::FileConfigProvider::new();

View File

@ -1,8 +1,8 @@
use crate::listener::Listener;
use log::{error, info, trace, warn};
use rand::seq::SliceRandom;
use std::error::Error;
use tokio::net::{TcpListener, TcpStream};
use tracing::{error, info, trace, warn};
#[derive(Debug)]
struct TcpHandler {

View File

@ -2,8 +2,8 @@ use std::collections::HashMap;
use std::sync::atomic::AtomicI32;
use std::sync::Arc;
use log::{debug, error, info, trace, warn};
use rand::seq::SliceRandom;
use tracing::{debug, error, info, trace, warn};
use tokio::net::UdpSocket;
use tokio::sync::Mutex;
@ -104,7 +104,7 @@ impl UDPChannel {
let num_bytes = tokio::select! {
res = upstream_listener.recv(&mut buf) => res.unwrap(),
_ = shutdown_receiver.recv() => {
info!("Exiting");
debug!("Exiting upstream_listener");
return;
}
};