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-11-09 22:33:42 +01:00
|
|
|
// As defined by http://elinux.org/Debugging_by_printing#Log_Levels
|
|
|
|
|
|
|
|
// Debug messages
|
2015-09-08 23:09:28 +02:00
|
|
|
var Debug = logChannel{false}
|
2015-11-14 17:16:17 +01:00
|
|
|
|
2015-11-09 22:33:42 +01:00
|
|
|
// Informational message e.g. startup information
|
|
|
|
var Info = logChannel{true}
|
2015-11-14 17:16:17 +01:00
|
|
|
|
2015-11-09 22:33:42 +01:00
|
|
|
// A warning, meaning nothing serious by itself but might indicate problems
|
2015-09-05 20:36:26 +02:00
|
|
|
var Warn = logChannel{true}
|