Debian Codegraph @

log.go

raw symbols SCIP
1 package mint
2
3 import (
4 "fmt"
5 "log"
6 "os"
7 "strings"
8 )
9
10 // We use this environment variable to control logging. It should be a
11 // comma-separated list of log tags (see below) or "*" to enable all logging.
12 const logConfigVar = "MINT_LOG"
13
14 // Pre-defined log types
15 const (
16 logTypeCrypto = "crypto"
17 logTypeHandshake = "handshake"
18 logTypeNegotiation = "negotiation"
19 logTypeIO = "io"
20 logTypeFrameReader = "frame"
21 logTypeVerbose = "verbose"
22 )
23
24 var (
25 logFunction = log.Printf
26 logAll = false
27 logSettings = map[string]bool{}
28 )
29
30 func init() {
31 parseLogEnv(os.Environ())
32 }
33
34 func parseLogEnv(env []string) {
35 for _, stmt := range env {
36 if strings.HasPrefix(stmt, logConfigVar+"=") {
37 val := stmt[len(logConfigVar)+1:]
38
39 if val == "*" {
40 logAll = true
41 } else {
42 for _, t := range strings.Split(val, ",") {
43 logSettings[t] = true
44 }
45 }
46 }
47 }
48 }
49
50 func logf(tag string, format string, args ...interface{}) {
51 if logAll || logSettings[tag] {
52 fullFormat := fmt.Sprintf("[%s] %s", tag, format)
53 logFunction(fullFormat, args...)
54 }
55 }