2015-09-03 18:57:28 +02:00
|
|
|
package cryptfs
|
2015-09-03 18:22:18 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2015-09-09 19:32:59 +02:00
|
|
|
"strings"
|
2015-09-03 18:22:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type logChannel struct {
|
|
|
|
enabled bool
|
|
|
|
}
|
|
|
|
|
2015-09-09 19:32:59 +02:00
|
|
|
func (l *logChannel) Printf(format string, args ...interface{}) {
|
2015-09-03 18:22:18 +02:00
|
|
|
if l.enabled == true {
|
|
|
|
fmt.Printf(format, args...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-03 13:36:49 +02:00
|
|
|
func (l *logChannel) Println(s string) {
|
|
|
|
if l.enabled == true {
|
|
|
|
fmt.Println(s)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 19:32:59 +02:00
|
|
|
func (l *logChannel) Dump(d []byte) {
|
|
|
|
s := string(d)
|
|
|
|
fmt.Println(strings.Replace(s, "\000", "\\0", -1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *logChannel) Enable() {
|
|
|
|
l.enabled = true
|
|
|
|
}
|
|
|
|
|
2015-10-07 21:26:17 +02:00
|
|
|
func (l *logChannel) Disable() {
|
|
|
|
l.enabled = false
|
|
|
|
}
|
|
|
|
|
2015-10-03 13:36:49 +02:00
|
|
|
// 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 {
|
2015-10-04 00:26:20 +02:00
|
|
|
return "disabled"
|
2015-10-03 13:36:49 +02:00
|
|
|
}
|
|
|
|
return md5sum(buf)
|
|
|
|
}
|
2015-09-03 18:22:18 +02:00
|
|
|
|
2015-09-08 23:09:28 +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}
|