Skip to content
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

Logging middleware #52

Merged
merged 5 commits into from
Nov 25, 2018
Merged

Logging middleware #52

merged 5 commits into from
Nov 25, 2018

Conversation

bIgBV
Copy link
Contributor

@bIgBV bIgBV commented Nov 19, 2018

This PR is to establish a base to build the logging infrastructure upon. The discussion is still ongoing in #8 , but this PR introduces a basic logging instance to start displaying information regarding the requests being served by the application. The output of running an application now shows up in the terminal as follows:

screen shot 2018-11-19 at 17 16 45

As you can see, the method, path and the status code of a request are logged to the terminal. This provides immediate feedback for the user.

Right now I'm instantiating an instance of the SimpleLogger middleware and adding it to the list of middlewares by default.

Copy link
Collaborator

@aturon aturon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! I left a few small suggestions to approach this a bit more conservatively.

src/app.rs Outdated
App {
data,
router: Router::new(),
middleware: Vec::new(),
middleware: vec![Box::new(logger)],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's hold off on setting up default middleware just yet -- maybe open an issue on it so we can discuss how we want to approach it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I went with a default middleware was because I felt that the logging provided by this is something that a framework should provide at the least. Is that a reasonable expectation from Tide? If it is, then where will the middleware loaded? As a part of the initial configuration?

This leads to my next question being what will app configuration look like? But I think that is being discussed over at #5

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, that's fair enough -- I certainly agree that this should be part of the default middleware set.

src/lib.rs Outdated
@@ -17,6 +17,7 @@ pub mod body;
mod endpoint;
mod extract;
pub mod head;
mod logger;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should consider putting this into a submodule of middlware and exposing it publicly that way.

src/logger.rs Outdated
///
/// Only used internally for now.
pub(crate) struct RootLogger {
// drain: dyn slog::Drain,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clean up this commented-out line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if/when we expose this publicly, we should bikeshed the name a bit. (No strong opinion here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the name was something I went back and forth on for a while. I decided to stick with RootLogger as the idea was that users would use child loggers of this instance.

@aturon
Copy link
Collaborator

aturon commented Nov 25, 2018

OK, I think we can land this as-is, after a rebase!

* No interface to log data currently present.
* Add a logger type which wraps over slog logger.
* Hook into the request cycle.
* This is in order to convey the idea that this is the RootLogger off of
which child loggers should be instantiated.

Fix lint warnings
* Remove unecessary types
* Remove unecessary request method implementation
@bIgBV bIgBV force-pushed the logging-middleware branch from 77da812 to 7431da8 Compare November 25, 2018 18:08
* Move logging.rs into middleware directory
@aturon aturon merged commit 07e436a into http-rs:master Nov 25, 2018
@aturon
Copy link
Collaborator

aturon commented Nov 25, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants