dart_frog icon indicating copy to clipboard operation
dart_frog copied to clipboard

feat: logger support

Open felangel opened this issue 2 years ago • 1 comments

Description

As a developer, I want to be able to have either integrated 1st party support or a recommended 3rd party logger which seamlessly integrates with dart_frog and provides the functionality described in the requirements section.

Requirements

  • [ ] Standard Logging Levels
  • [ ] Flexible API which can support logging-specific requirements for various cloud platforms
  • [ ] API which can support configuring log-levels based on the environment (e.g. debug in development and notice in production)

felangel avatar Jul 11 '22 20:07 felangel

Hi there 👋 I agree this is a very important thing to add!

Personally, I would add a few more requirements that would be super nice to have:

  • [ ] Automatically logging uncaught errors in handlers in the correct format
  • [ ] Included middleware so it works "out of the box"

Because of these, I propose we use something like this repository that I set up to demonstrate how I think a dart_frog logger should work. You can check it out now - instructions are in the README (although I haven't published it to pub.dev yet so you'll have to add it as a git dependency for now).

A few reasons I think this is a great solution:

  1. It covers all the requirements laid out in the issue and my comment
  2. It exposes a simple typedef LogFormatter so that it's super easy to define your own log style if you'd like
  3. In a separate library, it includes a built-in support for Google Cloud Logging and a simple log format for local development
  4. It includes information like source location and stacktraces in the logs
  5. It uses very_good_analysis and has 100% coverage
  6. It only depends on shelf and not dart_frog so it works just as well with a raw shelf API

Lastly, I really think it's good to have the logger not built into the framework but instead as a separate package that can be added in through middleware.

The bold part of me proposes we migrate the existing repository to the /packages directory and rename it dart_frog_logger. I could also write a page on the docs site showing how to use it.

Let me know what you think 💙 I'm sure my package isn't perfect, but hopefully can at least share ideas and at most make this a super easy ticket to close 😎

mtwichel avatar Jul 12 '22 23:07 mtwichel