Skip to content

Instantly share code, notes, and snippets.

@hackerzhut
Created April 19, 2019 09:18
Show Gist options
  • Save hackerzhut/cac960072b69811aca606ce0e3f98edf to your computer and use it in GitHub Desktop.
Save hackerzhut/cac960072b69811aca606ce0e3f98edf to your computer and use it in GitHub Desktop.
Ideal Logger Interface
type Logger interface {
// all levels + Prin
Print(v ...interface{})
Printf(format string, v ...interface{})
Println(v ...interface{})
Debug(v ...interface{})
Debugf(format string, v ...interface{})
Debugln(v ...interface{})
Info(v ...interface{})
Infof(format string, v ...interface{})
Infoln(v ...interface{})
Warn(v ...interface{})
Warnf(format string, v ...interface{})
Warnln(v ...interface{})
Error(v ...interface{})
Errorf(format string, v ...interface{})
Errorln(v ...interface{})
Fatal(v ...interface{})
Fatalf(format string, v ...interface{})
Fatalln(v ...interface{})
Panic(v ...interface{})
Panicf(format string, v ...interface{})
Panicln(v ...interface{})
// Prefix - chainable so it can create a logger instance, safe for concurrent use
Prefix(prefix string) Logger
// Prefixf to avoid having to use fmt.Sprintf whenever using this
Prefixf(fromat string, v ...interface{}) Logger
// fields for other formatters, acts like prefix be default
WithField(k, v interface{}) Logger
// Context stuff as explained earlier
Ctx(ctx context.Context) (Logger, context.Context)
SetCtxCallback(func(ctx context.Context, logger Logger) context.Context)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment