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

GIN & GORM logging integration #11

Merged
merged 3 commits into from
Jul 13, 2021
Merged

GIN & GORM logging integration #11

merged 3 commits into from
Jul 13, 2021

Conversation

applejag
Copy link
Contributor

@applejag applejag commented Jun 18, 2021

Summary

Adds easy integration for Gin-Gonic & GORM with wharf-core's logging. See the _example_test.go files for how they're meant to be used, but here's the gist:

// Gin-Gonic
r := gin.New()

r.Use(ginutil.DefaultLoggerHandler)
gin.DefaultWriter = ginutil.DefaultLoggerWriter
gin.DefaultErrorWriter = ginutil.DefaultLoggerWriter

// GORM
db, err := gorm.Open(postgres.Open("host=localhost"), &gorm.Config{
	DryRun:               true,
	DisableAutomaticPing: true,
	Logger: gormutil.NewLogger(gormutil.LoggerConfig{
		Logger: logger.NewScoped("GORM"),
	}),
})

Motivation

GORM and Gin still has their built-in ways for logging, but allow you to add your own logger if you want to. These changes makes that integration easy, so with just a few lines then both GORM and Gin will use wharf-core/pkg/logger for logging instead of their own solutions, which will bring a more unified visual to our logs

@applejag applejag added the enhancement New feature or request label Jun 18, 2021
@applejag applejag self-assigned this Jun 18, 2021
@applejag applejag marked this pull request as draft June 18, 2021 13:13
@applejag applejag force-pushed the feature/logging branch 2 times, most recently from 9136d90 to 7df879e Compare June 18, 2021 13:20
@applejag applejag marked this pull request as ready for review July 2, 2021 11:23
Copy link
Member

@Alexamakans Alexamakans left a comment

Choose a reason for hiding this comment

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

Looks good to me, just a few typos and nits.

pkg/gormutil/logger_example_test.go Outdated Show resolved Hide resolved
pkg/ginutil/logger.go Outdated Show resolved Hide resolved
pkg/gormutil/logger.go Outdated Show resolved Hide resolved
@applejag applejag requested a review from Alexamakans July 6, 2021 15:52
Copy link
Contributor

@fredx30 fredx30 left a comment

Choose a reason for hiding this comment

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

Code style seems fine to me.

Th PR description is missing both what and why. What problem does this solve? What does the integration do?

@applejag
Copy link
Contributor Author

Code style seems fine to me.

Th PR description is missing both what and why. What problem does this solve? What does the integration do?

Updated desc

@applejag applejag merged commit df61b20 into master Jul 13, 2021
@applejag applejag deleted the feature/logging branch July 13, 2021 07:58
@applejag applejag mentioned this pull request Jul 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants