From d1162c0f7b7a63ff497e7e744b09bb34a6d4d732 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Fri, 2 Jan 2015 14:35:03 +0000 Subject: [PATCH] Fix up half-arsed logging shims; set depth. --- client.go | 2 ++ logging/glog/glog.go | 28 ++++++++++++++++++++-------- logging/golog/golog.go | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 logging/golog/golog.go diff --git a/client.go b/client.go index 7da934f..05ae829 100644 --- a/client.go +++ b/client.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" irc "github.com/fluffle/goirc/client" + "github.com/fluffle/goirc/logging/glog" "os" "strings" ) @@ -14,6 +15,7 @@ var channel *string = flag.String("channel", "#go-nuts", "IRC channel") func main() { flag.Parse() + glog.Init() // create new IRC connection c := irc.SimpleClient("GoTest", "gotest") diff --git a/logging/glog/glog.go b/logging/glog/glog.go index ff87725..40d49a0 100644 --- a/logging/glog/glog.go +++ b/logging/glog/glog.go @@ -1,20 +1,32 @@ package glog import ( + "fmt" "github.com/golang/glog" + "github.com/fluffle/goirc/logging" ) // Simple adapter to utilise Google's GLog package with goirc. -// Just import github.com/fluffle/goirc/logging and this package, -// then call logging.Logger(glog.GLogger{}). -// The unfortunate downside of this is that it adds an extra hop -// to the caller chain which means *all* the line numbers are bad. +// Just import this package alongside goirc/client and call +// glog.Init() in your main() to set things up. type GLogger struct{} func (gl GLogger) Debug(f string, a ...interface{}) { // GLog doesn't have a "Debug" level, so use V(2) instead. - glog.V(2).Infof(f, a...) + if glog.V(2) { + glog.InfoDepth(3, fmt.Sprintf(f, a...)) + } +} +func (gl GLogger) Info(f string, a ...interface{}) { + glog.InfoDepth(3, fmt.Sprintf(f, a...)) +} +func (gl GLogger) Warn(f string, a ...interface{}) { + glog.WarningDepth(3, fmt.Sprintf(f, a...)) +} +func (gl GLogger) Error(f string, a ...interface{}) { + glog.ErrorDepth(3, fmt.Sprintf(f, a...)) +} + +func Init() { + logging.SetLogger(GLogger{}) } -func (gl GLogger) Info(f string, a ...interface{}) { glog.Infof(f, a...) } -func (gl GLogger) Warn(f string, a ...interface{}) { glog.Warningf(f, a...) } -func (gl GLogger) Error(f string, a ...interface{}) { glog.Errorf(f, a...) } diff --git a/logging/golog/golog.go b/logging/golog/golog.go new file mode 100644 index 0000000..4e2cca8 --- /dev/null +++ b/logging/golog/golog.go @@ -0,0 +1,15 @@ +package golog + +import ( + log "github.com/fluffle/golog/logging" + "github.com/fluffle/goirc/logging" +) + +// Simple adapter to utilise my logging package with goirc. +// Just import this package alongside goirc/client and call +// golog.Init() in your main() to set things up. +func Init() { + l := log.InitFromFlags() + l.SetDepth(1) + logging.SetLogger(l) +}