forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
72 lines (59 loc) · 2.13 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2016 Keybase, Inc. All rights reserved. Use of
// this source code is governed by the included BSD license.
package pvl
import (
"fmt"
libkb "github.com/keybase/client/go/libkb"
logger "github.com/keybase/client/go/logger"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
type proofContextExt interface {
libkb.ProofContext
GetLogPvl() logger.Logger
getStubDNS() *stubDNSEngine
}
type proofContextExtImpl struct {
libkb.ProofContext
pvlLogger logger.Logger
stubDNS *stubDNSEngine
}
func newProofContextExt(ctx libkb.ProofContext, stubDNS *stubDNSEngine) proofContextExt {
pvlLogger := ctx.GetLog().CloneWithAddedDepth(1)
return &proofContextExtImpl{
ctx,
pvlLogger,
stubDNS,
}
}
func (ctx *proofContextExtImpl) GetLogPvl() logger.Logger {
return ctx.pvlLogger
}
func (ctx *proofContextExtImpl) getStubDNS() *stubDNSEngine {
return ctx.stubDNS
}
func debugWithState(g proofContextExt, state scriptState, format string, arg ...interface{}) {
s := fmt.Sprintf(format, arg...)
g.GetLogPvl().CDebugf(g.GetNetContext(), "PVL @(service:%v script:%v pc:%v) %v",
debugServiceToString(state.Service), state.WhichScript, state.PC, s)
}
func debugWithStateError(g proofContextExt, state scriptState, err libkb.ProofError) {
g.GetLogPvl().CDebugf(g.GetNetContext(), "PVL @(service:%v script:%v pc:%v) Error code=%v: %v",
debugServiceToString(state.Service), state.WhichScript, state.PC, err.GetProofStatus(), err.GetDesc())
}
func debugWithPosition(g proofContextExt, service keybase1.ProofType, whichscript int, pc int, format string, arg ...interface{}) {
s := fmt.Sprintf(format, arg...)
g.GetLogPvl().CDebugf(g.GetNetContext(), "PVL @(service:%v script:%v pc:%v) %v",
debugServiceToString(service), whichscript, pc, s)
}
func debug(g proofContextExt, format string, arg ...interface{}) {
s := fmt.Sprintf(format, arg...)
g.GetLogPvl().CDebugf(g.GetNetContext(), "PVL %v", s)
}
// debugServiceToString returns the name of a service or number string if it is invalid.
func debugServiceToString(service keybase1.ProofType) string {
s, err := serviceToString(service)
if err != nil {
return string(service)
}
return s
}