mirror of https://github.com/fluffle/goirc
Fix up half-arsed logging shims; set depth.
This commit is contained in:
parent
a3debed539
commit
d1162c0f7b
|
@ -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")
|
||||
|
|
|
@ -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...) }
|
||||
|
|
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue