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

Connect Gorm logger to logrus #140

Open
sa7mon opened this issue Jul 19, 2023 · 0 comments
Open

Connect Gorm logger to logrus #140

sa7mon opened this issue Jul 19, 2023 · 0 comments
Labels
refactor Code cleanup / optimization
Milestone

Comments

@sa7mon
Copy link
Owner

sa7mon commented Jul 19, 2023

If we provide the -db flag without postgres running, we get this output

╰─$ go run main.go -json -bucket asdfasdf567 -enumerate -provider custom -db                                                                                

[error] failed to initialize database, got error failed to connect to `host=db_dev user=postgres database=postgres`: hostname resolving error (lookup db_dev: no such host)

{"level":"error","msg":"failed to connect to `host=db_dev user=postgres database=postgres`: hostname resolving error (lookup db_dev: no such host)"}
exit status 1

In database.go:Connect(), configure Gorm to hook into our existing Logrus logger so:

  • we only log errors once
  • we log errors in either JSON or human-readable format depending on -json flag

https://www.soberkoder.com/go-gorm-logging/

@sa7mon sa7mon added this to the Future milestone Jul 19, 2023
@sa7mon sa7mon transferred this issue from another repository Jul 29, 2023
@sa7mon sa7mon added the refactor Code cleanup / optimization label Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Code cleanup / optimization
Projects
None yet
Development

No branches or pull requests

1 participant