mirror of
https://github.com/fluffle/goirc
synced 2025-05-12 18:44:50 +00:00
Fix up half-arsed logging shims; set depth.
This commit is contained in:
parent
a3debed539
commit
d1162c0f7b
3 changed files with 37 additions and 8 deletions
|
@ -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...) }
|
||||
|
|
15
logging/golog/golog.go
Normal file
15
logging/golog/golog.go
Normal 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)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue