-
Notifications
You must be signed in to change notification settings - Fork 22
feat: setup logging with tracing #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: setup logging with tracing #291
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work setting up tracing!
Lets clean up a bit test code and take back trailing newlines please.
crates/http-server/src/cli.rs
Outdated
#[arg(long, default_value = "7878")] | ||
#[arg(long, default_value = "3000")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep this as 7878
? Which is the one used in The Rust Programming Language Book?
Using TcpListener, we can listen for TCP connections at the address 127.0.0.1:7878. In the address, the section before the colon is an IP address representing your computer (this is the same on every computer and doesn’t represent the authors’ computer specifically), and 7878 is the port. We’ve chosen this port for two reasons: HTTP isn’t normally accepted on this port so our server is unlikely to conflict with any other web server you might have running on your machine, and 7878 is rust typed on a telephone.
crates/http-server/src/cli.rs
Outdated
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the trailing newline
crates/http-server/src/main.rs
Outdated
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the trailing newline
crates/http-server/src/server/mod.rs
Outdated
async fn handler_custom() -> impl IntoResponse { | ||
info!("A request has been received on a custom route"); | ||
Html("Hello <strong>Rust!!!</strong>") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the trailing newline
crates/http-server/src/server/mod.rs
Outdated
|
||
async fn handler_default() -> impl IntoResponse{ | ||
debug!("A request has been received on the default route"); | ||
Html("Hello <strong>Rust!!!</strong>") | ||
} | ||
|
||
async fn handler_custom() -> impl IntoResponse { | ||
info!("A request has been received on a custom route"); | ||
Html("Hello <strong>Rust!!!</strong>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this as not related to tracing?
It's something very simple... it could be improved later... |
Thanks @FMFigueroa! Can you run |
Sure.. Apology man..! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets merge tracing first and then move into file explorer pls
pub struct Server(Router); | ||
pub struct Server(pub Router); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets keep the Router
encapsulated and use the getter we have as a method instead
fn from(value: Cli) -> Self { | ||
let filter = EnvFilter::from_default_env().add_directive(Level::INFO.into()); | ||
|
||
tracing_subscriber::fmt().with_env_filter(filter).init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taking advantage of the Cli
I think we could have a log
argument we could use to pass it to the tracing_subscriber
. This way we could do:
http-server --log debug
This would set the Level::DEBUG
in L16.
crates/http-server/src/cli.rs
Outdated
/// Directory to serve files from | ||
#[arg(long, default_value = "./")] | ||
pub root_dir: PathBuf, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move this into its own PR? Given that is out of scope of tracing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
No description provided.