aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/trace/trace.go
blob: cedd1bcf597d86a9c2ff928aa68573bbf992f691 (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej

package trace

import (
	"fmt"
	"os"
)

// handling of informational output

type outputLevel int

const (
	levelWarning outputLevel = iota - 1
	levelNone
	levelInfo
	levelTrace
	levelDebug
	levelSpam
)

var currentOutputLevel outputLevel = levelInfo

func AdjustVerbosity(howMuch int) {
	currentOutputLevel = (outputLevel)(howMuch + int(currentOutputLevel))
}

func Silent() {
	currentOutputLevel = levelNone
}

func outputStderr(l outputLevel, n string, v ...interface{}) {
	if l > currentOutputLevel {
		return
	}
	w := make([]interface{}, len(v)+1)
	w[0] = n
	for idx, arg := range v {
		w[idx+1] = arg
	}
	fmt.Fprintln(os.Stderr, w...)
}

func Info(v ...interface{}) {
	outputStderr(levelInfo, "[info]", v...)
}

func Trace(v ...interface{}) {
	outputStderr(levelTrace, "[trace]", v...)
}

func Debug(v ...interface{}) {
	outputStderr(levelDebug, "[debug]", v...)
}

func Warning(v ...interface{}) {
	outputStderr(levelWarning, "[warning]", v...)
}