-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
os/glog: Does GoFrame support for logging fields? #3869
Comments
I do have read this issue: #553 But the answer in that issue do not fit my situation. The point is the log message is a field in JSON, both logging in a simple way and logging with fields. |
@RyoJerryYu Hello, we does not support |
Hello @RyoJerryYu. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it! |
@gqcn Thank you for answering. But I don't seem to have made my real needs clear. What we really want is the ability of structured logging, and the simple logging should remain simple and work well with structured logging. We do not care how the codes look like. The logrus-like In fact, we all know there's a bunch of libraries that support structured logging in different styles. // zap styles
sugar.Infow("failed to fetch URL",
// Structured context as loosely typed key-value pairs.
"url", url,
"attempt", 3,
"backoff", time.Second,
)
logger.Info("failed to fetch URL",
// Structured context as strongly typed Field values.
zap.String("url", url),
zap.Int("attempt", 3),
zap.Duration("backoff", time.Second),
)
// zerolog styles
log.Debug().
Str("Scale", "833 cents").
Float64("Interval", 833.09).
Msg("Fibonacci is everywhere") Obviously we can easily convert to each style by adding a simple adapter layer. But it seems |
BTW, we finally found that it seems could be implemented by providing a self-defined It would be much better if |
Hello, if your root requirement is just structure logging feature, it is already supported in package main
import (
"context"
"net"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/glog"
)
func main() {
ctx := context.TODO()
glog.SetDefaultHandler(glog.HandlerStructure)
g.Log().Info(ctx, "caution", "name", "admin")
glog.Error(ctx, "oops", net.ErrClosed, "status", 500)
} When you run it, it outputs like this:
|
What do you want to ask?
We are using logrus and logging like this:
And it produce json logs like below:
So we can use the fields to filter our logs such as:
Do GoFrame support this? Or how can I implement something like this in GoFrame?
The text was updated successfully, but these errors were encountered: