-
-
Notifications
You must be signed in to change notification settings - Fork 629
feat(logging): Switch to slog library #1472
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
Draft
PythonGermany
wants to merge
15
commits into
TwiN:master
Choose a base branch
from
PythonGermany:switch-logging-to-slog
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d57a23b
refactor(logging): Separate logging config
PythonGermany 923c03a
refactor(logging): Use slog in endpoint watchdog
PythonGermany c74094b
feat(logging): Option to enable detailed source location
PythonGermany e6b3a5d
fix: Format text handler time attribute
PythonGermany 9bbdf76
refactor(logging): Replace logr with slog
PythonGermany da407f7
feat(logging): Create log attributes for common groups
PythonGermany e5b8a55
feat(logging): Create attribute for results
PythonGermany 73b05d2
fix(logging): Check if log level is debug or lower
PythonGermany 64c28dd
fix: Use log attribute helper methods
PythonGermany daf4eb8
refactor(logging): Change group value order
PythonGermany d7a22a8
refactor(logging): Change logs to warn level
PythonGermany 57e9cce
refactor(logging): Remove TODOs
PythonGermany beb8c53
refactor(logging): Rework config init logic
PythonGermany dde24a2
refactor(logging): Change default option log behavior
PythonGermany fd29616
fix(logging): Output consistency
PythonGermany File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package api | |
|
|
||
| import ( | ||
| "errors" | ||
| "log/slog" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -11,7 +12,6 @@ import ( | |
| "github.com/TwiN/gatus/v5/storage/store" | ||
| "github.com/TwiN/gatus/v5/storage/store/common" | ||
| "github.com/TwiN/gatus/v5/watchdog" | ||
| "github.com/TwiN/logr" | ||
| "github.com/gofiber/fiber/v2" | ||
| ) | ||
|
|
||
|
|
@@ -35,11 +35,11 @@ func CreateExternalEndpointResult(cfg *config.Config) fiber.Handler { | |
| key := c.Params("key") | ||
| externalEndpoint := cfg.GetExternalEndpointByKey(key) | ||
| if externalEndpoint == nil { | ||
| logr.Errorf("[api.CreateExternalEndpointResult] External endpoint with key=%s not found", key) | ||
| slog.Error("External endpoint not found", "key", key) | ||
| return c.Status(404).SendString("not found") | ||
| } | ||
| if externalEndpoint.Token != token { | ||
| logr.Errorf("[api.CreateExternalEndpointResult] Invalid token for external endpoint with key=%s", key) | ||
| slog.Error("Invalid token for external endpoint", "key", key) | ||
| return c.Status(401).SendString("invalid token") | ||
| } | ||
| // Persist the result in the storage | ||
|
|
@@ -51,7 +51,7 @@ func CreateExternalEndpointResult(cfg *config.Config) fiber.Handler { | |
| if len(c.Query("duration")) > 0 { | ||
| parsedDuration, err := time.ParseDuration(c.Query("duration")) | ||
| if err != nil { | ||
| logr.Errorf("[api.CreateExternalEndpointResult] Invalid duration from string=%s with error: %s", c.Query("duration"), err.Error()) | ||
| slog.Error("Invalid duration", "duration", c.Query("duration"), "error", err.Error()) | ||
| return c.Status(400).SendString("invalid duration: " + err.Error()) | ||
| } | ||
| result.Duration = parsedDuration | ||
|
|
@@ -64,14 +64,14 @@ func CreateExternalEndpointResult(cfg *config.Config) fiber.Handler { | |
| if errors.Is(err, common.ErrEndpointNotFound) { | ||
| return c.Status(404).SendString(err.Error()) | ||
| } | ||
| logr.Errorf("[api.CreateExternalEndpointResult] Failed to insert result in storage: %s", err.Error()) | ||
| slog.Error("Failed to insert endpoint result", "error", err.Error()) | ||
| return c.Status(500).SendString(err.Error()) | ||
| } | ||
| logr.Infof("[api.CreateExternalEndpointResult] Successfully inserted result for external endpoint with key=%s and success=%s", c.Params("key"), success) | ||
| slog.Info("Successfully inserted result for external endpoint", slog.Group("result", "key", c.Params("key"), "success", success)) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Remove group test or apply in other places too? |
||
| inEndpointMaintenanceWindow := false | ||
| for _, maintenanceWindow := range externalEndpoint.MaintenanceWindows { | ||
| if maintenanceWindow.IsUnderMaintenance() { | ||
| logr.Debug("[api.CreateExternalEndpointResult] Under endpoint maintenance window") | ||
| slog.Debug("External endpoint under maintenance window", "key", externalEndpoint.Key) | ||
| inEndpointMaintenanceWindow = true | ||
| } | ||
| } | ||
|
|
@@ -81,7 +81,7 @@ func CreateExternalEndpointResult(cfg *config.Config) fiber.Handler { | |
| externalEndpoint.NumberOfSuccessesInARow = convertedEndpoint.NumberOfSuccessesInARow | ||
| externalEndpoint.NumberOfFailuresInARow = convertedEndpoint.NumberOfFailuresInARow | ||
| } else { | ||
| logr.Debug("[api.CreateExternalEndpointResult] Not handling alerting because currently in the maintenance window") | ||
| slog.Debug("Not handling alerting because currently in the maintenance window", "key", externalEndpoint.Key) | ||
| } | ||
| if cfg.Metrics { | ||
| metrics.PublishMetricsForEndpoint(convertedEndpoint, result, extraLabels) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
TODO: More message context needed?