Fix up half-arsed logging shims; set depth.

This commit is contained in:
Alex Bramley 2015-01-02 14:35:03 +00:00
parent a3debed539
commit d1162c0f7b
3 changed files with 37 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import (
"flag" "flag"
"fmt" "fmt"
irc "github.com/fluffle/goirc/client" irc "github.com/fluffle/goirc/client"
"github.com/fluffle/goirc/logging/glog"
"os" "os"
"strings" "strings"
) )
@ -14,6 +15,7 @@ var channel *string = flag.String("channel", "#go-nuts", "IRC channel")
func main() { func main() {
flag.Parse() flag.Parse()
glog.Init()
// create new IRC connection // create new IRC connection
c := irc.SimpleClient("GoTest", "gotest") c := irc.SimpleClient("GoTest", "gotest")

View File

@ -1,20 +1,32 @@
package glog package glog
import ( import (
"fmt"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/fluffle/goirc/logging"
) )
// Simple adapter to utilise Google's GLog package with goirc. // Simple adapter to utilise Google's GLog package with goirc.
// Just import github.com/fluffle/goirc/logging and this package, // Just import this package alongside goirc/client and call
// then call logging.Logger(glog.GLogger{}). // glog.Init() in your main() to set things up.
// The unfortunate downside of this is that it adds an extra hop
// to the caller chain which means *all* the line numbers are bad.
type GLogger struct{} type GLogger struct{}
func (gl GLogger) Debug(f string, a ...interface{}) { func (gl GLogger) Debug(f string, a ...interface{}) {
// GLog doesn't have a "Debug" level, so use V(2) instead. // 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...) }

15
logging/golog/golog.go Normal file
View File

@ -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)
}