Commit d77ccb51 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7fa264d5
......@@ -258,6 +258,8 @@ type storRecovery struct {
// - nil: recovery was ok and a command came for cluster to start
// - !nil: recovery was cancelled
func (m *Master) recovery(ctx context.Context) (err error) {
defer running(&ctx, "recovery")(&err)
ctx = task.Running(ctx, "recovery")
defer task.ErrContext(&err, ctx)
log.Infof(ctx, "") // XXX automatically log in task.Running?
......
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
package server
// misc utilities
// Copyright (C) 2017 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com>
//
// This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your
// option) any later version, as published by the Free Software Foundation.
//
// You can also Link and Combine this program with other software covered by
// the terms of any of the Free Software licenses or any of the Open Source
// Initiative approved licenses and Convey the resulting work. Corresponding
// source of such a combination shall include the source code for all other
// software used.
//
// This program is distributed WITHOUT ANY WARRANTY; without even the implied
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package log provides logging with severity levels and tasks integration
//
// XXX inspired by cockrach
package log
import (
"github.com/golang/glog"
"lab.nexedi.com/kirr/neo/go/xcommon/task"
)
// taskPrefix returns prefix associated to current operational task stack to put to logs
func taskPrefix(ctx) string {
s := task.Current(ctx).String()
if s != "" {
s += ": "
}
return s
}
type Depth int
func (d Depth) Infof(ctx context.Context, format string, argv ...interface{}) {
// XXX avoid formatting if logging severity disables info
glog.InfoDepth(d+1, taskPrefix(ctx) + fmt.Sprintf(format, argv)
}
func Infof(ctx context.Context, format string, argv ...interface{}) {
Depth(1).Infof(ctx, format, argv)
}
// TODO Warningf, Errorf, ...
......@@ -17,7 +17,7 @@
// See COPYING file for full licensing terms.
// See https://www.nexedi.com/licensing for rationale and options.
// Package task allows to define currently running task via context XXX
// Package task provides primitives to track tasks via contexts.
package task
import (
......@@ -30,23 +30,6 @@ type Task struct {
Name string
}
// String returns string representing whole operational stack.
//
// For example if task "c" is running under task "b" which in turn is running
// under task "a" - the operational stack will be "a: b: c"
func (t *Task) String() string {
if o == nil {
return ""
}
prefix := Parent.String()
if prefix != "" {
prefix += ": "
}
return prefix + t.Name
}
type taskKey struct{}
// Running creates new task and returns new context with that task set to current
......@@ -78,12 +61,21 @@ func ErrContext(errp *error, ctx Context) {
return xerr.Context(errp, task.Name)
}
// XXX place
func Logf(ctx context.Context, format string, argv ...interface{}) {
s := CurrentOp(ctx).String()
if s != "" {
s += ": "
// String returns string representing whole operational stack.
//
// For example if task "c" is running under task "b" which in turn is running
// under task "a" - the operational stack will be "a: b: c"
//
// nil Task is represented as ""
func (t *Task) String() string {
if o == nil {
return ""
}
prefix := Parent.String()
if prefix != "" {
prefix += ": "
}
s += fmt.Sprintf(format, argv...)
log.Log(s)
return prefix + t.Name
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment