#8 logging, part 1
This commit is contained in:
parent
793daa9617
commit
9b4dbb9377
3 changed files with 12 additions and 1 deletions
9
Cargo.lock
generated
9
Cargo.lock
generated
|
|
@ -2,6 +2,15 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "log"
|
||||||
|
version = "0.4.29"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "workshop"
|
name = "workshop"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,4 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
log = "0.4"
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::{TcpListener, TcpStream};
|
use std::net::{TcpListener, TcpStream};
|
||||||
|
use log::info;
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let listener = TcpListener::bind("127.0.0.1:7878")?;
|
let listener = TcpListener::bind("127.0.0.1:7878")?;
|
||||||
|
|
@ -13,7 +14,7 @@ fn main() -> std::io::Result<()> {
|
||||||
fn handle_connection(mut stream: TcpStream) -> std::io::Result<()> {
|
fn handle_connection(mut stream: TcpStream) -> std::io::Result<()> {
|
||||||
let mut buffer = [0; 1024];
|
let mut buffer = [0; 1024];
|
||||||
stream.read(&mut buffer)?;
|
stream.read(&mut buffer)?;
|
||||||
println!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
info!("Request: {}", String::from_utf8_lossy(&buffer[..]));
|
||||||
|
|
||||||
let contents = include_str!("hello.html");
|
let contents = include_str!("hello.html");
|
||||||
let response = format!(
|
let response = format!(
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue