special logging fields: from now on only 'job', 'task', 'subsystem'

This commit is contained in:
Christian Schwarz 2018-08-25 22:15:37 +02:00
parent e30ae972f4
commit 861e5f8313
5 changed files with 13 additions and 30 deletions

View File

@ -48,7 +48,7 @@ func (a *IntervalAutosnap) findSyncPoint(fss []*zfs.DatasetPath) (syncPoint time
a.task.Log().Debug("examine filesystem state")
for _, d := range fss {
l := a.task.Log().WithField(logFSField, d.ToString())
l := a.task.Log().WithField("fs", d.ToString())
fsvs, err := zfs.ZFSListFilesystemVersions(d, NewPrefixFilter(a.Prefix))
if err != nil {
@ -175,7 +175,8 @@ func (a *IntervalAutosnap) doSnapshots(didSnaps chan struct{}) {
suffix := time.Now().In(time.UTC).Format("20060102_150405_000")
snapname := fmt.Sprintf("%s%s", a.Prefix, suffix)
l := a.task.Log().WithField(logFSField, d.ToString()).
l := a.task.Log().
WithField("fs", d.ToString()).
WithField("snapname", snapname)
l.Info("create snapshot")

View File

@ -182,9 +182,9 @@ func (j *PullJob) doRun(ctx context.Context) {
return
}
ctx = replication.WithLogger(ctx, replicationLogAdaptor{j.task.Log().WithField("subsystem", "replication")})
ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{j.task.Log().WithField("subsystem", "rpc.protocol")})
ctx = endpoint.WithLogger(ctx, j.task.Log().WithField("subsystem", "rpc.endpoint"))
ctx = replication.WithLogger(ctx, replicationLogAdaptor{j.task.Log().WithField(logSubsysField, "replication")})
ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{j.task.Log().WithField(logSubsysField, "rpc.protocol")})
ctx = endpoint.WithLogger(ctx, j.task.Log().WithField(logSubsysField, "rpc.endpoint"))
j.rep = replication.NewReplication()
j.rep.Drive(ctx, sender, puller)

View File

@ -209,8 +209,8 @@ func (j *SourceJob) handleConnection(conn net.Conn, task *Task) {
senderEP := endpoint.NewSender(j.Filesystems, NewPrefixFilter(j.SnapshotPrefix))
ctx := context.Background()
ctx = context.WithValue(ctx, contextKeyLog, task.Log().WithField("subsystem", "rpc.endpoint"))
ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{task.Log().WithField("subsystem", "rpc.protocol")})
ctx = context.WithValue(ctx, contextKeyLog, task.Log().WithField(logSubsysField, "rpc.endpoint"))
ctx = streamrpc.ContextWithLogger(ctx, streamrpcLogAdaptor{task.Log().WithField(logSubsysField, "rpc.protocol")})
handler := endpoint.NewHandler(senderEP)
if err := streamrpc.ServeConn(ctx, conn, STREAMRPC_CONFIG, handler.Handle); err != nil {
task.Log().WithError(err).Error("error serving connection")

View File

@ -22,14 +22,9 @@ const (
)
const (
logJobField string = "job"
logTaskField string = "task"
logFSField string = "filesystem"
logSubsysField string = "subsystem"
logMapFromField string = "map_from"
logMapToField string = "map_to"
logIncFromField string = "inc_from"
logIncToField string = "inc_to"
logJobField string = "job"
logTaskField string = "task"
logSubsysField string = "subsystem"
)
type NoFormatter struct{}
@ -91,19 +86,6 @@ func (f *HumanFormatter) Format(e *logger.Entry) (out []byte, err error) {
break
}
}
// even more prefix fields
//mapFrom, mapFromOk := e.Fields[logMapFromField].(string)
//mapTo, mapToOk := e.Fields[logMapToField].(string)
//if mapFromOk && mapToOk && !f.ignored(logMapFromField) && !f.ignored(logMapToField) {
// fmt.Fprintf(&line, "[%s => %s]", mapFrom, mapTo)
// prefixed[logMapFromField], prefixed[logMapToField] = true, true
//}
//incFrom, incFromOk := e.Fields[logIncFromField].(string)
//incTo, incToOk := e.Fields[logIncToField].(string)
//if incFromOk && incToOk && !f.ignored(logIncFromField) && !f.ignored(logMapToField) {
// fmt.Fprintf(&line, "[%s => %s]", incFrom, incTo)
// prefixed[logIncFromField], prefixed[logIncToField] = true, true
//}
if line.Len() > 0 {
fmt.Fprint(&line, ": ")

View File

@ -41,7 +41,7 @@ func (p *Pruner) filterFilesystems() (filesystems []*zfs.DatasetPath, stop bool)
func (p *Pruner) filterVersions(fs *zfs.DatasetPath) (fsversions []zfs.FilesystemVersion, stop bool) {
p.task.Enter("filter_versions")
defer p.task.Finish()
log := p.task.Log().WithField(logFSField, fs.ToString())
log := p.task.Log().WithField("fs", fs.ToString())
filter := NewPrefixFilter(p.SnapshotPrefix)
fsversions, err := zfs.ZFSListFilesystemVersions(fs, filter)
@ -59,7 +59,7 @@ func (p *Pruner) filterVersions(fs *zfs.DatasetPath) (fsversions []zfs.Filesyste
func (p *Pruner) pruneFilesystem(fs *zfs.DatasetPath) (r PruneResult, valid bool) {
p.task.Enter("prune_fs")
defer p.task.Finish()
log := p.task.Log().WithField(logFSField, fs.ToString())
log := p.task.Log().WithField("fs", fs.ToString())
fsversions, stop := p.filterVersions(fs)
if stop {