-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [#282] Print the values in ctx when calling facades.Log().WithC…
…ontext(ctx).Info() (#759) * feat: [#282] Print the values in ctx when calling facades.Log().WithContext(ctx).Info() * optimmize tests * fix http.Request * optimize first letter * optimize lint
- Loading branch information
Showing
13 changed files
with
512 additions
and
214 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
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package log | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cast" | ||
|
||
"github.com/goravel/framework/contracts/log" | ||
) | ||
|
||
type Hook struct { | ||
instance log.Hook | ||
} | ||
|
||
func (h *Hook) Levels() []logrus.Level { | ||
levels := h.instance.Levels() | ||
var logrusLevels []logrus.Level | ||
for _, item := range levels { | ||
logrusLevels = append(logrusLevels, logrus.Level(item)) | ||
} | ||
|
||
return logrusLevels | ||
} | ||
|
||
func (h *Hook) Fire(entry *logrus.Entry) error { | ||
e := &Entry{ | ||
ctx: entry.Context, | ||
data: map[string]any(entry.Data), | ||
level: log.Level(entry.Level), | ||
message: entry.Message, | ||
time: entry.Time, | ||
} | ||
|
||
data := entry.Data | ||
if len(data) > 0 { | ||
root, err := cast.ToStringMapE(data["root"]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if code, err := cast.ToStringE(root["code"]); err == nil { | ||
e.code = code | ||
} | ||
if domain, err := cast.ToStringE(root["domain"]); err == nil { | ||
e.domain = domain | ||
} | ||
if hint, err := cast.ToStringE(root["hint"]); err == nil { | ||
e.hint = hint | ||
} | ||
|
||
e.owner = root["owner"] | ||
|
||
if request, err := cast.ToStringMapE(root["request"]); err == nil { | ||
e.request = request | ||
} | ||
if response, err := cast.ToStringMapE(root["response"]); err == nil { | ||
e.response = response | ||
} | ||
if stacktrace, err := cast.ToStringMapE(root["stacktrace"]); err == nil { | ||
e.stacktrace = stacktrace | ||
} | ||
if tags, err := cast.ToStringSliceE(root["tags"]); err == nil { | ||
e.tags = tags | ||
} | ||
|
||
e.user = root["user"] | ||
|
||
if with, err := cast.ToStringMapE(root["with"]); err == nil { | ||
e.with = with | ||
} | ||
} | ||
|
||
return h.instance.Fire(e) | ||
} |
Oops, something went wrong.