Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
81 additions
and
141 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,9 +1,31 @@ | ||
package keycloakb | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
) | ||
|
||
// Logger interface for logging with level | ||
type Logger interface { | ||
Debug(keyvals ...interface{}) error | ||
Info(keyvals ...interface{}) error | ||
Warn(keyvals ...interface{}) error | ||
Error(keyvals ...interface{}) error | ||
} | ||
|
||
// LogUnrecordedEvent logs the events that could not be reported in the DB | ||
func LogUnrecordedEvent(ctx context.Context, logger Logger, eventName string, errorMessage string, values ...string) { | ||
if len(values)%2 != 0 { | ||
logger.Error("err", "When logging an unrecorded event the number of parameters should be even") | ||
} | ||
m := map[string]interface{}{"event_name": eventName} | ||
for i := 0; i < len(values); i += 2 { | ||
m[values[i]] = values[i+1] | ||
} | ||
eventJSON, errMarshal := json.Marshal(m) | ||
if errMarshal == nil { | ||
logger.Error("err", errorMessage, "event", string(eventJSON)) | ||
} else { | ||
logger.Error("err", errorMessage) | ||
} | ||
} |
This file contains 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 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 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 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.