Last active
March 27, 2018 17:58
-
-
Save hdonnay/66189d15f91de6dd0bf32a8e376f162e to your computer and use it in GitHub Desktop.
logger idea
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
package tlog | |
// import (...) | |
func WithTags(ctx context.Context, pairs ...string) context.Context { | |
// turn these pairs into a bunch of [][2]string, shove into the Context | |
} | |
func Print(ctx context.Context, f string, v ...interface{}) { | |
tags := fromContext(ctx) | |
line := strings.Builder{} | |
// build line... | |
Output(2, line.String()) | |
} | |
// etc... | |
type Logger struct {} | |
func New(...) *Logger { | |
// use the functional options pattern because we're breaking compatability with everything, hard | |
} | |
func (l *Logger) Print(ctx context.Context, f string, v ...interface{}) { | |
//... | |
} | |
func FromContext(ctx context.Context) *log.Logger { | |
// close over the provided context and provide a very unconfigurable logger, like the stackdriver package. | |
// A compatability niceity. | |
} |
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
package main | |
func mydumbfunction(ctx context.Context) error { | |
ctx := tlog.WithTags(ctx, "today", "tuesday") | |
tlog.Println(ctx, "doing mydumbfunction") | |
// ... | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment