libgocryptfs/cryptfs/log.go

49 lines
818 B
Go
Raw Normal View History

2015-09-03 18:57:28 +02:00
package cryptfs
2015-09-03 18:22:18 +02:00
import (
"fmt"
"strings"
2015-09-03 18:22:18 +02:00
)
type logChannel struct {
enabled bool
}
func (l *logChannel) Printf(format string, args ...interface{}) {
2015-09-03 18:22:18 +02:00
if l.enabled == true {
fmt.Printf(format, args...)
}
}
func (l *logChannel) Println(s string) {
if l.enabled == true {
fmt.Println(s)
}
}
func (l *logChannel) Dump(d []byte) {
s := string(d)
fmt.Println(strings.Replace(s, "\000", "\\0", -1))
}
func (l *logChannel) Enable() {
l.enabled = true
}
func (l *logChannel) Disable() {
l.enabled = false
}
// Only actually calculate the md5sum if the log channel is enabled to save
// CPU cycles
func (l *logChannel) Md5sum(buf []byte) string {
if l.enabled == false {
return "disabled"
}
return md5sum(buf)
}
2015-09-03 18:22:18 +02:00
var Debug = logChannel{false}
2015-09-16 19:32:37 +02:00
var Notice = logChannel{true}
2015-09-05 20:36:26 +02:00
var Warn = logChannel{true}