-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlogging.go
55 lines (46 loc) · 983 Bytes
/
logging.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
// Copyright (C) 2017 Kale Blankenship. All rights reserved.
// This software may be modified and distributed under the terms
// of the MIT license. See the LICENSE file for details
package tftp // import "pack.ag/tftp"
import (
"log"
"os"
)
var (
debug bool
trace bool
)
func init() {
if os.Getenv("TFTP_DEBUG") != "" {
debug = true
}
if os.Getenv("TFTP_TRACE") != "" {
debug = true
trace = true
}
}
type logger struct {
log *log.Logger
d bool
t bool
}
func newLogger(name string) *logger {
prefix := "tftp|"
if name != "" {
prefix += name + "|"
}
return &logger{log: log.New(os.Stderr, prefix, log.Lshortfile), d: debug, t: trace}
}
func (l *logger) debug(f string, args ...interface{}) {
if l.d {
l.log.Printf("[DEBUG] "+f, args...)
}
}
func (l *logger) trace(f string, args ...interface{}) {
if l.t {
l.log.Printf("[TRACE] "+f, args...)
}
}
func (l *logger) err(f string, args ...interface{}) {
l.log.Printf("[ERROR] "+f, args...)
}