Comments (3)
if h, ok := ctx.(http.Context); ok { fmt.Println(h.Header()) }
Is this help?
from kratos.
if h, ok := ctx.(http.Context); ok { fmt.Println(h.Header()) }
Is this help?
I want log http method in caller log, not I code log.info(ctx)
from kratos.
if h, ok := ctx.(http.Context); ok { fmt.Println(h.Header()) }
Is this help?I want log http method in caller log, not I code log.info(ctx)
you can custom your log middleware
func NewHTTPServer(c *conf.Server, greeter *service.GreeterService) *http.Server {
opts := []http.ServerOption{
http.Middleware(
loggingMiddleware,
),
}
if c.Http.Network != "" {
opts = append(opts, http.Network(c.Http.Network))
}
if c.Http.Addr != "" {
opts = append(opts, http.Address(c.Http.Addr))
}
if c.Http.Timeout != nil {
opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration()))
}
srv := http.NewServer(opts...)
v1.RegisterGreeterHTTPServer(srv, greeter)
return srv
}
func loggingMiddleware(handler middleware.Handler) middleware.Handler {
return func(ctx context.Context, req interface{}) (reply interface{}, err error) {
// fmt.Println("logging middleware in", req)
if hCtx, ok := ctx.(http.Context); ok {
log.Infow(
"method", hCtx.Request().Method,
)
}
reply, err = handler(ctx, req)
return
}
}
from kratos.
Related Issues (20)
- [Question] How to install a specific version of kratos ? HOT 1
- [Question] why trace_id and span_id in logger ctx? HOT 1
- [Feature] allow custom signal to do some handle logic HOT 1
- [Question] When using http, if I want to set timeouts for different routes, how should I set them? HOT 2
- [Feature] Some specification issues when Kratos registers services on Polaris HOT 9
- I have a question about proto. HOT 2
- apollo settings Watch cannot hot update configuration normally
- http.NewClient results in NODE_NOT_FOUND HOT 2
- load apollo config yml format panic HOT 6
- [Question] 如何使用json.Marshal 作为http server 返回的序列化工具 HOT 2
- [Question] The middleware is Executed at the end of the request? HOT 7
- [Question] trace.id is not passed HOT 5
- [Question] How to limit HTTP request size? HOT 6
- The trace_id between requests is getting mixed up HOT 4
- [Question] How should I create a kratos project HOT 1
- net: lookupIPAddr dns resolving panic by data race. HOT 4
- [Question] The pprof profile is not valid HOT 4
- [Feature] Replace `PGV` by `protovalidate` HOT 7
- [Question] Pubsub Implementation HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kratos.