-
Notifications
You must be signed in to change notification settings - Fork 19
Convert logging in dashboard.go to structured Zap logger #171
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
base: main
Are you sure you want to change the base?
Conversation
pkg/api/dashboard.go
Outdated
| // @Router /dashboard [get] | ||
| func GetDashboardData(c *gin.Context) { | ||
|
|
||
| logger := zap.L() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to initiate the logger, there is already a wrapper log.go, you can see main.go as a reference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, done!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment has not been addressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I already fixed that earlier, but I mistakenly pushed the change to another branch. I’ve now applied the same fix to this PR branch as well.
|
ok, looks good! Just 1 more thing, import the log package as logger logger "github.com/fossology/LicenseDb/pkg/log"and squash all commits into one, and sign your commit, and make sure your commit follows our commit convention |
7627ea2 to
197ed50
Compare
|
Done!!! |
|
Hi! Just wanted to check if there’s anything else needed from my end for this PR ? |
cb995ea to
1620c53
Compare
Yes, as Chayan said, squash all your commits into a single commit. Instructions here: squashing commits , |
1620c53 to
15da6ca
Compare
|
Squashed and signed!! |
|
We have some import errors. Some tests are failing in the pipeline. Please click on the individual tests and see why they fail. |
9dfbc37 to
a1e8573
Compare
|
All test cases are passing now |
pkg/api/dashboard.go
Outdated
| iso8601StartOfMonth := startOfMonth.Format(time.RFC3339) | ||
| if err := db.DB.Model(&models.Audit{}).Where("timestamp > ? AND type='license'", iso8601StartOfMonth).Count(&licenseChangesSinceLastMonth).Error; err != nil { | ||
| log.Printf("\033[31mError: error fetching audits count: %s\033[0m", err.Error()) | ||
| logger.LogError("error fetching users count", zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check all the logs properly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Chayan, done!! see it last time
pkg/api/dashboard.go
Outdated
| Select("rf_risk as risk, count(*) as count"). | ||
| Group("rf_risk"). | ||
| Scan(&licenseFrequency).Error; err != nil { | ||
| logger.LogError("error fetching users count", zap.Error(err)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check those lines!
10644be to
3c949c0
Compare
Signed-off-by: Joshna Waikar <joshnawaikar@gmail.com>
e7dd96c to
0d39965
Compare
ChayanDass
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Changes made -
Replaced all log.Printf calls with zap structured logs.
Added logger := zap.L() at the top of the handler.