Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

[cli] Add a tail command to follow server logs #85

Open
dstpierre opened this issue May 10, 2023 · 3 comments
Open

[cli] Add a tail command to follow server logs #85

dstpierre opened this issue May 10, 2023 · 3 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@dstpierre
Copy link
Member

Could be helpful to have a way to display HTTP requests info.

In the CLI program we could add a command line parameter to the server command, say --tail which would display the HTTP requests being handled by the server.

In the core package, we currently do not have a log middleware. We'd need one and use the logger to ourput nice output, but only if we used the --tail option.

This means that in the config we would need to add a new option to indicate if we want to display the server log or not.

The log middleware would be added to all middleware chains only if that config flag is true.

What I mean by middleware chains can be found in server.go:117:

stdAuth := []middleware.Middleware{
  middleware.Cors(),
  middleware.WithDB(backend.DB, backend.Cache, getStripePortalURL),
  .// ...
}

Since they are this function receive the config, the log middleware could accept a flag to be verbose or not, ex:

stdAuth := []middleware.Middleware{
  middleware.Log(config.TailRequests),
  middleware.Cors(),
  middleware.WithDB(backend.DB, backend.Cache, getStripePortalURL),
  // ...
}

Assuming the config flag would be called TailRequests and the log middleware Log.

If TailRequests is false the middleware simply do nothing.

@dstpierre dstpierre added help wanted Extra attention is needed good first issue Good for newcomers labels May 10, 2023
@mauriceLC92
Copy link

Hey @dstpierre I am keen to take this task on. Could you please assign it to me and I will try make a start this weekend?

@dstpierre
Copy link
Member Author

Thanks @mauriceLC92 highly appreciated. Here's a couple of tips since you will need to modify this project core and the cli

The cli import the core project, to make this work you'll need to replace the package in the cli to say you want to use your local version:

  1. Clone both projects side-by-side, ex: ~/src/staticbackend/ have the core and cli there.
  2. In the cli go.mod add replace github.com/staticbackendhq/core => ../core

From there you should be able to make changes in the core to create the log middleware and the changes to config and build the cli. Not optimal, still trying to figure out the best workflow for this.

I'm using make build to build the cli and from there you will have a binary called backend

$ ./backend server --tail-log

For example testing this new flag.

Do not hesitate if you have any questions.
`

@mauriceLC92
Copy link

Perfect, thanks for the extra tips! Will shout if I have any questions

@dstpierre dstpierre added this to the v1.6 milestone May 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants