当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.Logger方法代码示例

本文整理汇总了Golang中gnd/la/app.Context.Logger方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Logger方法的具体用法?Golang Context.Logger怎么用?Golang Context.Logger使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gnd/la/app.Context的用法示例。


在下文中一共展示了Context.Logger方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: afterTask

func afterTask(ctx *app.Context, task *Task, started time.Time, terr *error) {
	name := task.Name()
	if err := recover(); err != nil {
		skip, stackSkip, _, _ := runtimeutil.GetPanic()
		var buf bytes.Buffer
		fmt.Fprintf(&buf, "Panic executing task %s: %v\n", name, err)
		stack := runtimeutil.FormatStack(stackSkip)
		location, code := runtimeutil.FormatCaller(skip, 5, true, true)
		if location != "" {
			buf.WriteString("\n At ")
			buf.WriteString(location)
			if code != "" {
				buf.WriteByte('\n')
				buf.WriteString(code)
				buf.WriteByte('\n')
			}
		}
		if stack != "" {
			buf.WriteString("\nStack:\n")
			buf.WriteString(stack)
		}
		*terr = errors.New(buf.String())
	}
	end := time.Now()
	running.Lock()
	defer running.Unlock()
	c := running.tasks[task] - 1
	if c > 0 {
		running.tasks[task] = c
	} else {
		delete(running.tasks, task)
	}
	ctx.Logger().Infof("Finished task %s (%d instances now running) at %v (took %v)", name, c, end, end.Sub(started))
}
开发者ID:rainycape,项目名称:gondola,代码行数:34,代码来源:tasks.go

示例2: executeTask

func executeTask(ctx *app.Context, task *Task) (ran bool, err error) {
	var n int
	if n, err = numberOfInstances(task); err != nil {
		return
	}
	started := time.Now()
	ctx.Logger().Infof("Starting task %s (%d instances now running) at %v", task.Name(), n, started)
	ran = true
	defer afterTask(ctx, task, started, &err)
	task.Handler(ctx)
	return
}
开发者ID:rainycape,项目名称:gondola,代码行数:12,代码来源:tasks.go

示例3: gondolaRunTasksHandler

func gondolaRunTasksHandler(ctx *app.Context) {
	if ctx.GetHeader("X-Appengine-Cron") != "true" {
		ctx.Forbidden("")
		return
	}
	pendingTasks.Lock()
	for _, v := range pendingTasks.tasks {
		task := v
		ctx.Go(func(c *app.Context) {
			if _, err := executeTask(c, task); err != nil {
				ctx.Logger().Error(err)
			}
		})
	}
	pendingTasks.tasks = nil
	pendingTasks.Unlock()
	ctx.Wait()
}
开发者ID:rainycape,项目名称:gondola,代码行数:18,代码来源:tasks_appengine.go

示例4: registerUser

func registerUser(ctx *app.Context) {
	username := ctx.RequireIndexValue(0)
	userVal, _ := newEmptyUser(ctx)
	updating := false
	if ctx.Orm().MustOne(ByUsername(username), userVal.Interface()) {
		// Updating existing user
		updating = true
	} else {
		// Creating a new one
		userVal = newUser(ctx, username)
	}
	var askPassword bool
	ctx.ParseParamValue("p", &askPassword)
	if !updating || askPassword {
		password1, err := speakeasy.Ask("Password:")
		if err != nil {
			panic(err)
		}
		password2, err := speakeasy.Ask("Confirm Password:")
		if err != nil {
			panic(err)
		}
		if password1 != password2 {
			panic(fmt.Errorf("passwords don't match"))
		}
		setUserValue(userVal, "Password", password.New(password1))
	}
	var admin bool
	ctx.ParseParamValue("s", &admin)
	setUserValue(userVal, "Admin", admin)

	var email string
	ctx.ParseParamValue("e", &email)
	if email != "" {
		setUserValue(userVal, "Email", email)
	}

	ctx.Orm().MustSave(userVal.Interface())
	ctx.Logger().Infof("saved user as %+v", userVal.Interface())
}
开发者ID:rainycape,项目名称:gondola,代码行数:40,代码来源:commands.go


注:本文中的gnd/la/app.Context.Logger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。