Feat: Debugging/Logging is working
- Updated dependencies
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/main.rs
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/main.rs
									
									
									
									
									
								
							@@ -1,12 +1,17 @@
 | 
			
		||||
use color_eyre::Report;
 | 
			
		||||
use tokio::{
 | 
			
		||||
    io::{AsyncBufReadExt, AsyncWriteExt, BufReader},
 | 
			
		||||
    net::TcpListener,
 | 
			
		||||
    sync::broadcast,
 | 
			
		||||
};
 | 
			
		||||
use tracing::info;
 | 
			
		||||
use tracing_subscriber::filter::EnvFilter;
 | 
			
		||||
 | 
			
		||||
#[tokio::main]
 | 
			
		||||
async fn main() {
 | 
			
		||||
    // Set up a TCP listenner to listen for incoming tcp requests
 | 
			
		||||
async fn main() -> Result<(), Report> {
 | 
			
		||||
    // Setup the Environment
 | 
			
		||||
    setup()?;
 | 
			
		||||
    // Set up a TCP listener to listen for incoming tcp requests
 | 
			
		||||
    let listener = TcpListener::bind("127.0.0.1:8080").await.unwrap();
 | 
			
		||||
 | 
			
		||||
    // Setting up broadcast channel: A channel that will accept messages and broadcast them to everyone connected to the TCP server
 | 
			
		||||
@@ -31,7 +36,7 @@ async fn main() {
 | 
			
		||||
 | 
			
		||||
            let mut line: String = String::new();
 | 
			
		||||
 | 
			
		||||
            // second loop keeps receving input from that one client going
 | 
			
		||||
            // second loop keeps receiving input from that one client going
 | 
			
		||||
            loop {
 | 
			
		||||
                tokio::select! {
 | 
			
		||||
                    result = buffer_reader.read_line(&mut line) => {
 | 
			
		||||
@@ -57,3 +62,23 @@ async fn main() {
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn setup() -> Result<(), Report> {
 | 
			
		||||
    info!("Changing some environment variables!");
 | 
			
		||||
 | 
			
		||||
    if std::env::var("RUST_LIB_BACKTRACE").is_err() {
 | 
			
		||||
        std::env::set_var("RUST_LIB_BACKTRACE", "1");
 | 
			
		||||
        info!("RUST_LIB_BACKTRACE is set. There will be pretty error messages !")
 | 
			
		||||
    }
 | 
			
		||||
    color_eyre::install()?;
 | 
			
		||||
 | 
			
		||||
    if std::env::var("RUST_LOG").is_err() {
 | 
			
		||||
        std::env::set_var("RUST_LOG", "info");
 | 
			
		||||
        info!("RUST_LOG is set. All errors shall be logged !")
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    tracing_subscriber::fmt::fmt()
 | 
			
		||||
        .with_env_filter(EnvFilter::from_default_env())
 | 
			
		||||
        .init();
 | 
			
		||||
 | 
			
		||||
    Ok(())
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user