示例#1
0
func initAppContext(app *App) {
	ctx, cancel := context.WithCancel(context.Background())
	ctx = context.WithValue(ctx, &appContextKey, app)

	ctx = log.Context(ctx, app.log)
	app.ctx = ctx
	app.cancel = cancel
}
示例#2
0
文件: main.go 项目: lackac/horizon
// ContextWithLogBuffer returns a context and a buffer into which the new, bound
// logger will write into.  This method allows you to inspect what data was
// logged more easily in your tests.
func ContextWithLogBuffer() (context.Context, *bytes.Buffer) {
	output := new(bytes.Buffer)
	l, _ := glog.New()
	l.Logger.Out = output
	l.Logger.Formatter.(*logrus.TextFormatter).DisableColors = true
	l.Logger.Level = logrus.DebugLevel

	ctx := glog.Context(context.Background(), l)
	return ctx, output

}
示例#3
0
文件: main.go 项目: lackac/horizon
// Context provides a context suitable for testing in tests that do not create
// a full App instance (in which case your tests should be using the app's
// context).  This context has a logger bound to it suitable for testing.
func Context() context.Context {
	return glog.Context(context.Background(), testLogger)
}