Conversation
|
Not ready for this to merge still have a lot of work to do in the other packages but before I go crazy I want some early feedback on the approach and if you think this will be helpful to do it in this way. |
|
@kevpar - FYI |
|
The example in https://godoc.org/github.com/sirupsen/logrus shows using |
|
Also, |
|
@jstarks - I don't mind if we write In practice I feel like I want to write code like this (obviously more polished): func DoWork(ctx context.Context, ...) error {
ctx := log.Start(ctx, "DoWork")
defer log.End(ctx, "DoWork")
// Do something
if err := ChildOperation(ctx); err != nil {
return err
}
// ctx is restored to the original DoWork context
SameContext(ctx)
}
func SubOperation(ctx context.Context) error {
// Start a subcontext that tracks its parent but does not affect it.
ctx := log.Start(ctx, "SubOperation")
defer log.End(ctx, "SubOperation")
id = "test" // RealWork that creates id
ctx.WithFields("id", id)
log.Debug(ctx, "Success")
return nil
}
func SameContext(ctx context.Context) {
ctx.WithFields("flows-up", true)
log.Debug(ctx, "SameContext - Success")
}And then see output like this: { "msg": "DoWork: Start Operation" }
{ "msg": "SubOperation: Start Operation", "parent": "DoWork" }
{ "msg": "SubOperation: Success", "id": "test", "parent": "DoWork" }
{ "msg": "SubOperation: End Operation", "id": "test", "parent": "DoWork" }
{ "msg": "DoWork: SameContext - Success", "flows-up": true }
{ "msg": "DoWork: End Operation", "flows-up": true } |
0c7b3c0 to
c45fa5a
Compare
5fb9ae2 to
11441d8
Compare
|
@jstarks @jhowardmsft - PTAL. I removed any additional |
Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
|
Merging this for now. Will add two additional changes for |
Signed-off-by: Justin Terry (VM) juterry@microsoft.com